#native_company# #native_desc#
#native_cta#

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:

<?php

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

$valid_reply_to true;

else  
$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.

<?php

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

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

mail($message_head["reply-to"],

             
"Mailbot",

             
$message,

             
"From: [email protected]");



?>



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

<?php

fclose
($stdin);

?>



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.