PHPMailer Tutorial – How To Configure with Gmail Account

arp14 PHP, Tutorial Tags: , , , , 5

PHPMailer, you may have used it before and of course you should know PHP too to continue this tutorial otherwise you won’t get anything. PHPMailer is very handy – easy to use among all 3rd party mail sender application available out there. PHPMailer supports nearly all possiblities to send email: mail(), Sendmail, qmail & direct to SMTP server. We usually use PHPMailer for our individual web hosting email accounts. This time we are going to configure it and send email from our regular Gmail accounts. Please try the script below as the configuration is well tested and working absolutely fine.

As you may know, it is simply to send mails with the PHP mail() function. So why use PHPMailer? Isn’t it slower? Yes that’s true, but PHPMailer makes it easy to send e-mail, makes it possible to attach files, send HTML e-mail, etc. With PHPMailer you can even use your own SMTP server and avoid Sendmail routines used by the mail() function on *nix platforms.

Here is the PHPMailer home site : and please visit for a complete tutorial of PHPMailer from it’s home site.

PHPMailer configuration for Gmail

$to_name = "Recipient Name";
$to = "[email protected]";
$subject = "Subject";
$message = "A quick brown fox juumped over the lazy dog.";
$message = wordwrap($message,70);

$from_name = "your_gmail_ID";
$from = "[email protected]";
// phpMailer
$mail = new PHPMailer();

$mail->Host = ""; //enable php socks to make SSL it working
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Username = "[email protected]";
$mail->Password = "your_gmail_password";

$mail->FromName = $from_name;
$mail->From = $from;
$mail->AddAddress($to, $to_name);
$mail->Subject = $subject;
$mail->Body = $message;
$result = $mail->Send();
echo $result ? 'Sent' : 'Error'; // this line is optional - comment out as your need

Please give me your feedbacks. Thank you 🙂

5 thoughts on “PHPMailer Tutorial – How To Configure with Gmail Account

  1. Very nice collection of stuff you have got here. Keep it up and soon you will have build a great knowledge base for newcomers. Thank you!

  2. hey could i have more details on how to get this working with the fogot.php file you used in the last tutorial? I am not sure what i am meant to do with this code and if i need any addtion code to make this work?

Leave a Reply

Note: Your email address will not be published. Required fields are marked *