Hosting With Gmail

To get the lastest news on Hosting With WordPress make sure to sign up for our newsletter. Additionally you can read a related articles hosting with blogger or hosting with facebook on this topic.


I have been using PHPMailer to send emails for some time now. PHPMailer is a fully featured email transfer class for PHP and its popularity has grown rapidly over the years. Recently I had to send e-mail messages using the GMail SMTP server for one of my clients.

Up to now I had only sent email messages using SMTP servers provided by the hosting company. The difference here is that I had to use SSL encryption to send emails. Using hosting company SMTP server has its drawbacks as there is a chance that your website IP address is already on a blacklist simply because someone else had abused the service before you.


  • Latest version of PHPMailer
  • A web host having PHP 5 / 6 enabled with Open SSL
  • GMail or Google Apps account

Sending Email

  • Check with your web hosting provider if port 465 (TCP out) is open, if not check with your hosting provider. Port 465 is needed to connect with the GMail SMT server.
  • Include PHPMailer class in your mailing script as follows


Add the following code to your mailing script

$mail  = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP

$mail->Host         = ""; // GMAIL SMTP server

$mail->Port         = 465;                   // set the SMTP port for the GMAIL server

$mail->SMTPDebug    = 0;  // debugging: 0 = none, 1 = errors and messages,

// 2 = messages only

$mail->SMTPAuth     = true;                  // enable SMTP authentication

$mail->SMTPSecure   = 'ssl'; // secure transfer enabled and REQUIRED for GMail

$mail->Username     = ''; // SMTP account username

$mail->Password     = 'yourpassword';        // SMTP account password

$mail->AddAddress(''); // receiver mail address

$mail->SetFrom('your name', ''); // from address

$mail->Subject = 'Test mail'; // mail subject

$mail->MsgHTML("Message Body"); // HTML message body



$msg = "Mail could not be sent.
Error Description: ". $mail->ErrorInfo;

} else


$msg = 'Email Message sent successfully!';

echo $msg;                        

As a final note please do check the GMail SMTP limitations mentioned here.

Author: Shamly Faleel is a PMP certified IT Consultant, who has over 9 years overall experience in the IT Industry. Check out his blog at

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>