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

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&GT sender@gmail.com是一封保护隐私的掩码电子邮件.但我确实在那部分放了一个真正的电子邮件地址

解决方法:

你在PHP.ini中确保你已经取消注释了该行

extension=PHP_openssl.dll

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

相关推荐