phpmailer和Gmail SMTP错误:无法连接到服务器:网络无法访问(101)SMTP连接()失败 [英] phpmailer and gmail SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed
问题描述
我需要帮助请
这是我的代码:
需要'PHPMailerAutoload.php';
$ mail = new PHPMailer;
$ mail-> isSMTP();
$ mail-> Host =smtp.gmail.com;
$ mail-> SMTPDebug = 2;
$ mail-> SMTPAuth = true;
$ mail-> SMTPSecure =tls;
$ mail-> Port = 587;
$ mail->使用者名称='some@gmail.com';
$ mail->密码='somepass';
$ mail-> addAddress('another@gmail.com','Josh Adams');
$ mail-> Subject ='PHPMailer GMail SMTP test';
$ body ='这是以粗体显示的HTML邮件正文!';
$ mail-> MsgHTML($ body);
if(!$ mail-> send()){
echo邮件错误:。 $ MAIL-> ERRORINFO;
} else {
echoMessage sent!;
}
我得到这个错误:
2013-12 -11 15:15:02 SMTP错误:无法连接到服务器:网络无法访问(101)SMTP连接()失败。邮件错误:SMTP连接()失败。
有任何帮助吗?
您可能想从隔离这个问题开始,以确定它是否真的是网络问题;或者它是否特定于PHP邮件程序或您的代码。在您的服务器上,从命令提示符处,尝试使用telnet连接到端口587上的smtp.gmail.com,如下所示:
telnet smtp.gmail.com 587
您应该看到来自smtp.gmail.com的回复,就像所以:
尝试173.194.74.108 ...
连接到gmail-smtp-msa.l.google.com 。
转义字符是'^]'。
220 mx.google.com ESMTP f19sm71757226qaq.12 - gsmtp
您是否看到这个,或者连接尝试是否挂起并最终超时?如果连接失败,则可能意味着您的托管公司阻止了端口587上的传出SMTP连接。
I need help please this is my code:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Username = 'some@gmail.com';
$mail->Password = 'somepass';
$mail->addAddress('another@gmail.com', 'Josh Adams');
$mail->Subject = 'PHPMailer GMail SMTP test';
$body = 'This is the HTML message body in bold!';
$mail->MsgHTML($body);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
and I get this error: 2013-12-11 15:15:02 SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed. Mailer Error: SMTP connect() failed.
any help please?
You might want to start by isolating this problem to determine whether it's truly a network problem; or whether it's specific to PHP mailer or your code. On your server, from a command prompt, try using telnet to connect to smtp.gmail.com on port 587, like so:
telnet smtp.gmail.com 587
You should see a response from smtp.gmail.com, like so:
Trying 173.194.74.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP f19sm71757226qaq.12 - gsmtp
Do you see this, or does the connection attempt hang and eventually time out? If the connection fails, it could mean that your hosting company is blocking outgoing SMTP connections on port 587.
这篇关于phpmailer和Gmail SMTP错误:无法连接到服务器:网络无法访问(101)SMTP连接()失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!