0

i'm trying to use php mailer with symfony 2

public function sendMailAction($email){
    $user = $this->getUser();
    $UserMail =  $user->getEmail();
    $mail = new PHPMailer(true);

    $mail->isSMTP();
    $mail->SMTPDebug = 2;
    $mail->Host = 'smtp.gmail.com'; 
    $mail->Port = 465;
    $mail->SMTPSecure = 'ssl';
    $mail->SMTPAuth = true;           
    $mail->Username = 'myGmail@gmail.com';
    $mail->Password = '********';                           

    $mail->setFrom('myGmail@gmail.com', 'Mailer');
    $mail->addAddress($email, 'A Name');
    $mail->isHtml(true);
    $mail->Subject = 'PHPmailer test';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();

    if(!$mail->send()){
        return new JsonResponse($mail->ErrorInfo);
    } else {
        return new JsonResponse("mail envoyé");
    }
}

I follow all the github tutorial, try to change port (465 for ssl, and 587 for tsl), and spend a lot of time in stackoverflow to found an awnser, but at final I always have the same mistake "SMTP error : failed to connect to server". Thx

  • Follow the PHPMailer troubleshooting guide - it's likely that your ISP blocks outbound SMTP. Also, you're enabling exceptions (passing `true` to constructor) but never catching them. – Synchro Nov 07 '17 at 15:24
  • So I change the smtp server (switch gmail to live) and it works, weird. Thx for your time – Antoine Bernard Nov 07 '17 at 16:15

0 Answers0