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
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!

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.