Home >Backend Development >PHP Tutorial >Why Aren't My PHP Emails Sent from Localhost via Gmail SMTP Arriving?

Why Aren't My PHP Emails Sent from Localhost via Gmail SMTP Arriving?

Susan Sarandon
Susan SarandonOriginal
2024-12-10 01:29:101031browse

Why Aren't My PHP Emails Sent from Localhost via Gmail SMTP Arriving?

Troubleshooting Email Delivery from Localhost Using Gmail SMTP Server in PHP

Problem:

Despite receiving a "success" message after sending an email from localhost using the PHP mail() function, the intended recipient is not receiving the email.

Configurations:

  • GMail SMTP Server
  • php.ini and sendmail.ini both configured accordingly

Error Message:

13/10/02 13:36:41 : Must issue a STARTTLS command first.

Solution:

To resolve this issue and successfully send emails from localhost using Gmail, follow these steps:

  1. Install Fake Sendmail:

    • Download and install the "Fake Sendmail for Windows" utility if you have not already.
  2. Configure php.ini:

    • Comment out the default SMTP and sendmail settings in the php.ini file.
    • Configure the sendmail_path to point to the Fake Sendmail executable.
  3. Configure sendmail.ini:

    • Specify the Gmail SMTP server information, including the port (25), authentication credentials, and the force sender.
    • Ensure that the username is the same as the one you are using to access your Gmail account.
  4. Generate Application-Specific Password:

    • If you have enabled 2-factor verification for your Gmail account, you will need to generate an application-specific password for the email sending process.
  5. Modify sendmail.ini (optional):

    • Specify the SMTP port as 587 to use TLS encryption.
    • Uncomment the smtp_ssl line and set it to tls.

Once these changes are implemented, you should be able to successfully send emails from your localhost using PHP and the Gmail SMTP server.

The above is the detailed content of Why Aren't My PHP Emails Sent from Localhost via Gmail SMTP Arriving?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn