Solved

Reveive and Intercept email in php on a windows server

Posted on 2010-09-23
2
382 Views
Last Modified: 2012-05-10
Hi,
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.

Thanks,
Ross
0
Comment
Question by:ucsdmbdm
2 Comments
 
LVL 32

Accepted Solution

by:
DrDamnit earned 500 total points
Comment Utility
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: http://www.php.net/manual/en/function.socket-create-listen.php).
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 (http://tools.ietf.org/html/rfc821) and RFC 5321 (http://tools.ietf.org/html/rfc5321).

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 (http://phpmailer.worxware.com/), 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

0
 

Author Comment

by:ucsdmbdm
Comment Utility
Thank You for the reply, I will check it out later this week.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now