作者wendyhard (eeswd)
看板PHP
标题[请益] phpmailer error
时间Tue Feb 2 11:10:27 2016
大家新年快乐
小弟利用phpmailer练习发信 ,网页架设在XAMPP
SMTP是利用gmail发信 host=smtp.gmail.com, port=587
一直无法排除此error
2016-02-02 02:52:19 SMTP ERROR: Failed to connect to server: (0)
2016-02-02 02:52:19 SMTP connect() failed.
Message could not be sent.Mailer Error: SMTP connect() failed.
利用终端机查看 telnet smtp.gmail.com 587 也正常连线
Trying 173.194.72.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP c13sm6188756pat.8 - gsmtp
想请问有没有其他解决办法 谢谢。
以下是code;
<?php
require('PHPMailer/PHPMailerAutoload.php');
$host = 'smtp.gmail.com';
$port = 587;
$mail = new PHPMailer;
//SMTP连线
$mail->IsSmtp();
$mail->Host = $host;
$mail->Port = $port;
$mail->SMTPSecure = "ssl"; //Gmail 通讯协定走SSL
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->Username = '自己的gmail信箱';
$mail->Password = '自己的gmail密码';
//寄收件
$mail->setFrom('
[email protected]','mailer');
$mail->CharSet = 'utf-8';
$mail->WordWrap = 72;
$mail->AddAddress('
[email protected]');
//信件内容
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.25.105
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/PHP/M.1454382630.A.C68.html
1F:推 crossdunk: ssl有开吗 02/02 11:30
2F:→ wendyhard: 有! 在php.ini开了 02/02 12:13
3F:推 shadowjohn: port 改用465 看看,为啥是设587 ? 02/02 14:39
4F:推 crossdunk: 587是TLS ssl是 465@@ 02/02 15:05
5F:推 localhost: port 465 02/03 09:38
6F:→ wendyhard: 谢谢 更改port之後又去Gmail设定帐号两步验证>成功寄出 02/03 10:20