How to Implement a PHP SMTP Gmail Replacement for the PHP mail Function that Works with the Gmail OAuth Authentication By Manuel Lemos Many developers use Google Gmail to send email messages to their users because Gmail is a free service that works well.

In 2022 Google made the use of Gmail as a means to send email messages via Gmail SMTP server more secure by requiring an OAuth access token instead of the traditional password of the Gmail user account.

This requirement made many developers update their PHP applications to use OAuth tokens and continue to use the Gmail SMTP server for free.

Read this article to learn how to use OAuth access tokens to send email messages from PHP applications using the Gmail SMTP server.