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:
- 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?
- [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.