A web developer’s diary

June 12, 2007

Getting PhpMailer to connect to GMAIL’s SMTP Server

Filed under: PHP — Celia @ 8:38 am

PhpMailer is quite a cool open source library for sending outgoing mails in PHP. I have used it in a few applications which require sending mails via SMTP.

But sadly, it doesn’t work for GMAIL smtp server, the reason being that GMAIL requires TLS or SSL to send mails.

I found a way to fix this problem.

Fix:

1) Just prefix your smtp hostname with a ssl://
In this case, your hostname will be ssl://smtp.gmail.com

$this->phpMail->Host = "ssl://smtp.gmail.com";
$this->phpMail->Port=465;

2) Comment out the following lines of code in class.phpmailer.php
/* if(strstr($hosts[$index], ":"))
list($host, $port) = explode(":", $hosts[$index]);
else */

I guess that would be from Line No: 537 – 539

Save the file and test it out.

Advertisements

5 Comments »

  1. That was the best tip of the day ! 🙂

    Comment by Vladimir — May 26, 2008 @ 9:06 pm | Reply

  2. tip #2 saved the day!

    Comment by Rick — November 14, 2009 @ 1:23 am | Reply

  3. Hi.This is the best tip i have found for the gmail SMTP settings.many many thanks for the help.

    Comment by Rajender — March 9, 2010 @ 1:43 pm | Reply

  4. You win. Thank you.

    Comment by Michael — July 15, 2010 @ 1:21 pm | Reply

  5. It’s perfect time to make a few plans for the long run and it’s
    time to be happy. I’ve learn this post and if I may I desire to suggest you some attention-grabbing things or suggestions. Perhaps you can write subsequent articles relating to this article. I desire to read more issues approximately it!

    Comment by Automobile Personal Injury Law Firm in Ridgewood NY — May 17, 2013 @ 6:31 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: