Skip to main content

Auto-responder

This is an email auto-responder script.   The instructions for use are in the comments at the top of the script.   The script is intended to be run using Cron at preset invervals (for example every hour).   The script should be placed above the public directory to provide better security and to ensure no one else runs the script from http.

- - Start Script Here - -
<?php/*
Email auto-responder script.  Save in a file named responder.php
The script reads an IMAP mail box and auto-responds to all emails where the to address matches an address in the addressMatch array.
All messages checked by the script are marked as read and the script will only respond to unread messages.  This prevents duplicate responses.
Optionally, can set a flag to only send one response per received email address.
  -> Controlled by entries in the responder.dat file, which the script will create for you.
  -> To reset to send everyone a response again, simply delete the responder.dat file.
You must review and change as needed all the variables in the section below.
*/

// This section contains the variables which are set to use the auto-responder script
$server "mail.yourdomain.com";$user "XXXXXX";$password "XXXXXX";$subjectPrefix "Automatic Response to: ";  // response subject prefix - attaches to the front if the original subject$addressMatch = array("address@yourdomain.com","address2@yourdomain.com");   // email address array of the to email addresses you want processed$responseMessage "The auto-response message goes here";  // your auto-response message$returnAddress "auto-responder@yourdomain.com";  // return address for the autoresponse - use an address NOT in $addressMatch or the script will not run$returnLimit "N";  // must be Y to limit the auto-responses to one per email address
// End of user variables section - do not modify anything below this line unless you know what you are doing
$path "responder.dat";  // path to the file that contains addresses that have already received responses - used if $returnLimit = "Y"if (!preg_match("(^[-\w\.]+@([-a-z0-9]+\.)+[a-z]{2,4}$)i"$returnAddress))  die('Return address is not valid');
if (
in_array($returnAddress,$addressMatch)) die('Cannot use this email address as a return address'); $addressList "";
if (
file_exists($path)) $addressList file_get_contents($path);$host "{".$server.":143"."}"."INBOX";$msgStream imap_open($host$user$password);$check imap_mailboxmsginfo($msgStream);$number $check->Nmsgs;

function 
getheader($msgStream$msgNumber) {
  global 
$addressMatch;
  
$mailHeader imap_headerinfo($msgStream$msgNumber);
  
$headerArray = array();
  
$to $mailHeader->to;
  foreach (
$to as $id => $object) {
    
$test  $object->mailbox "@" $object->host;  // to address
    
if (in_array($test,$addressMatch)) {
      
$headerArray[0] = "match";
      
$headerArray[1]  = $object->personal;  // to personal
      
$headerArray[2]  = $object->mailbox "@" $object->host;  // to address
    
}
  }
  
$from $mailHeader->from;
  foreach (
$from as $id => $object) {
    
$headerArray[3]  = $object->personal;  // from personal
    
$headerArray[4]  = $object->mailbox "@" $object->host;  // from address
  
}
  if (
$mailHeader->Unseen == 'U' || $mailHeader->Recent == 'N') { $headerArray[5] = "new"; } else { $headerArray[5] = "old"; }
  
$headerArray[6] = $mailHeader->subject;
  return 
$headerArray;
}
$msgNumber "1";
while (
$msgNumber <= $number) {
  
$headerArray getheader($msgStream$msgNumber);
  
$body=imap_body($msgStream,$msgNumber);
  if (
$headerArray[0] == "match") {
    if ((
$returnLimit  !== "Y" OR ($returnLimit  == "Y"  AND substr_count($addressList,$headerArray[4]) == "0")) AND $headerArray[5] == "new" ) {
      
$addressList .=  $addressList "|" $headerArray[4];
      
$subject $subjectPrefix $headerArray[6];
      
$headers "From: <$returnAddress>\n";
      
$headers .= "Reply-To: <$returnAddress>\n";
      
mail($headerArray[4],$subject,$responseMessage,$headers,"-f$returnAddress");
    }
  }
  
$msgNumber ++;
}
imap_close($msgStream);

