How to send an email through Gmail’s SMTP server using PHP

Introduction

In this tutorial, you will learn how to send emails in PHP using PHP Mailer library via Gmail SMTP. Like PHP Mailer, there are few good email sending libraries in PHP, e.g. Eg PEAR: Mail interface, Swift mailer, etc., Sometimes issues with Gmail smtp not working which can help you easily send mail in PHP using Gmail SMTP.

What is SMTP?

SMTP stands for Simple Mail Transfer Protocol. It is a simple set of commands that you can use to direct email transfers.

Protocols are network software rules that allow your computer to connect to other networks around the world.

You have probably heard of IP addresses, which stands for Internet Protocol and is just one example of these types of protocols.

For technical information, SMTP is part of the application layer that uses the TCP / IP protocol (TCP / IP stands for Transmission Control Protocol / Internet Protocol) to send email over networks such as the Internet. It does this through a process known as “store and forward.” With the Mail Transfer Agent, SMTP makes sure your emails reach the correct computer, in the correct email inbox.

How does SMTP work?
Simply put, when you send an email from an email client, it is forwarded to the SMTP server. When it reaches the SMTP server, it is sent to the recipient’s email server.

SMTP essentially takes different parts of your message and categorizes them. This allows the other server to understand the message in a two-way communication using a set of standards.

Prerequisites

Before we start with the steps on how to send mail using SMTP in the PHP example, let’s first see what some limits are with Gmail’s SMTP servers and how to overcome some of these:

Gmail limits the number of recipients in a single email and the number of emails that can be sent per day. The current limit is 500 emails in a day or 500 recipients in a single email. You can’t really increase this limit. If you want to send above these limits, you need to integrate with a third-party email delivery platform like Pepipost Send grid, etc.
Upon reaching the threshold limits, you will not be able to send messages for the next 24 hours. After this temporary suspension period ends, the counter is automatically reset and the user can resume sending emails.
By default, third-party apps / codes cannot send emails using your Gmail account. And so there are some settings that need to be done at the end:

How to enable email sending in Gmail?

Before sending emails using Gmail’s SMTP server, you must perform some of the security and permission level settings in the Security Settings of your Google account.

Make sure 2-Step Verification is turned off.

Activate access to the “Less secure application” or click here.

If two-step verification is enabled, you will need to create an app password for your app or device.

For security reasons, Google may ask you to complete this additional step when logging in. Click here to allow access to your Google account using the new device / application.

Configure system notifications
Login to your DSM.
Go to Control Panel> Notification> Email.
Check Enable email notifications.
Change the service provider to the custom SMTP server.
Fill in the required fields according to the instructions below:
SMTP server: smtp.gmail.com
SMTP port: 587
Authentication required: check the checkbox.
Username: enter your Gmail address.
Password: Enter the password for your Google account. If you have enabled two-step verification for your Google account, enter your 16-character app password.
Save the settings and wait for DSM to access your Google account. two
You can click Send a test email to see if the settings are correct.

What is POP and what is IMAP?
SMTP is used to send outgoing emails from your email clients. But how do you receive the emails?

To receive incoming messages, you must set up an incoming mail message on a server. To do this, you can use POP or IMAP.

Use the SMTP servers of your email account

You can switch to SMTP with your email account to fix WordPress not sending emails in ten easy steps.

1.Download, install and activate the WP Mail SMTP plugin from the WordPress repository.

2. Once the plugin is activated, click the Settings link (or the Settings> Email link in the sidebar) to configure the plugin.

3. Enter your email address and your name.

4. In the Mailer section, make sure Send all WordPress emails via SMTP is selected.

5. Under SMTP Options, complete the configuration using the HostPapa email server settings. You can find them in My cPanel in the HostPapa Control Panel by clicking the Email Accounts button.

6. Scroll down to Email Accounts and click the Configure Email Client link to view the SMTP settings.

7. Make sure Yes: Use SMTP authentication is selected and enter your SMTP login details.

8. Click the Save Changes button.

9. Test your configuration by entering an email address in the To field under Send a test email.

10. Click the Submit Test button to continue. If you do not receive an email, check your SMTP settings.

Source URL- Netgear Router login not working