Phpmailer using smtp with Gmail not working - connection timing out

前端 未结 8 1971
天命终不由人
天命终不由人 2020-12-11 07:52

I\'ve looked into the following links:

phpmailer send gmail smtp timeout

send email using Gmail SMTP server through PHP Mailer

http://uly.me/phpmaile

相关标签:
8条回答
  • 2020-12-11 08:06

    Add

    date_default_timezone_set('Etc/UTC');
    

    before including the autoloader. SMTP Needs to have the timezone set which was my issue.

    0 讨论(0)
  • 2020-12-11 08:07

    I had this same problem and solved it:

    First, turn on smtp error logging in phpmailer:

        $mail->SMTPDebug  = 2;       // enables SMTP debug information (for testing)
    

    Then retry your phpmailer email send. You will see the entire SMTP conversation on standard error output. If you're using a web server, look in the web server log file.

    I could then see the error response from gmail. Gmail was not accepting the login.

    The error within the smtp conversation refers to an article. It gives some tips:

    1. Allow less secure apps to use your account.
    2. Login to gmail from a web browser.
    3. Confirm the gmail login captcha. (It may not actually display a captcha to you, but this was the additional step that suddenly allowed my email to go through.)
    0 讨论(0)
  • 2020-12-11 08:07

    That might probably be Gmail blocking your access.

    Go to your security configurations and see if it's blocking any access..

    Or try to change your password and try again.

    0 讨论(0)
  • 2020-12-11 08:10

    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';
        }
    

    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

    0 讨论(0)
  • 2020-12-11 08:10

    Use ssl

    $mail -> SMTPSecure = 'ssl';
    

    Port should be 465

    $mail -> Port = 465;
    

    Change your host to:

    $mail -> Host = 'ssl://smtp.gmail.com';
    

    Hopefully it works

    0 讨论(0)
  • 2020-12-11 08:16

    Check to make sure you can reach gmail from your webhost. I'm assuming it's linux. SSH in and on the command line type

    telnet smtp.gmail.com 587
    

    You should get back

    Connected to smtp.something 
    

    It has to be a configuration difference between localhost and your provider

    0 讨论(0)
提交回复
热议问题