我已经在网络上阅读了每个示例,但似乎仍然无法连接到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