Reveive and Intercept email in php on a windows server

I have php 5 installed on a windows server 2008 (IIS 6). So far I've used php to send out emails to clients but now I would like to setup an email on the server to receive & intercept incoming emails as soon as they come in  and parse them using php.

Can somebody tell me how to do that ? I am very new to this so a detailed step by step instruction would be great.

Who is Participating?
DrDamnitConnect With a Mentor Commented:
PHP is not the ideal language for this, but it can be done:

1. Create a script that binds to and listens on port 25 (see:
2. Once you are listening to port 25, you'll need to have a loop running that processes incoming requests. Most notably, you'll want to work from the server.php example in the link I gave you above. The attached code loop will be your jumping off point.
3. You'll need to process incoming SMTP requests using standard responses (reference RFC 821 ( and RFC 5321 (

Once you have read from the socket and recieve the message, you'll be able to parse it. You might even be able to use phpmailer to parse it (, but phpmailer is designed to send mail more than it is for reciving and parsing mail.

Still... you could use the code in the phpmailer class as an example of how to deal with the SMTP protocol.

while($c = socket_accept($sock)) {
   /* do something useful */
   socket_getpeername($c, $raddr, $rport);
   print "Received Connection from $raddr:$rport\n";

Open in new window

ucsdmbdmAuthor Commented:
Thank You for the reply, I will check it out later this week.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.