PHP : send mail in localhost
It is configured to use localhost:25
for the mail server.
The error message says that it can't connect to localhost:25
.
Therefore you have two options:
- Install / Properly configure an SMTP server on localhost port 25
- Change the configuration to point to some other SMTP server that you can connect to
Send email from localhost running XAMMP in PHP using GMAIL mail server
Here's the link that gives me the answer:
[Install] the "fake sendmail for windows". If you are not using XAMPP you can download it here: http://glob.com.au/sendmail/sendmail.zip
[Modify] the php.ini file to use it (commented out the other lines):
[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: "sendmail -t -i").
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
(ignore the "Unix only" bit, since we actually are using sendmail)
You then have to configure the "sendmail.ini" file in the directory where sendmail was installed:
[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
To access a Gmail account protected by 2-factor verification, you will need to create an application-specific password. (source)
Can't Send Email through PHP on localhost using Gmail account
I am going to assume you are connecting to Gmail via the smtp server.
If you are currently using the actual password for the gmail account you are connecting to. The the best thing to do would be to try creating an apps password and using that.
Sign in with App Passwords
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.example.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'user@example.com'; //SMTP username
$mail->Password = 'APPsPassword'; //New apps password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465;
Another option would be to switch to Xoauth or switching to the Gmail api again using Oauth2.
$mail->oauthUserEmail = "[Redacted]@gmail.com";
$mail->oauthClientId = "[Redacted]";
$mail->oauthClientSecret = "[Redacted]";
$mail->oauthRefreshToken = "[Redacted]";
Related Topics
How to Convert String to Boolean PHP
Cloudflare and Logging Visitor Ip Addresses via in PHP
Custom Pagination View in Laravel 5
Getting Http Code in PHP Using Curl
Laravel Stylesheets and JavaScript Don't Load for Non-Base Routes
Call to a Member Function Fetch() on Boolean
Doctrine Query Language Get Max/Latest Row Per Group
Executing MySQLi_Query Inside a Function
Jquery Ajax Settimeout After Form Succes Not Redirecting
What Does This Symbol Mean in PHP <=
How to Add All of My Array Values Together in PHP
Difference Between Array_Map, Array_Walk and Array_Filter
Deleting All Files from a Folder Using PHP
Best Practice to Generate Random Token for Forgot Password