if (
$returnLimit  == "Y") {
  
$filePointer fopen($path"w" );
  
fwrite($filePointer$addressList);
  
fclose($filePointer);
?>

- - End Script Here - -

Read and auto-process mail
Here is a script that will read and process your mail.   The script is written to match the subject line, allow you to do custom processing, then optionally delete the message.   You can use this script to auto-process email requests.   You can easily change the script to compare against other header fields.   You have full access to the header fields and the message body.   Use cron to kick it off every few minutes and you have auto mail processing.   The script should be placed above the public directory to provide better security and to ensure no one else runs the script from http.

- - Start Script Here - -
<?php

$server 
"mail.yourdomain.com";$user "XXXXXX";$password "XXXXXX";$subjectMatch "Test";  // subject of the email messages you want processed$delete "Y";  // if delete is Y then processed mail will be deleted
 
$host "{".$server.":143"."}"."INBOX";$msgStream imap_open($host$user$password);
$check imap_mailboxmsginfo($msgStream);$number $check->Nmsgs;

function 
getHeader($msgStream$msgNumber) {
  
$mailheader imap_headerinfo($msgStream$msgNumber);
  
$headerArray = array();
  
$headerArray[0] = $mailheader->subject;
  
$from $mailheader->from;
  foreach (
$from as $id => $object) {
    
$headerArray[1]  = $object->personal;  // from personal
    
$headerArray[2]  = $object->mailbox "@" $object->host;  // from address
  
}
  
$headerArray[3] = $mailheader->Date;
  return 
$headerArray;
}

function 
getBody($msgStream$msgNumber){
   
$body=imap_body($msgStream,$msgNumber);
   return 
$body;
}
$msgNumber "1";
while (
$msgNumber <= $number) {
  
$headerArray getHeader($msgStream$msgNumber);
  
$body getBody($msgStream$msgNumber);
  if (
$headerArray[0] == $subjectMatch) { // check to see if the current message subject line matches what you want
    // do your special logic here
    // you have the header array and the body to work with
    // the echo line below is just for testing
    
echo "$headerArray[0]<br>$headerArray[1]<br>$headerArray[2]<br>$headerArray[3]<br>$body<br>";
    if (
$delete == "Y"imap_delete($msgStream$msgNumber);  // mark the current message for deletion
  
}
  
$msgNumber ++;
}

if (
$delete == "Y"imap_expunge($msgStream);  // delete all messages marked for deletion imap_close($msgStream);?>

- - End Script Here - -

As another example, if you wanted to process all mail over 3 days old you could use this test:

if (strtotime($headerarray[3]) <= strtotime("-3 days")) {

Comments

Popular posts from this blog

links

0.  https://michael67654.qowap.com/64523001/new-pos-technique-to-perk-up-your-company 1.  https://johnnydinqr.blog2learn.com/52856602/new-pos-system-to-perk-up-your-company 2.  http://edwinsqgcu.onesmablog.com/New-POS-Process-to-Perk-Up-Your-company-43309737 3.  http://chloe69246.bloguetechno.com/New-POS-Process-to-Perk-Up-Your-Business-39814721 4.  http://jacob87541.pointblog.net/New-POS-Technique-to-Perk-Up-Your-online-business-43741223 5.  http://arlette53302.thezenweb.com/New-POS-System-to-Perk-Up-Your-online-business-41464611 6.  http://devinpixna.tinyblogging.com/New-POS-Program-to-Perk-Up-Your-online-business-46354577 7.  https://rylanevsom.blog5.net/46759651/new-pos-program-to-perk-up-your-small-business 8.  https://mariowoesh.affiliatblogger.com/56515206/new-pos-system-to-perk-up-your-organization 9.  https://liam66429.diowebhost.com/60164326/new-pos-procedure-to-perk-up-your-company 10.  https://henry19219.fitnell.com/4557...

Raisonnement, la résolution de problèmes

Les chercheurs ont d'abord développé des algorithmes mimétiques raisonnement humain étapes que les gens utilisent pour résoudre le casse-tête ou faire méthode d'exclusion logique. [2] Dans les années 1980 et 1990 fin, l'étude de la grippe aviaire a développé des méthodes de traitement de l'information incertaine ou incomplète, en utilisant des concepts de probabilité et de l'économie. [3] Pour ces problèmes, les algorithmes requis matériel assez puissant pour effectuer des calculs de géant - à subir « combinaisons d'explosion »: la quantité de mémoire et le temps de calcul peut devenir invisible prendre si la résolution d'un problème difficile. La plus haute priorité est l'algorithme de recherche pour résoudre le problème.  Les gens utilisent généralement les jugements rapides et intuitifs plutôt que pas de déduction que les chercheurs en IA d'origine peuvent simuler. [5] Amnesty International a progressé en utilisant la résolution de problèmes « c...

Tracking and Securing Downloads

If you want to report or track downloads from your website, try this script.   This script will send you an email every time you have a download.   The email will tell you what file was downloaded and who did the download.   You could change this script to keep counts (store them in flat file or MySQL) if you desire. The variable $directory is the directory where the download files are located.   If you want the script in the same directory as the files then use "./" as the directory (you must always have the slash). In your html page, use the following structure as your download link (where name.txt is the file name to download): <a href="download.php?file=name.txt">download</a> Then you use the following script (called download.php): - - Start Script Here - - <?php $emailaddress  =  "email@yourdomain.com" ; $filename  =  $_GET [ 'file' ]; $directory  =  "downloads/" ; $path  =  "$directory$filename" ; putenv (...