How to send email from localhost

How to send email from localhost

This post was last updated on August 3rd, 2021 at 03:08 am

We always find difficulties in testing emails for our local PHP projects. Sending emails from localhost requires tweaking mail server settings in the php.ini file. Additionally you have to rely on SMTP mail servers of third parties like Google, Yahoo etc. After too much effort many times the communication does not occur the way it should.

So, for people including myself who want a simpler solution, there is a very simple, small application which makes email testing easier. Though this program will not send actual mails, it simulates an actual SMTP server – you can read mails in any local mail application or even in notepad.

Test Mail Server Tool

Test Mail Server Tool is a full featured mail (SMTP) server emulation to test mail sending capabilities of a web or desktop application or to preview messages before they are actually sent. This is a great tool for web programmers or application developers who need mail server for tests but don't want to install one.

The program listens on localhost on a SMTP port (usually 25, may be changed). All mail sent to this tool is automatically stored and optionally opened with your mail client.

Steps are simple Download, Install and Check Mails

  1. Download and Install the Free Test Mail Server Tool from the link above which emulates SMTP server on windows platform.
  2. Once installed simply run the mail server (Test Mail Server Tool) as you do for other servers like Wamp or XAMPP.
  3. (Optional) You can specify a folder to store received messages. The program listens on localhost on an SMTP port (usually 25).
  4. Check the icon tooltip in the Taskbar notification area to make sure it's Running. If the status is Stopped, another program may listen on the SMTP port.

Test the new mail system

Now you're ready to test, copy the code below and save it as testingemail.php and test open this file by open url:http://localhost/testingemail.php
- Open Outlook to read the email file or open the  file in any text editor


// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to="me@localhost"; // could be any email address

// Subject
$subject="Testing emails from localhost";

// From
$header="from: your name <your email>";

// Your message
$message.="This is test email from my localhostrn";
$message.="Thank you";

// send email
$sentmail = mail($to,$subject,$message,$header);

// if email succesfully sent
echo ($sentmail)?"Email Has Been Sent .":"Cannot Send Email ";



Now every time you send a mail with PHP script, it creates a file containing the text of the mail in the folder specified in a Path to store received mail edit box that is on step 3. The email file is stored with the extension .eml and can be opened and read in notepad or in outlook.

About This Author

My name is Parameshwar Roy (P. Roy), and I am a web developer. This is my personal blog to record my own thoughts. Though I am not a natural writer, I love to share my experiences. Hope my experiences will be useful to more about me

1 Comment

You can post comments in this post.

  • Very nice write-up. I absolutely appreciate this website.

    Keep writing!

    강남안마 3 years ago Reply

Leave A Reply