Phpmailer using smtp with Gmail not working - connection timing out

☆樱花仙子☆ 提交于 2019-11-28 12:39:12

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

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.)

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

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

This question has many duplicates, so here's a canned answer:

  1. Base your code on the gmail example provided with PHPMailer
  2. Check out the troubleshooting docs
  3. Be aware of this issue, related to what Larry K said.

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.

Add

date_default_timezone_set('Etc/UTC');

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

Newtron

Download sendmail for Windows from http://www.glob.com.au/sendmail/sendmail.zip Copy sendmail.exe and sendmail.ini into C:/usr/lib/

Edit sendmail.ini and enter your mail account credentials.

You might want to configure these 2 fields as well (or sending may not work) force_sender=you-sender@yourdomain.com force_recipient=you@yourdomain.com By the way I uncommented debug_logfile so I can see what data is being sent to my SMTP server.

edit c:\php\php.ini

sendmail_from = you@yourdomain.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path = C:/usr/lib/sendmail.exe -t -i

Restart apache Start sendmail.exe either from [Start] > Run > C:/usr/lib/sendmail.exe or Go to C:/usr/lib in Windows Explorer and then DoubleClick on the exe file.

And this solution appears in Sendmail Wamp Php

I tried it on Windows 10 now and it runs with gmail account

Added:

Open CMD and make a sendmail as daemon/service using

sc create SendMail binpath= "C:\usr\lib\sendmail.exe"

Now, be sure you have OpenSSL installed on your system, you can download it from here: https://slproweb.com/products/Win32OpenSSL.html

Installs the version what do you need and dont remember to install "files to windows folder". Do a restart and try again, you will have it solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!