首页 > PHPmailer 使用网易126发送邮件的问题

PHPmailer 使用网易126发送邮件的问题

最近使用PHPMailer库连接网易的smtp.126.com邮件服务发送邮件总是返回连接失败
Mailer Error: SMTP connect() failed.
换过swiftmailer库也是一样的结果。
这是使用新的网易帐号才会有的问题,因为新的网易帐号需要开启客户端授权码才能使用SMTP服务。旧帐号是没有这个问题的。

请问这个授权码要如何使用连接网易的smtp?或者有其他办法解决连接失败的问题?

/**这是网上摘抄的代码 使用其他帐号可以正常使用的,问题同上*/
/**
* phpmailer发送邮件实例
* 发送网易邮箱126.com
* edit www.jbxue.com
*/
$mail= new PHPMailer();

$body= "发送邮件成功";

//采用SMTP发送邮件
$mail->IsSMTP();

//邮件服务器
$mail->Host       = "smtp.126.com";
$mail->SMTPDebug  = 0;

//使用SMPT验证
$mail->SMTPAuth   = true;

//SMTP验证的用户名称
$mail->Username   = "longmonhau";

//SMTP验证的秘密
$mail->Password   = "?";//密码

//设置编码格式
$mail->CharSet  = "utf-8";

//设置主题
$mail->Subject    = "测试";

//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";

//设置发送者
$mail->SetFrom('longmonhau@126.com', 'test');

//采用html格式发送邮件
$mail->MsgHTML($body);

//接受者邮件名称
$mail->AddAddress("1307995200@qq.com", "test");//发送邮件
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

在我看来,客户端授权码像是作为密码的替代。

参考链接: http://help.163.com/14/0923/22/A6S1FMJD00754KNP.html

【热门文章】
【热门文章】