【发布时间】:2013-10-13 12:35:16
【问题描述】:
我查看了以下链接:
phpmailer send gmail smtp timeout
send email using Gmail SMTP server through PHP Mailer
http://uly.me/phpmailer-and-gmail-smtp/
...并尝试为自己实现这些组合但是...大多数时候它会发送此消息...
消息无法发送。
邮件程序错误:SMTP 连接()失败。
但是有一次当我在“tls”和“ssl”之间进行实验时它发送了这个......
SMTP 错误:无法连接到服务器:连接超时 (110) SMTP connect() 失败。 无法发送消息。
邮件程序错误:SMTP 连接()失败。
我的代码已附上...我是否遗漏了什么?我询问了网络托管服务他们是否阻止并给了他们我的代码模板 - 他们说服务器允许连接到 Gmail 的 SMTP。
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail -> IsSMTP();
$mail -> SMTPDebug = 2;
$mail -> SMTPAuth = 'true';
$mail -> SMTPSecure = 'tls';
$mail -> SMTPKeepAlive = true;
$mail -> Host = 'smtp.gmail.com';
$mail -> Port = 587;
$mail -> IsHTML(true);
$mail -> Username = "myemail@gmail.com";
$mail -> Password = "mypassword";
$mail -> SingleTo = true;
$to = xxx;
$from = xxx;
$fromname = xxx;
$subject = xxx;
$message = xxx
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$mail -> From = $from;
$mail -> FromName = $fromname;
$mail -> AddAddress($to);
$mail -> Subject = $subject;
$mail -> Body = $message;
if(!$mail -> Send()){
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail-> ErrorInfo;
exit;
}
【问题讨论】:
-
-
我还研究了link,它没有帮助,因为我尝试了 ssl 和 tls,它给出了相同的输出
-
我编辑了我的答案,看看你是否错过了它
标签: php email ssl gmail phpmailer