We’re going to learn how we can send an email using Gmail SMTP server from a PHP page/script.SMTP is an abbreviation for Simple Mail Transfer Protocol.SMTP is an Internet standard for electronic mail, i.e., email.All mail servers and other mail transfer agents use SMTP to send and receive emails.Firstly, we’ll take a look at the PHP mailer library we’re going to use.You can take this library as an alternative of mail() function in PHP.After that, we’ll discuss the process.

Đang xem: How to send emails using php mail and phpmailer: a complete guide

In case you want to send emails via Gmail, you can choose a simpler way that doesn’t require any technical coding – Connect with external SMTP Service Providers

Also you can learn, How to send mass emails in Gmail without getting blacklisted?

*

Download script

You can purchase our service Mailget – email marketing platform for the complete solution.

Change in Gmail settings :

First of all, you need to make some changes in your Gmail account settings.You need to open your Gmail account settings. The following page will get open.

*

You need to click Signing in to Google. It will redirect you to the following page.

Xem thêm: Javascript — Thay Đổi Thuộc Tính Css Bằng Jquery Và Thuộc Tính Css

*

There are 2 steps :

1. You need to keep the 2-step verification off if you’re using it.2. Then click on Connected apps & sites. It will redirect you to the following window.

*

Here, you need to keep Allow less secure apps : ON .And it’s done. That’s all you need to do.

Files to be needed:

We’re going to use a PHPMailer library which you can find on the GitHub repository.You can take it as an alternative to the mail() function of PHP.

Xem thêm:

Process:

Let’s take a look at the full code of the PHP file.

PHP file : index.php

Send email via Gmail SMTP server in PHP
Send email via Gmail SMTP server in PHP

Gmail SMTP

isSMTP();$mail->Host = “smtp.gmail.com”;$mail->Port = 587;$mail->SMTPSecure = “tls”;$mail->SMTPAuth = true;$mail->Username = $email;$mail->Password = $password;$mail->addAddress($to_id);$mail->Subject = $subject;$mail->msgHTML($message);if (!$mail->send()) {$error = “Mailer Error: ” . $mail->ErrorInfo;echo “”.$error.”

Related Post

Leave a Reply

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