如何解决PHPMailer可以将Gmail用作SMTP服务器无法连接到SMTP主机邮件错误:SMTP错误:无法连接到SMTP主机
|| 我正在尝试使用phpMailer通过电子邮件将确认消息发送给用户。我的代码是这样的:<?php
include(\"class.phpmailer.php\");
include(\"class.smtp.php\");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = \"ssl://smtp.gmail.com\"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = \"sender@gmail.com\"; // your SMTP username or your gmail username
$mail->Password = \"mypasswrord\"; // your SMTP password or your gmail password
$from = \"webmaster@example.com\"; // Reply to this email
$to=\"receiver@yahoo.com\"; // Recipients email ID
$name=\"Jersey Name\"; // Recipient\'s name
$mail->From = $from;
$mail->FromName = \"Webmaster\"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,\"Webmaster\");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = \"Sending Email From Php Using Gmail\";
$mail->Body = \"This Email Send through phpmailer,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\";
}
?>
我已经在php.ini中启用了ssl。
PS> sender@gmail.com是用于保护隐私的掩码电子邮件。但是我确实在那部分写了一个真实的电子邮件地址
解决方法
在您的php.ini中,请确保您已取消注释以下行
extension=php_openssl.dll
, 该页面具有作者声称“完美工作”的代码。
我看到他和您的人之间唯一真正的区别是他有:
$mail->Mailer = \"smtp\";
我想我应该从他的代码开始,看看它是否有效,然后从那里调试。
, 错误:
$mail->Host = \"ssl://smtp.gmail.com\"; // specify main and backup server
好:
$mail->Host = \"smtp.gmail.com\"; // specify main and backup server
, 从这里
2)注释掉class.phpmailer.php中的以下代码行
/*
if(strstr($hosts[$index],\":\"))
list($host,$port) = explode(\":\",$hosts[$index]); else
*/
如果尚未尝试,请尝试此操作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。