How Can PHP Send Email Using Gmail SMTP Server for Free Using OAuth Tokens That Renew Automatically By Manuel Lemos The Gmail SMTP server has required OAuth-based authentication to send email messages since May 2022 for Gmail users of free accounts.
The OAuth process obtains token string values from the Gmail OAuth server. These token strings are a sort of password to access the Gmail SMTP server.
The token strings are valid for a period that currently is 1 hour. After that period, applications that use the Gmail SMTP server will have to renew the tokens using the OAuth process again.
The MIME Message package uses the SASL package to perform authorization. The XOAUTH2 driver class of the SASL package can renew the OAuth token automatically when necessary.
Please read this article to learn with example code how to use the PHP MIME Message, SMTP Client, SASL, and OAuth client packages to send email messages using PHP with the Gmail SMTP server in a way that does not require human intervention to renew the OAuth tokens automatically after they expire.