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
上一篇:PHPMailer无法发送电子邮件


下一篇:为什么PHPmailer不发送附件?