Home » PHP » Send an Email via Gmail SMTP Server in PHP using PHPMailer

Send an Email via Gmail SMTP Server in PHP using PHPMailer

In this tutorial, we going to see how to send an email via Gmail SMTP server in PHP using PHPMailer. We send an email with different mail transfer libraries using PHP. In this, We are going to use PHPMailer. These libraries give excellent features like SMTP authentication and more.

Using Gmail SMTP server sending emails by using PHPMailer. PHPMailer library is famous because of its excellent features are available. Some of those features are below,

1. PHPMailer supports both HTML content and plain text.
2. We can able to use an array of email addresses like to, cc, bcc, reply-to.
3. It also gives Secure/MIME encryption with email validation, SMTP authentication including multiple language support.

Before using Gmail SMTP.

To send an email you can use the mail server of another host but for this, you need first to have authentication. E.g. You need to send an email from Gmail mail server first you require Gmail account.

Gmail SMTP needs the TLS encryption so we set it accordingly. If you want to send mail via SMTP, you want to find the Hostname, Port number, SMTPSecure encryption type if authentication is needed you also want the username and password.

Now need to do some changes in your Gmail account settings. First login and open your Gmail account settings.

1. We want to off the 2-Step Verification before using it.

2-Step Verification gmail smtp

2. Next, go to less secure apps. The default Gmail less secure apps are in off. So here, you need to keep Allow less secure apps: ON.

less secure apps google

Required files are needed:

Now we going to use a PHPMailer library which you can download on GitHub.

In this, we going to send a mail using TextBox and TextArea without saving data in the database. Below you can see the full code.


The below code is used to require the PHPMailerAutoload file. This PHPMailerAutoload file is available in PHPMailer library.




I believe in this tutorial you feeling happy with sending an email via Gmail SMTP Server in PHP using PHPMailer. Using other SMTP servers also you can try to send mail.

Was this article helpful?

Yes No

How can we improve it?


We appreciate your helpul feedback!

Your answer will be used to improve our content. The more feedback you give us, the better our pages can be.

Follow us on social media:

Facebook Pinterest


Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts.

Leave a Reply

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

Back to top