# Media auto responder setup



## heero1 (Feb 6, 2007)

Hi
I am in the middle of setting up above auto responder for my website.
Instructions are as below:

Installation And Setup Instructions: 

1) Create a folder named "responder" on your web server and copy ALL files in that folder.
Chmod 777 the folders 'temp' and 'media'

2) Create a new database

3) Modify the MYSQL database information using the new database
you have just created in the file include/globals.php 

4) Run the installer program using:
http://www.yoursite.com/responder/install.php
Enter your Name, Email, Username, Password and click the "Install" button.
Please DO NOT forget to remove the install.php file after installation.

5) Modify the mail account username/password (main email address for domain*)
in the file robot/imap_globals.php. (<?php
// pop3 mail server connection parameters
$MailHost = "";IS MAIL HOST MY WWW.DOMAIN.COM?
$MailUser = "";WHAT SHOULD I ENTER HERE EXPLAIN IN DETAILS PLEASE
$MailPassword = "";WHICH PASSWORD?
?>

Note: For $MailHost, the variable is usually yoursite.com.
If you are unsure of your mail server, please contact your host administrator

6) Add to cron job php responder/robot/check_deliver_broadcast_messages.php once at a minute

(

```
<?php
// Sends broadcast messages
// Set CRON for each 5 minutes
// Written by Michel Komarov [url]http://icoder.com[/url] (2005-12-13)
function error_page($error_message) { return "$error_message"; } 
	$bunchSize = 300;
	$bunchPause = 60; //sec
	$bunchInterval = 600; //sec (from CRON timing)
	$cron_file = "../temp/broadcast.cron";
	if (file_exists($cron_file)) {
		$cron = file_get_contents($cron_file);
		if ((5 * $bunchInterval) + $cron > time()) exit;
	}
	if ($fh = fopen($cron_file, "w")) {
		fputs($fh, time());
		fclose($fh);
	}

	require("../include/globals.php");
	require("../include/db_mysql.php");
	require("../include/phpmailer.php");
	require("../include/mail.php");

	set_time_limit(0);
	$db = new DB_Sql;
	$db2 = new DB_Sql;

	$queryWhere = "FROM broadcastmessages
					WHERE 
					broadcastmessages_delivery_date <= NOW() AND
					broadcastmessages_sent = '0' ";
	$db->query("SELECT * $queryWhere");
	if (($count = $db->num_rows()) > 0) {
		if ($fh = fopen("../temp/broadcast.log", "a")) {
			fputs($fh, "\n".date("Y-m-d H:i:s")." Messages: $count\n");
			fclose($fh);
		}
	}
	$msg = 0;
	while ($db->next_record()) {
		if (0 == ((++$msg) % $bunchSize)) {
			if ($fh = fopen("../temp/broadcast.log", "a")) {
				fputs($fh, "\t$msg sent\n");
				fclose($fh);
			}
			if ($fh = fopen($cron_file, "w")) {
				fputs($fh, time());
				fclose($fh);
			}
			sleep($bunchPause);
		}
		$broadcast_message_id = $db->f("broadcastmessages_id");

		$error = SendBroadcastMessage($broadcast_message_id);
		if ($error) {
			if ($fh = fopen("../temp/broadcast.log", "a")) {
				fputs($fh, " $error.");
				fclose($fh);
			}
		}

		$db2->query("UPDATE broadcastmessages
						SET broadcastmessages_sent = '1'
						WHERE broadcastmessages_id = '$broadcast_message_id'");
	}
	unlink($cron_file);
	if ($count > 0) {
		if ($fh = fopen("../temp/broadcast.log", "a")) {
			fputs($fh, "\t$msg Sent.\n");
			fclose($fh);
		}
	}
?>
```
)
7) Add to cron job php responder/robot/check_deliver_followup_messages.php once at one day
(

```
<?php
// Sends follow-up and instant messages
// Set CRON for each 5 minutes
// Written by Michel Komarov [url]http://icoder.com[/url] (2005-12-13)
function error_page($error_message) { return $error_message; }
	$bunchSize = 300;
	$bunchPause = 60; //sec
	$bunchInterval = 600; //sec (from CRON timing)
	$cron_file = "../temp/followup.cron";
	if (file_exists($cron_file)) {
		$cron = file_get_contents($cron_file);
		if ((5 * $bunchInterval) + $cron > time()) exit;
	}
	if ($fh = fopen($cron_file, "w")) {
		fputs($fh, time());
		fclose($fh);
	}

	require("../include/globals.php");
	require("../include/db_mysql.php");
	require("../include/phpmailer.php");
	require("../include/mail.php");

	class DB_Sql_Log extends DB_Sql {
		var $Write_Log = false;
		var $Halt_On_Error = "report";
		function haltmsg($msg) {
			if ($this->Write_Log && ($fh = fopen("../temp/followup.log", "a"))) {
				fputs($fh, "Database error: $msg\nMySQL Error: {$this->Errno} ($this->Error)\n");
				fclose($fh);
			}
		}
	}

	set_time_limit(0);
	$db  = new DB_Sql_Log;
	$db2 = new DB_Sql;
	$query = "SELECT messages_id, subscribers_id, subscribers_email, messages_interval
					FROM messages, subscribers, users
					WHERE 
					users_id = messages_user_id AND
					users_id = subscribers_user_id AND
					subscribers_active = '1' AND
					subscribers_trouble_mailing < 2 AND
					messages_interval > subscribers_messages_interval AND
					TO_DAYS(subscribers_join_date + INTERVAL messages_interval DAY) = TO_DAYS(NOW()) ";
	$db->query("$query ORDER BY messages_interval");
	if (0 == $db->Errno && ($count = $db->num_rows()) > 0) {
		if ($fh = fopen("../temp/followup.log", "a")) {
			fputs($fh, "\n".date("Y-m-d H:i:s")." Messages: $count\n");
			fclose($fh);
		}
		$db->Write_Log = true;
		$msg = 0;
		while ($db->next_record()) {
			if (0 == ((++$msg) % $bunchSize)) {
				if ($fh = fopen("../temp/followup.log", "a")) {
					fputs($fh, "\t$msg sent\n");
					fclose($fh);
				}
				if ($fh = fopen($cron_file, "w")) {
					fputs($fh, time());
					fclose($fh);
				}
				sleep($bunchPause);
			}
			$message_id = $db->f("messages_id");
			$subscriber_id = $db->f("subscribers_id");
			$subscriber_email = $db->f("subscribers_email");
			$messages_interval = $db->f("messages_interval");

			$error = SendMessage2Subscriber($message_id, $subscriber_id);
			if ($error) {
				if ($fh = fopen("../temp/followup.log", "a")) {
					fputs($fh, date("\tCan't send $subscriber_email\n"));
					fclose($fh);
				}
			}

			$db2->query("UPDATE subscribers
							SET subscribers_messages_interval='$messages_interval'
							WHERE subscribers_id='$subscriber_id'");
		}
	}
	unlink($cron_file);
	if ($count > 0) {
		if ($fh = fopen("../temp/followup.log", "a")) {
			fputs($fh, "\t$msg Sent.\n");
			fclose($fh);
		}
	}
?>
```
)

