提示:Mailer错误: SMTP Error: Could not connect to SMTP host.
我的源码是这样的:
<?php
// 使用PHPMailer发送邮件实例,163邮箱
include("class.phpmailer.php");
include("class.smtp.php"); // 可选
$mail = new PHPMailer();
$body = $mail->getFile('test/contents.html');//邮件正文内容,提取html文件为其内容
$body = eregi_replace("[\]",'',$body);
$mail->CharSet ="UTF-8";
$mail->IsSMTP();
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true; // 必填,SMTP服务器是否需要验证,true为需要,false为不需要
$mail->Host = "smtp.163.com"; //必填,设置SMTP服务器
//$mail->Port = 25; // 设置端口
$mail->Username = "
gfrghrthtj@163.com"; // 必填,开通SMTP服务的邮箱;任意一个163邮箱均可
$mail->Password = "gfrghrthtj123"; //必填, 以上邮箱对应的密码
$mail->From = "
gfrghrthtj@163.com"; //必填,发件人Email
$mail->FromName = "Webmaster"; //必填,发件人昵称或姓名
$mail->Subject = "This is the subject"; //必填,邮件标题(主题)
$mail->AltBody = "This is the body when user views in plain text format"; //可选,纯文本形势下用户看到的内容
$mail->WordWrap = 50; // 自动换行的字数
$mail->MsgHTML($body);
$mail->AddReplyTo("
gfrghrthtj@163.com","Webmaster");//回复邮箱地址
//$mail->AddAttachment("/path/to/file.zip"); // 添加附件,注意路径
//$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // 添加附件
$mail->AddAddress("
yx50yx@gmail.com","First Last");//收件人地址。参数一:收信人的邮箱地址,可添加多个。参数二:收件人称呼
//$mail->IsHTML(true); // 是否以HTML形式发送,如果不是,请删除此行
if(!$mail->Send()) {
echo "Mailer错误: " . $mail->ErrorInfo;
} else {
echo "邮件发送成功";
}
?>错误报告是这样的:
[24-Aug-2012 04:35:16 UTC] PHP Warning: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]: unable to connect to smtp.163.com:25 (Connection timed out) in /home/yxcocc/public_html/phpmailer/class.smtp.php on line 122
[24-Aug-2012 04:36:50 UTC] PHP Warning: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]: unable to connect to smtp.163.com:25 (Connection timed out) in /home/yxcocc/public_html/phpmailer/class.smtp.php on line 122
[24-Aug-2012 04:43:45 UTC] PHP Warning: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]: unable to connect to ssl://smtp.163.com:25 (Connection timed out) in /home/yxcocc/public_html/phpmailer/class.smtp.php on line 122
$mail->SMTPSecure = "ssl";
你知道Secure是“安全”的意思吧。
你知道ssl就是https中用的安全连接协议吧。
你知道php要支持ssl需要openssl模块吧。
所以你知道你为什么打不开了吧。
取消这句。