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:
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.
对我来说,注释掉isSMTP()行使其可以工作,但是它仍然进入我的hotmail帐户的垃圾邮件文件夹中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.