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
- Download and Install the Free Test Mail Server Tool which emulates SMTP server on windows platform.
- Once installed simply run the mail server (Test Mail Server Tool) as you do for other servers like Wamp or XAMPP.
- (Optional) You can specify a folder to store received messages. The program listens on localhost on a SMTP port (usually 25).
- Check icon tool tip in Taskbar notification area to make sure its Running. If status is Stopped, other program may listen on SMTP port.
Test the new mail system
Now you're ready to test, copy the code below and save as testingemail.php and test open this file by open url:http://localhost/testingemail.php
- Open Outlook to receive email
<?php // ---------------- 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="Hirn"; $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.