Mail in PHP with XAMPP on localhost (windows)


I am trying to set up mailing using php on my localhost.  
I am not really quite aware what my options are, but a quick search found me sendmail.exe (which hasnt been updated for years, but is included with XAMPP)

Currently, this is what I have :

text.php :
    $to      = '';
    $subject = 'About localhost';
    $message.="Please...let this work";
    $headers = 'From:' . "\r\n" .
        'Reply-To:' . "\r\n";
    $headers.= "MIME-Version: 1.0\r\n";
    $headers.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $headers.= 'X-Mailer: PHP/' . phpversion();
    try {
        mail($to, $subject, $message, $headers);
    catch (mysqli_sql_exception $e){
        echo ("hahahahahaha");
        echo "well this didnt work out" . $e;

Open in new window

php.ini :

smtp_port = 465
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini :

I have also modified the properties of sendmail.exe so that it is running under administrative mode, with compatibility setting for windows xp sp 3

The result I am getting on the page is as follows

UAC opens up, requesting permission to run sendmail.exe
once I give the permission, sendmail.exe opens up a blank command prompt window
The website keeps loading, waiting for some sort of response from sendmail.exe.

Then nothing happens. The sendmail.exe command prompt never changes.

Any suggestions?
Or maybe a different solution to sendmail?

Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
For what it's worth, Gmail has changed their login authentication and you will not be able to use that code to connect to Gmail.
NeverEndingFlashStoriesAuthor Commented:
Thanks, Dave. Any recommendation on what I need to use/do?
Dave BaldwinFixer of ProblemsCommented:
The only external email client that supports Oauth2 that Google uses is the Current version of Thrundrbird.  Otherwise, you need to open Gmail in your browser.
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

NeverEndingFlashStoriesAuthor Commented:
Thanks Dave.
I am keeping the thread alive for a little longer, hoping someone can give me a way to make sending mail using localhost with xampp on windows to work .
NeverEndingFlashStoriesAuthor Commented:
So setting up mercury mail server to send mail to thunderbird works. I dont think this can work for other online email, but at least it lets me tests that my code works before i ever have to upload my files to the server.
NeverEndingFlashStoriesAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for NeverEndingFlashStories's comment #a40850913
Assisted answer: 500 points for Dave Baldwin's comment #a40849625

for the following reason:

The tutorial i linked uses outlook express, which is not available anymore for windows 8. So I downloaded thunderbird, and set my pop3 and smtp server to and set all username and password to root.

It worked, if only for testing purposes. I am not sure I like it, but at the moment I dont have a better solution.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
A simple and free solution for you would be to install hMail Server on your Windows machine, with hMail replacing "sendmail.exe".

hMail supports setting up your Gmail account as an SMTP relay.

Your PHP.ini file would change as follows:

    SMTP = localhost
    smtp_port = 25
    sendmail_path =

Then in hMail you add / localhost as a trusted IP.

Add your Gmail account to the
SMTP Relay
details in hMail (described in the documentation for hMail), and you are ready to go.

You can download hMail from

If you don't use it for this project, you might need it in the future for testing purposes.
NeverEndingFlashStoriesAuthor Commented:
Going to award points to a new comment.
NeverEndingFlashStoriesAuthor Commented:
Thanks guys!

For now, the mercury solution worked. I have spent a day and a half trying sendmail.exe and phpmailer to work to no avail for me through gmail, for something that should work flawlessly if i had done this through a real server, and not a windows localhost one. So i'll keep the suggestion with hmail at the back of my mind for my next project.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.