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

  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 = "[email protected]";
   $headers = "From:" . $from;
   echo mail ("[email protected]" ,"headline" , "text", $headers);
?>
Share:
18,635
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    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
    Adam Silva about 9 years
    Hey, 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
    Jens A. Koch about 9 years
    Yes, 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
    Adam Silva about 9 years
    Thanks 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.