0

I am experiencing the same problem as SMTP connect() failed PHPmailer - PHP. My code is as follows:

public function sendEmail($toAddress, $subject, $message)
{
    require 'PHPMailer-master/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'username';
    $mail->Password = 'password';
    $mail->SMTPSecure = 'tls';
    $mail->SMTPDebug = 2;
    $mail->Port = 587;
    $mail->setFrom('support@tripmatcher.com', 'Tripmatcher Support');
    $mail->addAddress($toAddress);
    $mail->Subject = $subject;
    $mail->Body = $message;
    if (!$mail->send()) {
        error_log('Mailer Error: ' . $mail->ErrorInfo);
    } else {
        error_log('Email has been sent.');
    }
}

Two questions:

  1. What is wrong here, as far as I can see my code looks correct, and I have also enabled less secure apps for my email address?
  2. [Mon Sep 18 21:01:43.342766 2017] [:error] [pid 22052] [client 2.28.76.119:55132] Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting, referer:

That is all I see in the logs, how can I produce a more descriptive error message? I have tried looking at similar questions, and I still can't work out what exactly the problem is.

genesst
  • 1,333
  • 1
  • 10
  • 39
Michael Nares
  • 401
  • 4
  • 19
  • 1
    Did you read the page you mentioned in your question? Specifically https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#smtp-error-could-not-connect-to-smtp-host and https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling-debug-output parts – Nima Sep 19 '17 at 00:15
  • dig +short smtp.gmail.com gmail-smtp-msa.l.google.com. 64.233.184.108 64.233.184.109 – Michael Nares Sep 19 '17 at 10:55
  • That is what I get from dig +short smtp.gmail.com and also my SSL is not with GoDaddy, so I don't think it's either of those two. – Michael Nares Sep 19 '17 at 10:56

1 Answers1

0

For me, commenting out the isSMTP() line made it work, but it still went into the spam folder of my hotmail account.

Michael Nares
  • 401
  • 4
  • 19