Home >Backend Development >PHP Tutorial >How Can I Successfully Send Emails from XAMPP Localhost Using Gmail's SMTP Server?

How Can I Successfully Send Emails from XAMPP Localhost Using Gmail's SMTP Server?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-15 06:05:15346browse

How Can I Successfully Send Emails from XAMPP Localhost Using Gmail's SMTP Server?

Sending Emails from Localhost with XAMPP and Gmail Mail Server

Despite sending emails from localhost using the PHP mail() function, some users may encounter issues where emails are not received at the intended destination. This article addresses these difficulties by outlining a specific solution involving the implementation of "fake sendmail" and the necessary configurations.

Step 1: Installation of "Fake Sendmail for Windows"

Download and install "fake sendmail for windows" to bridge the communication gap between PHP and the SMTP server.

Step 2: PHP.ini Configuration

Adjust the php.ini file to specify the use of sendmail:

[mail function]

; For Win32 only.
; SMTP = smtp.gmail.com
; smtp_port = 25

; For Win32 only.
; sendmail_from = <e-mail username>@gmail.com

; For Unix only. You may supply arguments as well (default: &quot;sendmail -t -i&quot;).
sendmail_path = &quot;C:\xampp\sendmail\sendmail.exe -t&quot;

Step 3: "sendmail.ini" Configuration

Configure the "sendmail.ini" file with the following settings:

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=<username>
auth_password=<password>
force_sender=<e-mail username>@gmail.com

Step 4: Two-Factor Verification

For Gmail accounts protected by two-factor authentication, generate and utilize an application-specific password to access the account via PHP.

The above is the detailed content of How Can I Successfully Send Emails from XAMPP Localhost Using Gmail's SMTP Server?. 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