?
Solved

Reveive and Intercept email in php on a windows server

Posted on 2010-09-23
2
Medium Priority
?
399 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article explains how to install and use the NTBackup utility that comes with Windows Server.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

777 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