【发布时间】:2019-03-29 05:27:50
【问题描述】:
我使用 PHP 邮件程序发送电子邮件 在我的 localhost XAMPP 服务器中,使用以下附加代码脚本(使用 PHP 邮件程序)成功发送电子邮件 但在生产服务器中托管的 Windows 2012 中,它会显示错误
SMTP Error: Could not authenticate
SMTP connect() failed.
这是我的脚本
<?php
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);
require_once('PHPMailer-master/class.phpmailer.php');
require_once('PHPMailer-master/class.smtp.php');
$email = new PHPMailer();
$email->MailerDebug = true;
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
/*$mail->SMTPAuth = false;
$mail->SMTPSecure = false;*/
$mail->Username = 'someusername@gmail.com';
$mail->Password = 'password';
$mail->setFrom('someusername@gmail.com', 'hello');
$mail->addAddress('testaddress@gmail.com');
$mail->addReplyTo('someusername@gmail.com');
$mail->isHTML(true);
$mail->Subject = 'the subject of the e-mail';
$mail->Body = 'The body of the email';
// $mail->AltBody = 'Alternative'; // this is mostly sent to your own mail
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: <pre>' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
错误信息
我还在谷歌邮件设置中启用了安全性较低的应用选项
【问题讨论】:
-
请不要发布文字图片,而是发布文字。
标签: php windows email phpmailer