我查看了以下链接:
...并试图为自己实现这些的组合......但大多数时候它发送此消息......
无法发送消息.
邮件程序错误:SMTP连接()失败.
然而有一次,当我在"tls"和"ssl"之间进行实验时,它发送了这个...
SMTP错误:无法连接到服务器:连接超时(110)SMTP连接()失败.无法发送消息.
邮件程序错误: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.
";
echo "Mailer Error: " . $mail-> ErrorInfo;
exit;
}