<?php
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "gdssdh";
//$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "myemail@gmail.com"; // GMAIL username
$mail->Password = "******"; // GMAIL password
$mail->SetFrom('mysent@gmail.com', 'PRSPS');
//$mail->AddReplyTo("user2@gmail.com', 'First Last");
$mail->Subject = "PRSPS password";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "mymail@yahoo.co.in";
$mail->AddAddress($address, "user2");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
当我在本地机器上运行脚本时,我得到了
客户端-> SMTP:EHLO localhost 客户端-> SMTP:身份验证登录客户端-> SMTP:cHV0aGVhLmh1b25nMjAxNEBnbWFpbC5jb20= 客户端-> SMTP:UHV0aGVhMDEy 客户端-> SMTP:邮件来自:客户端-> SMTP:RCPT 到:客户端-> SMTP:数据客户端-> SMTP:日期:星期一,2013 年 6 月 17 日 04:25:49 -0400 客户端 -> SMTP:返回路径:客户端 -> SMTP:收件人:user2 客户端 -> SMTP:发件人:PRSPS 客户端 -> SMTP:主题: PRSPS 密码 CLIENT -> SMTP: Message-ID: <405be3508111cd4789653ec34cdfba23@localhost> CLIENT -> SMTP: X-Priority: 3 CLIENT -> SMTP: X-Mailer: PHPMailer 5.2.6 ( https://github.com/PHPMailer/ PHPMailer/) CLIENT -> SMTP: MIME-Version: 1.0 CLIENT -> SMTP: Content-Type: multipart/alternative; 客户端-> SMTP:boundary="b1_405be3508111cd4789653ec34cdfba23" 客户端-> SMTP:内容传输编码:8 位客户端-> SMTP:客户端-> SMTP:--b1_405be3508111cd4789653ec34cdfba23 客户端-> SMTP:内容类型:文本/纯文本;charset=iso-8859-1 CLIENT -> SMTP: Content-Transfer-Encoding: 8bit CLIENT -> SMTP: CLIENT -> SMTP: gdssdh CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: --b1_405be3508111cd4789653ec34cdfba23 CLIENT - > SMTP:内容类型:文本/html;charset=iso-8859-1 CLIENT -> SMTP: Content-Transfer-Encoding: 8bit CLIENT -> SMTP: CLIENT -> SMTP: gdssdh CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: --b1_405be3508111cd4789653ec34cdfba23--客户-> SMTP: 客户 -> SMTP: . 客户端 -> SMTP:退出 消息已发送!
但是当我在主机上运行相同的脚本时
SMTP -> ERROR: Failed to connect to server: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应。(10060)SMTP Connect() 失败。邮件程序错误:SMTP Connect() 失败。
你有什么想法来解决这个问题吗?
提前致谢。