Test mail() function of PHP on localhost with Windows 8.1
18,635
On Windows PHP needs additional configuration. Especially the SMTP settings are relevant. http://www.php.net/manual/en/mail.configuration.php
The emulator "test-mail-server-tool" listens on the specified port, normally 25 and writes the mail send there into a specific folder. It takes the place of a real SMTP server, in fact it's a dummy for testing purposes. If the mail is sent, it should be in the specified folder of "tmst".
Complete Walk-Through
- install "test-mail-server-tool"
- start the tool
- go to tray: set port 25 and folder for the email output
- create new php file with the source code from the send mail example below
- execute the php file (in your browser or on cli)
- go to the defined email output folder
- find a "*.eml" file with the content of your email
Basic PHP example for sending mail
<?php
$from = "[email protected]";
$headers = "From:" . $from;
echo mail ("[email protected]" ,"headline" , "text", $headers);
?>
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
How can I test the mail () function on my local server?
I use Windows 8.I tried using the 'Test Mail Server Tool' (http://www.toolheap.com/test-mail-server-tool/) tool but it did not work, the email was not saved anywhere after the execution of the function .
-
Adam Silva about 9 yearsHey, quick question. Okay I tested this and it worked (Thanks :D). So if I put my code that worked with this tool on the server that has the live website, can I assume that it will send actual emails to people?
-
Jens A. Koch about 9 yearsYes, if email sending is properly configured, then it should send mails "for real". Two things are needed: 1. proper php.ini config for mail sending - 2. real mail tool, like sendmail running on port 25. Alternative: if (1.) contains an external smtp service, like google, the mail is send via that service.
-
Adam Silva about 9 yearsThanks a lot :D from what I know the company server uses chimpmail as the smtp service, and the server should already have the php.ini config done correctly.