[英]How to send email in PHP
I am experiencing the same problem as SMTP connect() failed PHPmailer - PHP . 我遇到了与SMTP connect()失败的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帐户的垃圾邮件文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.