8) Add to cron job php responder/robot/check_instant_messages.php once at a minute 
(

```
<?php
	// scriptul se executa la fiecare 1 minut
	// si verifica daca in INBOX (pt account-ul [email protected]{sitename})
	// au sosit mesaje destinate utilizatorilor (de ex: [email protected]{sitename})
	// daca da, atunci inregistram persoana care a trimis mail ca si 
	// un subscriber pt utilizatorul "myuser", si in trimitem toate mesajele instante
function error_page($error_message) { } 

	require("imap_globals.php");
	require("imap_functions.php");
	require("../include/globals.php");
	require("../include/db_mysql.php");
	require("../include/phpmailer.php");
	require("../include/mail.php");

	set_time_limit(0);
	$db = new DB_Sql;

	$message_box = imap_open("{".$MailHost.":110/pop3}INBOX", $MailUser, $MailPassword);

	if ($message_box != false)
	{
		$message_number = imap_num_msg($message_box);
		$headers = getHeaders($message_box, 1, $message_number);

		// parcurgem mesajele
		for ($i=1; $i<=$message_number; $i++)
		{
			$subject = $headers[$i][2];
			$uid = $headers[$i][6];
			$from_name = $headers[$i][1];

			// extragem numai numele (fara adresa de mail)
			$pos = strpos($from_name, "<");

			if ($pos === false)
				$from_name = $from_name;
			else
			    $from_name = substr($from_name, 0, $pos);

			$head = imap_fetchheader($message_box, $uid, FT_UID);
			$header_info = imap_headerinfo($message_box, $uid, FT_UID);

			$from = $header_info->from;
			$to = $header_info->to;

			foreach ($from as $id => $object)
			{
				$from_address = $object->mailbox . "@" . $object->host;
			}

			foreach ($to as $id => $object)
			{
				$to_address = $object->mailbox . "@" . $object->host;
				$to_user = $object->mailbox;
			}

			$body = imap_body($message_box, $uid, FT_INTERNAL);

			// vedem daca mesajul este adresat vreunui user al aplicatiei
			$query = "SELECT * 
						FROM users 
						WHERE users_username = '$to_user' ";
			$db->query($query);

			if ($db->num_rows() != 0)
			{
				// da, exista un user caruia i se adreseaza mailul primit
				$db->next_record();
				$user_id = $db->f("users_id");

				// verificam daca nu avem deja un subscriber cu email-ul dat
				// pt user-ul caruia i s-a trimis email
				$query = "SELECT * 
							FROM subscribers
							WHERE 
								subscribers_user_id = '$user_id' AND
								subscribers_email = '$from_address' ";
				$db->query($query);

				if ($db->num_rows() != 0)
				{
					// gasim id-ul subscrisului
					$db->next_record();
					$subscriber_id = $db->f("subscribers_id");
				}
				else
				{							
					// inregistram persoana care a trimis mail 
					// ca subscriber al user-ului caruia ii era destinat mail-ul
					$_head = addslashes($head);
					$query = "INSERT INTO subscribers (
							    subscribers_name,
							    subscribers_email,
							    subscribers_user_id,
							    subscribers_header,
							    subscribers_join_date
							    ) VALUES (
							    '$from_name',
								'$from_address',
							    '$user_id',
								'$_head',
							    NOW()
							    )";
					$db->query($query);

					// gasim id-ul subscrisului numai ce adaugat
					$subscriber_id = mysql_insert_id($db->link_id());
				}

				// trimitem toate mesajele instante ale user-ului subscrisului				
				$query = "SELECT * 
							FROM messages 
							WHERE 
								messages_user_id = '$user_id' AND
								messages_interval = '0' AND
								messages_disabled = '0' ";
				$db->query($query);

				while ($db->next_record())
				{
					SendMessage2Subscriber($db->f("messages_id"), $subscriber_id);
				}

				// stergem mesajul
				imap_delete ($message_box, $uid, FT_UID);
			}
		}

		imap_expunge($message_box);
		imap_close($message_box);
	}

?>
```
)

