?
Solved

Reveive and Intercept email in php on a windows server

Posted on 2010-09-23
2
Medium Priority
?
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
DrDamnit earned 2000 total points
ID: 33750530
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
ID: 33771974
Thank You for the reply, I will check it out later this week.
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
We aren’t perfect, just like everyone else.  Check out the email errors our community caught and learn the top errors every email marketer should avoid.
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.
Suggested Courses

650 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