最近使用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!;}
回复内容: 最近使用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