
pohrebacek
New Members-
Posts
7 -
Joined
-
Last visited
Everything posted by pohrebacek
-
I found out it didn't work beacause my mailjet account was temporarily blocked. Here is code that works for me: <?php require 'vendor/autoload.php'; use \Mailjet\Resources; $apikey = 'MY_APIKEY'; $apisecret = 'MY_SECRETKEY'; $mj = new \Mailjet\Client($apikey, $apisecret, true,['version' => 'v3.1']); if($_SERVER['REQUEST_METHOD'] == 'POST') { $body = [ 'Messages' => [ [ 'From' => [ 'Email' => "EMAIL", 'Name' => "Mailjet Pilot" ], 'To' => [ [ 'Email' => "EMAIL", 'Name' => "passenger 1" ] ], 'Subject' => $_POST["subject"], 'TextPart' => $_POST["msg"], 'HTMLPart' => $_POST["msg"] ] ] ]; $response = $mj->post(Resources::$Email, ['body' => $body]); if ($response->success()) { $data = $response->getData(); echo "Email was sent successfully.\n"; var_dump($data); } else { echo "Failed to send email. Error: " . $response->getReasonPhrase() . "\n"; var_dump($response->getData()); } } ?>
-
Everything is fine according to this.
-
Thanks, there aren't any errors anymore, but I still can't see any email that was sent thanks to my script. I added this line and switched "from" and "to" email but it still doesn't work.
-
Yes I have mailjet account and I'm using my real API keys in my code. I tried to Initialize my Mailjet Client like you said, but now I'm getting different error, Failed to send email. Error: At least FromEmail or Sender must be provided array(0) { } But althrough i can see my from email in array when i echo it, I still get this error. <?php /* This call sends a message to one recipient. */ require 'vendor/autoload.php'; use \Mailjet\Resources; $apikey = 'MY_APIKEY'; $apisecret = 'MY_APISECRETKEY'; $mj = new \Mailjet\Client($apikey, $apisecret); if($_SERVER['REQUEST_METHOD'] == 'POST') { $body = [ 'Messages' => [ [ 'From' => [ 'Email' => $_POST["email"], 'Name' => "Mailjet Pilot" ], 'To' => [ [ 'Email' => "MY_EMAIL", 'Name' => "passenger 1" ] ], 'Subject' => $_POST["subject"], 'TextPart' => $_POST["msg"], 'HTMLPart' => $_POST["msg"] ] ] ]; $response = $mj->post(Resources::$Email, ['body' => $body]); echo print_r($body); if ($response->success()) { $data = $response->getData(); echo "Email was sent successfully.\n"; // Zobraz nebo zpracuj data podle potřeby var_dump($data); } else { echo "Failed to send email. Error: " . $response->getReasonPhrase() . "\n"; // Zobraz nebo zpracuj chybové informace var_dump($response->getData()); } } ?>
-
Oh my bad, I'm new here <?php /* This call sends a message to one recipient. */ require 'vendor/autoload.php'; use \Mailjet\Resources; $mj = new \Mailjet\Client(getenv('MY_APIKEY'), getenv('MY_SECRETKEY '),true,['version' => 'v3.1']); if($_SERVER['REQUEST_METHOD'] == 'POST') { $body = [ 'Messages' => [ [ 'From' => [ 'Email' => $_POST["email"], 'Name' => "Mailjet Pilot" ], 'To' => [ [ 'Email' => "MY_EMAIL", 'Name' => "passenger 1" ] ], 'Subject' => $_POST["subject"], 'TextPart' => $_POST["msg"], 'HTMLPart' => $_POST["msg"] ] ] ]; $response = $mj->post(Resources::$Email, ['body' => $body]); if ($response->success()) { $data = $response->getData(); echo "Email was sent successfully.\n"; var_dump($data); } else { echo "Failed to send email. Error: " . $response->getReasonPhrase() . "\n"; var_dump($response->getData()); } } ?>
-
when i use MailJet API I get this error: Failed to send email. Error: Unauthorized array(0) { } my code: <?php /* This call sends a message to one recipient. */ require 'vendor/autoload.php'; use \Mailjet\Resources; $mj = new \Mailjet\Client(getenv('MY_APIKEY'), getenv('MY_SECRETKEY '),true,['version' => 'v3.1']); if($_SERVER['REQUEST_METHOD'] == 'POST') { $body = [ 'Messages' => [ [ 'From' => [ 'Email' => $_POST["email"], 'Name' => "Mailjet Pilot" ], 'To' => [ [ 'Email' => "MY_EMAIL", 'Name' => "passenger 1" ] ], 'Subject' => $_POST["subject"], 'TextPart' => $_POST["msg"], 'HTMLPart' => $_POST["msg"] ] ] ]; $response = $mj->post(Resources::$Email, ['body' => $body]); if ($response->success()) { $data = $response->getData(); echo "Email was sent successfully.\n"; var_dump($data); } else { echo "Failed to send email. Error: " . $response->getReasonPhrase() . "\n"; var_dump($response->getData()); } } ?>
-
Hi, im trying to make webpage where user type their email, subject and message in html form and then hit submit. After that I want to send that form to my email address. I'm using mailjet.com as SMTP server. When I hit submit on my page, I get response that email has been sent, but none emaill has arrived. Any ideas on how to make it work? Maybe some other scripts or ways to achieve it? Please help. my php script: <?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; require 'vendor/autoload.php'; if($_SERVER['REQUEST_METHOD'] == 'POST') { $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output $mail->isSMTP(); //Send using SMTP $mail->Host = 'in-v3.mailjet.com'; //Set the SMTP server to send through $mail->SMTPAuth = true; //Enable SMTP authentication $mail->AuthType = 'LOGIN'; $mail->Username = 'API KEY'; //SMTP username $mail->Password = 'SECRET KEY'; //SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable implicit TLS encryption $mail->Port = 587; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` //Recipients $mail->setFrom($_POST["email"]); $mail->addAddress('MY EMAIL ADDRESS'); //Add a recipient //$mail->addAddress('MY EMAIL ADDRESS'); //Name is optional //$mail->addReplyTo('[email protected]', 'Information'); //$mail->addCC('[email protected]'); //$mail->addBCC('[email protected]'); //Attachments //$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name //Content $mail->isHTML(true); //Set email format to HTML $mail->Subject = $_POST["subject"]; $mail->Body = $_POST["msg"]; $mail->AltBody = $_POST["msg"]; $mail->send(); echo 'Message has been sent'; //header("Location: ./"); } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } }