使用 php 邮件从本地主机 xamp 成功发送邮件,但在生产环境中发送失败 windows 托管
using php mailer mail send from localhost xamp successfully but failed to sending in production windows hosting
我使用 PHP 邮件程序发送电子邮件
在我的本地主机 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';
}
?>
错误信息
我还在 google 邮件设置中启用了安全性较低的应用程序选项
这个配置适合我:
$mail->Host = 'smtp.googlemail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPAuth = true;
首先,您使用的是旧版本的 PHPMailer,因此 upgrade。
错误消息中有消息和 link 告诉您问题,首先是 Google,还有 link PHPMailer 故障排除指南,它描述了exactly this problem in great detail。那些 link 在那里是有原因的。
当它说 "Please log in via your web browser and then try again" 时,它的意思就是它所说的:您应该使用普通的网络浏览器登录到您的 gmail 帐户,然后再次尝试您的脚本。这样做的原因是 google 将您的网络登录视为一种确认您的帐户被合法访问的方式。
按照指南中的其他说明进行操作,它将解决您的问题。
您还泄露了您的gmail账号和密码,建议您修改。
我使用 PHP 邮件程序发送电子邮件 在我的本地主机 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';
}
?>
错误信息
我还在 google 邮件设置中启用了安全性较低的应用程序选项
这个配置适合我:
$mail->Host = 'smtp.googlemail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPAuth = true;
首先,您使用的是旧版本的 PHPMailer,因此 upgrade。
错误消息中有消息和 link 告诉您问题,首先是 Google,还有 link PHPMailer 故障排除指南,它描述了exactly this problem in great detail。那些 link 在那里是有原因的。
当它说 "Please log in via your web browser and then try again" 时,它的意思就是它所说的:您应该使用普通的网络浏览器登录到您的 gmail 帐户,然后再次尝试您的脚本。这样做的原因是 google 将您的网络登录视为一种确认您的帐户被合法访问的方式。
按照指南中的其他说明进行操作,它将解决您的问题。
您还泄露了您的gmail账号和密码,建议您修改。