#native_company# #native_desc#

How to build a mailbot in PHP Page 4

By Michael Galloway
on November 6, 2002

You may also want to do additional regular expression checks to insure the “Reply-To” address is a valid email. A simple way to do that (no doubt great improvements could be made), is to do the following:


if(ereg("^[email protected]+..+$",$message_head["reply-to"])) 

$valid_reply_to true;

$valid_reply_to false;


Now we do our decision-making “if” statement. Basically the technique I use to avoid the message loops (which, by the way, can crash a server in no time) is to require the word “unsubscribe” in the subject header. If, for some reason, the message the mailbot sends is returned, the subject will be changed (it would now say something like “Returned Mail”), and the mailbot will not reply. Thus a loop is avoided.


if(eregi("unsubscribe",$message_head[subject]) && $valid_reply_to) {

$message "Dear $message_head[from]nnWe have unsubscribed you.";




"From: [email protected]");


Finally we should close the pointer to the $stdin file. (You don’t need to do this in 4.3)




So now we have the mailbot software ready to go. You may consider having it dump information into a logfile for error checking purposes, since you will not be running this from the command line.