Phpmailer使用smtp与Gmail不工作 - 连接超时 [英] Phpmailer using smtp with Gmail not working - connection timing out

查看:218
本文介绍了Phpmailer使用smtp与Gmail不工作 - 连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了以下链接:

phpmailer send gmail smtp timeout

通过PHP Mailer发送邮件使用Gmail SMTP服务器

http://uly.me/phpmailer-and-gmail-smtp/

...并试图为自己实现这些组合,但大部分时间它发送这个消息...

...and tried to implement for myself a combination of those however...most of the time it sends this message...


无法发送消息。

Message could not be sent.

Mailer错误:SMTP connect()失败。

Mailer Error: SMTP connect() failed.

然而,当我在tls和ssl之间进行实验时,有一次发送了这个消息。

However there was one time where it sent this when I experimented between "tls" and "ssl"...


SMTP错误:无法连接到服务器:连接超时(110) SMTP connect()失败。
无法发送消息。

SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Message could not be sent.

Mailer错误:SMTP connect()失败。

Mailer Error: SMTP connect() failed.

我的代码是附加的...我以某种方式错过了什么?我问网络托管服务是否阻止,并给他们一个代码模板 - 他们说服务器允许连接到Gmail的SMTP。

My code is attached...did I somehow miss something? I asked the web hosting service if they're blocking and gave them a template of my code - they said the server allows connections to Gmail's SMTP.

    require_once("class.phpmailer.php");
    $mail = new PHPMailer();
    $mail -> IsSMTP();
    $mail -> SMTPDebug = 2;
    $mail -> SMTPAuth = 'true';
    $mail -> SMTPSecure = 'tls';
    $mail -> SMTPKeepAlive = true;
    $mail -> Host = 'smtp.gmail.com';
    $mail -> Port = 587;
    $mail -> IsHTML(true); 

    $mail -> Username = "myemail@gmail.com";
    $mail -> Password = "mypassword";
    $mail -> SingleTo = true; 

    $to = xxx;                           
    $from = xxx;
    $fromname = xxx;
    $subject = xxx;
    $message = xxx
    $headers = "From: $from\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";

    $mail -> From = $from;
    $mail -> FromName = $fromname;
    $mail -> AddAddress($to);

    $mail -> Subject = $subject;
    $mail -> Body    = $message;

    if(!$mail -> Send()){
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail-> ErrorInfo;
        exit;
    }


推荐答案

使用php本机的fsocketopen来测试连接并消除大部分的潜在问题。写一个简单的PHP页面:

I dug into it. Use fsocketopen, which is native to php, to test the connection and eliminate most of the potential problems. Write a simple php page with this:

    $host = "smtp.gmail.com";
    $port = "587";
    $checkconn = fsockopen($host, $port, $errno, $errstr, 5);
    if(!$checkconn){
        echo "($errno) $errstr";
    } else {
        echo 'ok';
    }

您应该恢复ok。如果你不知道你有一个与Phpmailer无关的连接问题。如果是这样的话,那可能是托管公司。如果不是,那么对于本地主机和托管公司(如不同版本的PHP)的区别可能是一件简单的事情。

You should get back "ok". If not you know you have a connection problem that has nothing to do with Phpmailer. If that's the case it's probably the hosting company. If not then it's probably something simple about the difference between your local host and the hosting company like different versions of php.

我怀疑这个脚本不会使连接

I suspect though that this script won't make the connection

这篇关于Phpmailer使用smtp与Gmail不工作 - 连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