Announcement

Collapse
No announcement yet.

Send email with mailjet

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Send email with mailjet

    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:​
    Code:
    <?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('info@example.com', 'Information');        
    //$mail->addCC('cc@example.com');        
    //$mail->addBCC('bcc@example.com');        
    
    //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}";
    }
    }​

  • #2
    1. unauthorized error = You have specified an incorrect Api Key / API Secret Key.
    2. To use the Mailjet Email API, you need to: Create a Mailjet account, then retrieve your API and Secret keys. They will be used for authentication purposes.

    Comment


    • #3
      I've had similar email delivery gotchas with blocked accounts. For smooth multi-channel communication, I use the whatsapp business api for customer follow-ups alongside email. The fixed pricing at UltraMsg makes it a solid alternative for reliable messaging without hidden issues.

      Comment

      Working...
      X