Jump to content

Mail() sending duplicate E-mails


software4

Recommended Posts

I have this script that sends an E-mail to my custoemr when an account is created and does a Bcc to me. Every email gets sent once, then about 2 min later another one is sent. So both the customer and myself get 2 emails. I did a test and just after the mail() function i write to a text file. What is odd is that it logs the sent mail 2 times. So somehow it is going through it a second time. The time difference between the first and the second seem to usually be about 2-3 min.

 

For exampel this was only sent one time. My guess is there has to be something wrong with my headers, but i have been over them many times and tried different configurations.

 

To: ben@....com

Time 05/12/2011 12:18:30 am

 

To: ben@...com

Time 05/12/2011 12:21:09 am

 

<?php 


	$db_con = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); 	
	mysql_select_db($database, $db_con);

if((isset($_POST['password'])) && ($_POST['password'] == 'mandb108' )) {

	$install_date = date("Y-m-d");
$end = mktime(0, 0, 0, date("m"), date("d"), date("y")+1);
$end_date = date("Y-m-d", $end); 

$folder = $_POST['folder'];
$school_db = $_POST['school_db'];
$school_name = $_POST['school_name'];

// Check to see if school, db or folder exists
if (mysql_num_rows(mysql_query("Select * FROM $select_table WHERE `school_name` = '$school_name'"))) { 
	$message = 'School Name Already Exists in Database'; 
} elseif (mysql_num_rows(mysql_query("Select * FROM $select_table WHERE `school_db` = '$school_db'"))) {
	$message = 'Database Already Exists';
} elseif (mysql_num_rows(mysql_query("Select * FROM $select_table WHERE `school_folder` = '$folder'"))) {
	$message = 'School Folder Already Exists';
} else {



	////////////////////id, school, db, folder, install, renew, end, contact, email, job, notes  
	$insertSQL = sprintf("INSERT INTO $select_table VALUES (null, %s, %s, %s, %s, '$install_date', null, '$end_date', %s, %s, null, null)",

	GetSQLValueString($_POST['school_state'], "text"),
	GetSQLValueString($_POST['school_name'], "text"),
	GetSQLValueString($_POST['school_db'], "text"),
	GetSQLValueString($_POST['folder'], "text"),
	GetSQLValueString($_POST['contact'], "text"),
	GetSQLValueString($_POST['email'], "text"));

	mysql_select_db($database, $db_con);

	if($Result1 = mysql_query($insertSQL, $db_con) or die(mysql_error())) {
		$message = 'Added to Database - Successful<br>';
	} else { 
		$message = 'Added to Database - Failed<br>';
	}

	// Funcatiobn to copy sampel folder to new directory for school
	full_copy("01_sample","$folder");

	// Echo results
	$message .= 'Install Date - '.$install_date;
	$message .= '<br>';
	$message .= 'Expire Date - '.$end_date.'<br>';
	$message .= 'Copy of Folder - Successful<br>';
	$message .= '<br><br>School - ';
	$message .= $_POST['school_name'];
	$message .= '<br>Database - ';
	$message .= $_POST['school_db']; 
	$message .= '<br>Folder - ';
	$message .= $_POST['folder']; 
	$message .= '<br>Contact - ';
	$message .= $_POST['contact']; 
	$message .= '<br>Email - ';
	$message .= $_POST['email'];

	// Write to school_info file 
	$open = fopen ("$folder/school_info.php", "at");
	fwrite($open, "<?php\n$".$old);
	fwrite($open, "school_folder = '$folder';\n$".$old);
	fwrite($open, "school_db = '$school_db';\n$".$old);
	fwrite($open, "database = $".$old);
	fwrite($open, "school_db;\n?>".$old);
	fclose($open);


	// Link to create a database on voting site
	$message .= '<br><a href="http://www.anaheimartscouncil.com:2082/frontend/x3/sql/index.html" target="_blank">Cpanel</a><br>';

	// link to setup Database tables on new site 
	$message .= '<br><a href="'.$folder.'/index.php?install=yes&school='.$school_name.'" target="_blank">Database Setup</a><br>';
	// link to send email to client
	$message .= '<br><a href="web_install.php?email=yes&school_db='.$school_db.'">Send E-mail</a><br><br>';


	}// end if school name, databae or folder already exists	

} elseif ((isset($_GET['email'])) && ($_GET['email'] == 'yes')) {

	$school_db = $_GET['school_db'];
	$results = mysql_query("select * from tbl_schools_vote WHERE school_db = '$school_db' LIMIT 1");
	// removed the while loop to get rid of duplicate emails. 
	//while($row = mysql_fetch_array($results)){
	$row = mysql_fetch_array($results);
		$school_contact = $row['school_contact'];
		$school_folder = $row['school_folder'];
		$school_contact_email = $row['school_contact_email'];

	//} // end while loop


		$email_message = 'Dear ';
		$email_message .= $school_contact;
		$email_message .= ',<br>';


		$subject = "Voting 4 Schools - Account Activated";
		$email_message .= 'Your Voting 4 Schools account has been setup. Below is all the information that you should need to get started.<br><br>
Here is a link to your voting site. <a href="http://www.voting4schools.com/'.$school_folder.'">www.voting4schools.com/'.$school_folder.'</a><br><br>At the bottom of the page you will find an admin link. The user name and password are as follows<br><br>User Name: admin<br>Password: vote<br><br>When you log in please go to the control panel and create a new admin user and delete the default one that we have assigned you. At the top of the page you will find a link that says video tutorial. If you are unsure how to use the software, this is a great place to start. If you have any questions, or need help setting it up, please let us know.<br><br>Thank You,<br>Ben Star<br><br>Software 4 Schools<br>(866)757-7226<br><a href="http://www.software4schools.com">www.software4schools.com</a>';

		// website link here
		//$to = $school_contact_email.', support@software4schools.com';
		$to = $school_contact_email;
		//$email = 'support@software4schools.com';
		//$headers = "To: ".$school_contact_email."\r\n";
		//$headers .= "From: Software 4 Schools <support@software4schools.com>" . "\r\n";
		//$headers .= "Bcc: Software 4 Schools <support@software4schools.com>" . "\r\n";
		//$headers .= "MIME-Version: 1.0" . "\r\n";
		//$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

		$headers = 	'From: michael@anaheimartscouncil.com' . "\r\n" . 
					'Reply-To: anaheimartscouncil.com' . "\r\n" . 
					'Bcc: ben@software4schools.com' . "\r\n" .
					'Content-type: text/html; charset=iso-8859-1';
					//. "\r\n"; 
					//. 'X-Mailer: PHP/' . phpversion(); 



		if (mail($to, $subject, $email_message, $headers)) {
			$date = date('m/d/Y h:i:s a', time());
			$myFile = "mail.txt";
			$fh = fopen($myFile, 'a') or die("can't open file");
			$stringData = "To: ". $to."\n";
			fwrite($fh, $stringData);
			$stringData = "Time ". $date."\n\n";
			fwrite($fh, $stringData);
			fclose($fh);


			$message = 'E-mail was sent once';
		}else {
			$message = 'Problem sending message';
		}


	} elseif ((isset($_POST['password'])) && ($_POST['password'] != 'mandb108' )) {	

		$message = 'Password is incorrect';
		$folder = $_POST['folder'];
		$school_db = $_POST['school_db'];
		$school = $_POST['school'];
		$contact = $_POST['contact'];
		$email = $_POST['email'];


	} else {
	// not sure what to do here yet...


} // end if password isset from post
if (!isset($_POST['school_db'])) {
$school_db = 'voting_';
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.