简体   繁体   English

PHPMailer 使用 Gmail 作为 SMTP 服务器。无法连接到 SMTP 主机。 邮件程序错误:SMTP 错误:无法连接到 SMTP 主机

[英]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

From here这里

2) Comment out the following lines of code in class.phpmailer.php 2)注释掉class.phpmailer.php中的以下代码行

/*
if(strstr($hosts[$index], ":"))
list($host, $port) = explode(":",
$hosts[$index]); else 
*/

Try this if you haven't already.如果你还没有,试试这个。

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.

相关问题 SMTP错误:无法连接到SMTP主机。邮件程序错误:SMTP错误:无法连接到SMTP主机 - SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host SMTP 错误:无法连接到 SMTP 主机。 phpmailer 错误 - SMTP Error: Could not connect to SMTP host. Phpmailer error SMTP错误:无法连接到SMTP主机。 - SMTP Error: Could not connect to SMTP host. 如何解决“SMTP错误:无法连接到SMTP主机”。 在phpmailer中? - How to resolve 'SMTP Error: Could not connect to SMTP host.' in phpmailer? 无法连接到SMTP主机。 邮件错误:SMTP错误:无法连接到SMTP主机 - Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host PHPMailer,SMTP错误无法连接到smtp主机 - PHPMailer,SMTP Error Could not connect to smtp host PHPMailer:SMTP 错误:无法连接到 SMTP 主机 - PHPMailer: SMTP Error: Could not connect to SMTP host xampp + PHPMailer + Gmail = SMTP错误:无法连接到SMTP主机 - xampp + PHPMailer + Gmail = SMTP Error: Could not connect to SMTP host PHPMailer() + IIS + SMTP = SMTP 错误:无法连接到 SMTP 主机 - PHPMailer() + IIS + SMTP = SMTP Error: Could not connect to SMTP host SMTP-&gt;错误:无法连接到服务器:连接超时(110)SMTP错误:无法连接到SMTP主机。 - SMTP -> ERROR: Failed to connect to server: Connection timed out (110) SMTP Error: Could not connect to SMTP host.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM