【发布时间】:2019-03-06 09:28:37
【问题描述】:
我尝试了 win server 2012 r2 相关答案中提示的所有步骤,包括其相关答案和特定的 PHPMailer。
但是,我仍然遇到同样的问题。此外,已检查端口 25 是否在此处运行防火墙问题。
如果有人可以帮助我,真的很感激。
注意:
Win server 2012 r2 relates答案
PHPMailer答案
server fault 回复 谢谢
更新
//To test is via basic mail function
/*
mail("from_to_email@example.com", "Test Subject", "Test Message");
*/
//To Test via PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "from_email@example.com";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("to_email@example.com"); //Tried $mail->addAddress("to_email@example.com", "test name"); and third param too.
//Send HTML or Plain Text email
$mail->isHTML(true); //Tried with false too.
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPDebug = 3;
$mail->SMTPSecure = 'ssl';
// optional
// used only when SMTP requires authentication
$mail->SMTPAuth = true;
$mail->Username = SMTP_EMAIL_HERE;
$mail->Password = SMTP_PASS_HERE;
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
甚至,我通过online SMTP Tool 尝试了我的 SMTP 凭据,它工作正常,但上面的代码却不行。
注意:我验证了 PHP/Apache 模块的可用性并且它存在,所以关于模块没有问题。
【问题讨论】:
-
您是否尝试过使用 SMTP 到 localhost 而不是使用
mail()函数(即您是否调用$mail->isSMTP())? -
是的,我是使用 localhost 和 PHPMailer 完成的。
-
只有在您使用
mail()时才会出现“无法实例化”错误,因此不会出现这种情况。请使用SMTPDebug = 2显示您的代码和调试输出。 -
@Synchro 我已经经历了(可能是你的)答案来自:github.com/PHPMailer/PHPMailer/issues/1006。特别
SMTPDebug = 3,但没有什么比运气更重要的了:( -
请发布您的代码和调试输出,以便我们查看!
标签: phpmailer windows-server-2012-r2 php-7.2 wamp64