Posts Tagged ‘gmail in php’


How-to use PHPMailer for SMTP and GMail : PHP mail using GMail SMTP and PHPMailer
Sending e-mails via SMTP with PHPmailer and Gmail

I have been a fan of PHPMailer for quite some time. It is a very easy to use class that offers much more power than the regular PHP mail function. Although one problem I have had PHPMailer have been its rather poor documentation. Methods and attributes are split up with examples and tutorials seemingly overlapping but disconnected as well. However this is a small fault for such a great contribution to the PHP development community.

A thing I found hard to find was a specific example of how to set up PHPMailer to work with a GMail SMTP server. The results are actually quite simple and I managed to get it working with only a few tries. However if you are reading this you probably do not want to waste that 10 minutes, so I’ll just show you the sample code below.

$pm = new PHPMailer();
$pm->IsSMTP(true);
$pm->Host = 'ssl://smtp.gmail.com:465';
$pm->SMTPAuth = true;
$pm->Username = 'yourusername@gmail.com';
$pm->Password = 'yourpassword';

The above code shows all the configuration settings that need to be set. I will not reproduce the normal message attribute settings needed for sending mail in PHP with PHPMailer as you can find them at the PHPMailer website.