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:
[mail function]
; 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:me@someaddress.com\r\n”.
“To:me@myaddress.com\r\n”.
“MIME-Version: 1.0\r\n” .
“Content-Type: multipart/mixed;\r\n”;
mail(“me@myaddress”,”PHP mail test”,”www.ria-coder.com/blog”, $headers);
?>
And you’re done!
| Print article | This entry was posted by Danny Kopping on December 12, 2008 at 8:33 pm, and is filed under Lessons, PHP. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 3 years ago
I have tried but my mails are continuesly showing in outbox
It is not being delivered to destination..
I am using dialup connection
Thanks
about 3 years ago
I am getting following log message
554-Your ability to send mails to the IN.com Mail System has been restricted due to the Sending Mail Server’s Reputation as a Spammer. This does not mean you are sending a spam message, it just means that the server you used has been used to send out spam in the recent past.
Please help me
about 3 years ago
Other message I am getting is
Connecting to localhost
Thread 2: 12:43:27 AM [] : Connected.
Thread 2: 12:43:27 AM [--->] : 220 PostCast SMTP server (http://www.postcastserver.com/) ready at Sat, 14 Mar 2009 0:43:27
Thread 2: 12:43:27 AM [] : 250 Hello 116.74.115.206 ([127.0.0.1])
Thread 2: 12:43:27 AM [] : 250 reset …
Thread 2: 12:43:27 AM [<---] : MAIL FROM:
Thread 2: 12:43:27 AM [--->] : 250 sender is valid
Thread 2: 12:43:27 AM [<---] : RCPT TO:
Thread 2: 12:43:27 AM [--->] : 250 husss@in.com… recipient is valid
Thread 2: 12:43:27 AM [] : 354 Enter mail. End with the . character on a line by itself.
Thread 2: 12:43:27 AM [] : 250 Message accepted for delivery
Thread 2: 12:43:27 AM [] : 221 closing connection
Thread 2: 12:43:27 AM [] : Disconnected.
about 3 years ago
Hi Hussain
Check out http://www.spamhaus.org/sbl/. This will give you some info as to why your mails are being flagged as spam. If your ISP allocates you new IP addresses each time you reconnect, then all you need to do is reconnect, get a new IP address and try again. I also sometimes have issues with this, but that should sort things out. Otherwise, make sure you’re sending to a valid address and that your emails don’t conflict with the spam rules as set out here: http://www.mailingcheck.com/check-spam-score/
about 2 years ago
hi, im trying to set a SMTP server in my pc, im using the code from this page, and it seems like it works, but no, it dosent send anything, what could i do
about 1 year ago
Very very nice tutorial
about 10 months ago
i have tried this but emails are unsent to my email address… i have opened postcast server and the email’s status is idle… how do i send this?
about 10 months ago
Hi chung
See this page:
http://www.postcastserver.com/help/Start_Pause_Stop.aspx