Auto-Responder (autoresponse.class.php)

This class implements an email auto-response system. It accesses mailboxes via POP3 or IMAP protocols and sends out automatic responses emails to the messages found in the inbox folder.

Currently it implements three types of auto-response:

The response messages may be in plain text or HTML. After the auto-response is sent, the mails are marked read or can be deleted.This class is meant to be used from tasks run periodically for instance as cron jobs. Also it is possible to use this class from a webpage.

Functions implemented:

autoresponse($username,$password,$responderEmail,$mailserver='localhost',$servertype='pop',$port='110')
Class Constructor:
$username: Mail User Name ( for some servers, like name based hosts you might need to write the complete email address with the domain name. E.g: someone@somewhere.com)
$password: Mail User's Password
$respondersEmail: This email appears in the from field of the auto-response.
$mailserver: Mail Server to connect to, (Optional if you are running the script on the same server)
$servertype: Type of mail server i.e pop or imap, (Optional paramater if you are using a pop3 mail server)
$port: Port in which the mail server accepts connections, (143 for imap, Optional if you use pop in the $servertype arg)

void connect(void): Connects to the mail server

$responseContentSource="$string_source": Source to pick up the mail content from, in case of a custom and file autoresponder, thoug its absurd in case of a url autoresponder.

In case of a file auto responder the path of the file is given as:
$o->responseContentSource="/path/to/readable/file";

In case of a custom autoresponder it is as:
$respond->responseContentSource="This is a response to your mail!";
or
$respond->responseContentSource="$message"; # $message contains the autoresponse message

void send($type='custom',$format='html',$deleteMails=false):Send out the autoresponder message
$type: Type of auto responder message, valid types are custom, file or url (Optional if type is custom)
$format: Format of the mail that is sent out, valid formats are html or text (Optional if format is html)
$deleteMails: Valid args are true or false, Does the script delete the mails after the autoresponder is sent out.

void close_mailbox(void):Close the mailbox after the auto responder is sent out


Examples:

Send out a simple custom autoresponder:
/* include the main class */
include("autoresponse.class.php");
/* create a object of the class */
$respond=new autoresponse('vedanta@exampledomain.com','bulky','vedanta@exampledomain.com','mail.exampledomain.com');
/* connect to the mail server specified in the constructor */
$respond->connect();
/* set a autoresponse content */
$respond->responseContentSource="This is a response to your mail!";
/* send out a html format custom autoresponse and delete all the mails in the mail server */
$respond->send('custom','html',true);
/* close the mailbox */
$respond->close_mailbox();

Send out a file autoresponse in html format:
/* include the main class */
include("autoresponse.class.php");
/* create a object of the class */
$respond=new autoresponse('vedanta@exampledomain.com','bulky','vedanta@exampledomain.com','mail.exampledomain.com');
/* connect to the mail server specified in the constructor */
$respond->connect();
/* set a autoresponse content to a file in the system*/
$respond->responseContentSource="/path/to/a/readable/file/in/your/system";
/* send out a html format file autoresponse and do not delete the mails in the mail server */
$respond->send('custom','html');
/* close the mailbox */
$respond->close_mailbox();

Send out a url autoresponder:
In this type of autoresponder the url request is made by a valid url on the subject line:
E.g: Here are the headers of one such mail:

X-Booh-Received: 8d8347bcf82058be591c38be5468824261263390
Received: by 10.54.43.42 with HTTP; Mon, 6 Dec 2004 08:00:42 -0800 (PST)
Message-ID: <c52b4e4c04120608001c9dc0af@mail.booh.com> Date: Mon, 6 Dec 2004 21:30:42 +0530 From: Vedanta Barooah <vedanta.barooah@booh.com>
Reply-To: Vedanta Barooah <vedanta.barooah@booh.com>
To: give_me_the_url@something.com
Subject: http://www.gnu.org
Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit
Delivered-To: vedanta.barooah@booh.com

Notice the subject line requesting the URL, so the code will be as follows:

$respond=new autoresponse('vedanta@exampledomain.com','elephant','vedanta@exampledomain.com','mail.exampledomain.com');
$respond->connect();
$respond->send('url','html');
$respond->close_mailbox();

Please post me bugs and feature requests at : vedanta.barooah at gmail dot com

;-)