If you have ability it would be better to install the check_POP3_mailbox.pl Perl-script.
It has a powerful bounced email manager.

The check_POP3_mailbox.pl requires the Net:OP3, DBI and DBD::mysql modules installed.

You have to edit the variables inside the file:

# pop3 mail server connection parameters
$mailHost = "yourdomain.com"; Please explain
$mailUser = "username"; Which username???
$mailPassword = "password";

# Database connection parameters
$dbName = "responder";
$dbUser = "responder";
$dbPass = "password";
$dbHost = "localhost";

You should upload the check_POP3_mailbox.pl file into cgi-bin folder with ASCII-text ftp-mode
then set permissions (chmod) to 755.
Set the cron job (point 8) as
/usr/bin/perl /absolute-path/cgi-bin/check_POP3_mailbox.pl


*This email address must have the ability to catch all emails received
for that domain that have no address (catch all, default email address)

Running The Software:
Login: http://www.yoursite.com/responder/index.php


Thanks in advance for yourhelpray:
Heero1


----------



## KoosHopeloos (Nov 3, 2004)

@ Heero1: Welcome to TSF!

I'm not quite sure how we can help you. Can you be more specific? Where do you get stranded?


----------



## heero1 (Feb 6, 2007)

opt in page is on my website with name and email caputuring box.when I filled in name and email(to test)following message pops up:

404 Error - Not Found 
The resource you have requested could not be found on the server. There are many possible reasons for this. Either the file does not exist, there is an error in your request, or the file is not accessible in the requested directory. Please verify that:

You have used the proper case; requests ARE case-sensitive! 
You have entered the URL correctly. (i.e. proper directory/filename) 
You used the FULL URL. (i.e. proper file type: .html, .gif , .jpg, etc.) 
You use a tilde (~) before user directories. (i.e. www.furcen.org/~jurann/ ) 
The user/file still exists on this server.


----------



## KoosHopeloos (Nov 3, 2004)

@ heero1: Have you followed the instructions to set up the responder as you gave in your first post?


----------



## ezeemart (Jun 20, 2008)

I have the same problem and can't seem to figure out as I am also trying to install an autoresponder. Can anyone help me.


----------



## chaosprime (Jun 20, 2008)

This means that the form submission URL (action attribute on the form tag) in your form document is wrong. It's not clear to me how that gets set up when you're using this software, but it's where the problem is.


----------



## BestBizOps4u (Jun 6, 2009)

I am trying to install Media Autoresponder. I am stuck on step 3. 

3) Modify the MYSQL database information using the new database
you have just created in the file include/globals.php 

How do I modify MYSQL and how do I access it to modify?


----------



## BestBizOps4u (Jun 6, 2009)

I wish I could get help with my Media Autoresponders but it looks like this forum has been abandoned.


----------



## wmorri (May 29, 2008)

Give it a little time. Some of the staff, has a life outside of the forum. But they will be back to help you.


----------



## dm01 (Oct 10, 2006)

Due to the many now-inactive users who have posted on this thread, I have made the decision to lock this thread.

@suemd: I have moved your post to its own thread.

If you still require assistance, please make a NEW thread. Hijacking a thread is not looked upon with kindness.

Thank you for your understanding.


----------

