Jump to content

Why is this code sending two emails?


munnaz

Recommended Posts

Hi,  Just wondering if you can figure out why this code is sending two emails?? I can't figure it out.

 

<?php 
$recent=$_GET['recent'];
$sendemail=$_GET['sendemail'];

mysql_close($conn);

$output = 'no';

$dbhost = '*********';
$dbuser = '*********';
$dbpass = '*********';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('MYSQL N/A - Please Contact Admin');

$dbname = 'documentaries';
mysql_select_db($dbname);

$query1  = "SELECT * FROM table1";
$result1 = mysql_query($query1);
$num1    = mysql_numrows($result1);

if(is_int($num1/10)){
$output = 'yes';
}

if (($output == 'yes') && ($sendemail == 'yes')) {	

$query2  = "SELECT * FROM table2";
$result2 = mysql_query($query2);
$num2    = mysql_numrows($result2);

$i=0;

while ($i < $num2) {

$email=mysql_result($result2,$i,"email");

$subject = "Subject Here";
$msg = "Message Here";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$eLog="/tmp/mailError.log";

//Get the size of the error log
//ensure it exists, create it if it doesn't
$fh= fopen($eLog, "a+");
fclose($fh);
$originalsize = filesize($eLog);

mail($email,$subject,$msg,$headers);

/*
* NOTE: PHP caches file status so we need to clear
* that cache so we can get the current file size
*/

clearstatcache();
$finalsize = filesize($eLog);

//Check if the error log was just updated
if ($originalsize != $finalsize) {
print "<b>Problem sending mail to $email. (size was $originalsize, now $finalsize) See $eLog...<br>";
} else {
print "Mail sent $email<br>";

}

$i++;
}
// redirect
}

mysql_close($conn);

// redirect

?>

 

Thanks For your help!

Link to comment
https://forums.phpfreaks.com/topic/214801-why-is-this-code-sending-two-emails/
Share on other sites

I changed it to the following because I had them the same values and thought the num of the first query was getting mixed up with the number of the second query and then it would happen that way. I can't see anything wrong with the text you mentioned?

 

$query2  = "SELECT * FROM table2";
$result2 = mysql_query($query2);
$num2    = mysql_numrows($result2);

$query1  = "SELECT * FROM table1";
$result1 = mysql_query($query1);
$num1    = mysql_numrows($result1);

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.