Send Email using Gmail SMTP with PHP


In this tutorial, we are going to learn how to Send Email using Gmail SMTP with PHP. We are going to use Gmail SMTP settings. SMTP is abbravation of Simple Mail Transfer Protocal. SMTP is used for sending email. Emails servers use SMTP for sending email.

In this code snippt “Send Email using Gmail SMTP with PHP”, we will use PHPMailer library to send email. You can download PHPMailer library. PHPMailer is a email library written in PHP, which used SMTP configuration to send emails.

Once you get PHPMailer library on your development envrinoment. You can start coding to Send Email using SMTP with PHP.

Now, all you need to include the PHPMailer.php file in your configuration file. This files autoloads all its related files and library those are requires for SMTP functioning.

SMTP has some good features like.

  • Allow to send email content in plain text and HTML format.
  • Allow multiple recipient, Carbon copy to and reply to ( TO,Cc, Bcc, Reply-to)
  • It supports multiple language.
  • It supports SMTP authentication.

Script for Send Email using Gmail SMTP with PHP.


In this file, first we include PHPMailer library and initialize the object of it. We will configure Gmail SMTP settings like host, port and credentials. Gmail SMTP host is SMTP secure value is tls here. But it will be SSL if you sending email through secure connection. sdvsd sdvsdv sdv

Send Email using Gmail SMTP with PHP

$email = new PHPMailer(); 
$email->SMTPDebug = 0;
$email->SMTPAuth = TRUE;
$email->SMTPSecure = "tls";
$email->Port = 587; 
$email->Username = "your gmail username";
$email->Password = "your gmail password";
$email->Host = "";
$email->Mailer = "smtp";
$email->SetFrom("From email", "From name");
$email->AddReplyTo("From email", "From name");
$email->AddAddress("recipient email");
$email->Subject = "Test email using PHP mailer";
$email->WordWrap = 90;
$content = "<b>Add your email body or you can include template here.</b>"; 
if(!$email->Send()) {
echo "Problem sending email.";
} else { 
echo "Cound not seend the message Error: ".$email->error;

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.