[英]PHPMailer to use Gmail as SMTP server.Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host
i am trying to use phpMailer to send confirmation messages to users via email.我正在尝试使用 phpMailer 通过 email 向用户发送确认消息。 my code is this:我的代码是这样的:
<?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";
}
?>
i already enabled ssl in php.ini.我已经在 php.ini 中启用了 ssl。
PS> sender@gmail.com is a mask email to protect the privacy. PS> sender@gmail.com 是掩码 email 以保护隐私。 but i did put a true email address in that part但我确实在那部分放了一个真正的 email 地址
in you php.ini make sure you have uncommented the line with在您的 php.ini 中确保您已取消注释该行
extension=php_openssl.dll
This page has code the author claims "worked flawlessly". 此页面包含作者声称“完美运行”的代码。
The only real difference I see between his and yours is that his has:我看到他和你之间唯一真正的区别是他有:
$mail->Mailer = "smtp";
I guess I would start with his code exactly to see if it works, and then debug from there.我想我会从他的代码开始,看看它是否有效,然后从那里调试。
wrong:错误的:
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
good:好的:
$mail->Host = "smtp.gmail.com"; // specify main and backup server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.