AUTO RESPONDER SCRIPT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
handellphp
Forum Newbie
Posts: 1
Joined: Sat Apr 10, 2010 10:35 pm

AUTO RESPONDER SCRIPT

Post by handellphp »

NEWBIE HERE.

Im having trouble with an auto responder type script.
I forward all mail to 'responder@tmgraphics.biz' while on vacation.
I have certain people that I need a more personalized vacation response.

Everything works great except when someone hits reply to or forwards me an email.
It does not always read the thread properly.
Does anyone have a better email thread parsing technique.
Does anyone know if GMAIL has such a tool already?


Here's what I have so far.

Code: Select all

<?php
/*
this is run by a cron job every minute, 
will process emails and return a variety 
of reponses based on the recipient. 
Similar to vacation responer but personalized 
for many individuals.
*/



$email_fold ="~PATH_TO_EMAIL_THREADS/NEW";
$emailz = "";

  
////repeat with all emails
$cnt2 = 0;
if ($handle2 = opendir($email_fold)) {
while (false !== ($emailz = readdir($handle2))) {
if ($emailz != "." &&  $emailz != "..") {$cnt2++;
echo   "EMAIL THREAD:" .$emailz. "<br>";
 
 
//////////////start
if ($emailz !=""){
$the_email_thread = $email_fold.$emailz;
$encoded_string = file_get_contents($the_email_thread);
$email_text =  substr($encoded_string, 0, 22000);   
//////echo "<br>".$Recipiant; 




///////////GET ORIG SUBJECT////////////
 function get_string_between($string, $start, $end){ 
    $string = " ".$string; 
    $ini = strpos($string,$start); 
    if ($ini == 0) return ""; 
    $ini += strlen($start); 
    $len = strpos($string,$end,$ini) - $ini; 
    return substr($string,$ini,$len); 
}
$subjz= get_string_between($email_text, "Subject: ", "From: ");
 echo "SUBJ: ".$subjz."<br>";
///////////////////////////////



///////////GET ORIG SENDER////////////
$Recipiant = explode ("From: ", $email_text);
$Recipiant = $Recipiant[1];
$Recipiant = explode ("<", $Recipiant);
$Recipiant = $Recipiant[1];
$Recipiant = explode (">",$Recipiant);
$Recipiant2 = $Recipiant[0];
$Recipiant = "<".$Recipiant2.">";
echo "RECIPIENT IS: ".$Recipiant2."<br><br> ";
///////////////////////////////


unlink($the_email_thread); ///this can be chdir = change dir if need be


//////////////DEFAULT RESPONDER
$namez = "";
$message = "I will be out of the office until Nov 15 2010. \r\n (DO NOT REPLY)";
$subject = $subject;
$subject = "VACATION RESPONSE";
///////////// 
 
 
/////////responder for TIM 
if ( $Recipiant2 == "timmymason@gmail.com" ){ 
$namez = "Tim";
$message = "I am on vacation & you are not, now you have to do all my work . HA HA!!. \r\n (DO NOT REPLY)";
$subject = "In response to: " .  $subjz;
}
//////////////////



////////responder for HANDELL
if ( $Recipiant2 == "tim@tmgraphics.biz" ){ 
$namez = "Handell";
$subject = "IM ON VACTION";
$message = " Im on vaction however I will be checking my emails periodically. \r\n If it is extremely important, I will get back to you ASAP";
}
///////////////// 


///////////send email to the individual
$to      = $Recipiant;
$message = "ORIGINAL SUBJECT: ". $subjz."\r\n\r\nHi ".$namez.",\r\n ".$message;
$headers = 'From: masont@mglass.com' . "\r\n" .
    'Reply-To: masont@mglass.com' . "\r\n" ;
mail($to, $subject, $message, $headers);
////////////


}}}} 
 
?>  
Post Reply