Setting up email on localhost with PHP + PostCast Server
I recently had a great ballache with trying to test emails from my local machine. Testing emails is painful enough when it fucking works, nevermind when it doesn’t! I’d been putting off setting my system up for weeks but tonight i finally decided to give it a proper bash… And it worked!
This is how i did it… In 3 easy steps!
Step 1 – Configure your PHP to allow for SMTP connections
Firstly, you need to edit your php.ini file found in the php folder of your local server. I personally use XAMPP because it’s everything i need in a web server. XAMPP now has versions for Windows, Mac and Linux, so nobody has an excuse not to use it now.
In your PHP config file (php.ini), if you do a search for SMTP, you will find the following code:
; For Win32 only.
;SMTP = localhost
;smtp_port = 25
All you need to do is uncomment the last two lines (take out the semi-colons).
Step 2 – Download, install and configure PostCast Mail Server
PostCast Mail Server is a great, simple to use application that will allow you to send email from your local machine. Download and install the application. Once installed, go to Tools->Settings, and set your host name to localhost with a server port of 25. Once you’ve done that, you’re almost ready to go!
Step 3 – Send a mail
Create a file on your server called testmail.php and use the following code:
$headers = “From:email@example.com\r\n”.
“MIME-Version: 1.0\r\n” .
mail(“me@myaddress”,”PHP mail test”,”www.ria-coder.com/blog”, $headers);
And you’re done!