PHP mail function not working on localhost

PHP mail function not working on localhost is one of the major issue and we worked on different steps and its 100% working solutions.

PHP mail function not working on localhost

Solution 1 for PHP mail function not working on localhost

While searching about this topic we got plenty of bad results and finaly now we got different solutions.This entire work around solution is only for the XAMPP server.This is because Port 587 is blocked in our network on your computer this leads to the php mail function not worked on localhost so use Port 465 so it will clear the issue,follow the steps to sort it out.Initally we need to make changes on the Sendmail config.php and PHP Config.php

Sendmail config:

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username==*****@gmail.com
auth_password=*********
force_sender=*****@gmail.com

PHP config:

SMTP=smtp.gmail.com
smtp_port=465
sendmail_from = *****@gmail.com
sendmail_path = “\”c:\xampp\sendmail\sendmail.exe\” -t”

Code:
<?php
$message = mail(“repicient@example.com”,”Testing”,”Test Mail from localhost using PHP”);
echo “—“.$message.”—“;
if ( $message ) {
echo “The email has been sent!”;
} else {
echo “The email has failed!”;
}
?>

Note: For PHP mail function not working on localhost you need to enable SMTP access in GMAIL, also you need to allow unsecure clients.

If problem still exist take a look at this info https://stackoverflow.com/questions/27273153/php-xampp-mail-function-not-working

Solution 2 for PHP mail function not working on localhost

Make sure where you are testing the code, whether it is online or in localhost?
The mail() function will not work in localhost without SMTP.

Solution 3 for PHP mail function not working on localhost

This mostly cause because of your configuration. If you insist on using PHP mail function, you will have to edit php.ini.

Solution 4 for PHP mail function not working on localhost

search this line in php.ini file.

;sendmail_path =”C:\wamp\sendmail\sendmail.exe -t -i”

just remove semicolon

sendmail_path =”C:\wamp\sendmail\sendmail.exe -t -i”

and restart your xampp.

Still the problem exist take a look at this      

Thanks for reading Feel free to ask your doubts.

Leave a Reply

Your email address will not be published. Required fields are marked *