Search code examples
phpemailsmtpimapwindows-8.1

Test mail() function of PHP on localhost with Windows 8.1


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 .


Solution

  • 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

    1. install "test-mail-server-tool"
    2. start the tool
    3. go to tray: set port 25 and folder for the email output
    4. create new php file with the source code from the send mail example below
    5. execute the php file (in your browser or on cli)
    6. go to the defined email output folder
    7. find a "*.eml" file with the content of your email

    Basic PHP example for sending mail

    <?php
       $from = "sender@sender.com";
       $headers = "From:" . $from;
       echo mail ("receiver@receiver.com" ,"headline" , "text", $headers);
    ?>