微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用PHPMailer和GMAIL SMTP发送电子邮件

我已经在网络上阅读了每个示例,但似乎仍然无法连接到GMAIL SMTP.这是我正在运行的代码

include("PHPMailer/class.PHPmailer.PHP"); // path to the PHPMailer class
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myUsername"; // SMTP username
$mail->Password = "myPassword"; // SMTP password
$mail->SMTPDebug = 1;
$webmaster_email = "webMasterEmail@gmail.com"; //Reply to this email ID
$email="someone@gmail.com"; // Recipients email ID
$name="SomeonesName"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Me";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo "Message has been sent";
}

我尝试在此处设置端口,并且在class.smtp.PHP文件中也进行了以下设置:

$host = "ssl://smtp.gmail.com";
$port = 465;

我不断收到相同的错误,并确保已启用ssl.我得到的错误是:

SMTP -> ERROR: Failed to connect to server: No connection Could be made because the target machine actively refused it.(10061)

解决方法:

如前所述,我已经通过摆脱ssl来启用了ssl;与PHP_openssl.dll并重新启动Apache.我做了一些阅读,发现启用命令之前还有一些人[PHP_OPENSSL].我添加了它并重新启动了Apache,一切正常!感谢所有的评论

PHP.ini中:

[PHP_OPENSSL]
extension=PHP_openssl.dll

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