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
Add
date_default_timezone_set('Etc/UTC');
before including the autoloader. SMTP Needs to have the timezone set which was my issue.
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:
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.
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
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