最近要写一个php脚本发送邮件,本来很简单的,下载一个phpMailer 类,在网上找了代码就好了。如下
<?php
require("class.phpmailer.php"); //下载的文件放在该目录下
require("class.smtp.php");
$mail=new PHPMailer(); //建立邮件发送类
$adress="1506516221@qq.com"; //目的邮箱
$mail->IsSMTP(); //使用SMTP方式发送
$mail->CharSet="UTF-8"; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
$mail->Host="202.38.64.8"; // SMTP服务器
$mail->SMTPAuth=true; //启用SMTP验证功能
$mail->Username="liuxuwei@mail.ustc.edu.cn"; //发送方 email
$mail->Password="******";
$mail->Port=465; //端口号
$mail->SMTPDebug = 1; // 启用SMTP调试功能
// 1 = errors and messages
// 2 = messages only
$mail->SMTPSecure = "ssl"; // 安全协议
$mail->From="liuxuwei@mail.ustc.edu.cn";
$mail->FromName="liuxw";
$mail->AddAddress("$adress","liuxuwei");
$mail->Subject="PHPMailer测试邮件。"; //邮件标题
$mail->Body="Hello,this is a test email!"; //邮件内容
$mail->AltBody="extra informtoin of this email."; //附加信息
if(!$mail->Send())
{
echo "send failed.";
echo "error reason: ".$mail->ErrorInfo;
exit;
}
echo "success send.";
?>
可是现实错误:
2015-03-12 07:20:57 SMTP ERROR: Failed to connect to server: (0) 2015-03-12 07:20:57 SMTP connect() failed. send failed.error reason: SMTP connect() failed.
在晚上找了许多原因都没解决,什么在php.ini中修改extension=php_openssl.dll 这个啊,
把俩文件放到 C:\Windows\System32 这里啊,还是不行,后来我我发现,原来WIN8系统没有SMTP协议了,连pop3都没有了,我估计这就是原因了,不清楚是不是这样的,欢迎大神指正,浪费好长时间,还是没解决,目测就是这个问题了。