php PHPMailer 仅在 SMTPDebug = true 时发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18869269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHPMailer only sends email when SMTPDebug = true
提问by Chris J Allen
I'm using PHPmailer. It works when $mail->SMTPDebug = true; but when I remove that line, it silently fails. I say silently fails as it doesn't give any errors, and yet the email doesn't seem to be delivered.
我正在使用 PHPmailer。它在 $mail->SMTPDebug = true 时工作;但是当我删除那条线时,它默默地失败了。我说悄悄失败,因为它没有给出任何错误,但电子邮件似乎没有送达。
$mail = new PHPMailer;
$mail->SMTPDebug = true;
$mail->SMTPAuth = true;
$mail->CharSet = 'utf-8';
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->Username = '[email protected]';
$mail->Password = 'xxxxx';
$mail->Mailer = 'smtp';
$mail->AddReplyTo('[email protected]', 'xxxxx Support');
$mail->From = '[email protected]';
$mail->FromName = 'xxxxx Applications';
$mail->Sender = 'xxxxx Applications';
$mail->Priority = 3;
//To us
$mail->AddAddress('[email protected]', 'xxxxx xxxxx');
//To Applicant
$mail->AddAddress($email, $first_name.''.$last_name);
$mail->IsHTML(true);
$last_4_digits = substr($card_num, -4);
//build email contents
$mail->Subject = 'Application From '.$first_name.' '.$last_name;
$mail->Body = $body_html;
$mail->AltBody = $body_text;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
回答by Chris J Allen
By setting
通过设置
$mail->SMTPDebug = false;
instead of omitting the line completely, it works every time.
它不是完全省略该行,而是每次都有效。