I want to query my database with a SELECT statement and send email to the results:
$username="********";
$password="********";
$database="********";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"
;
$query="SELECT email2,handle,passwrd FROM profiles WHERE status = 'old'";
$result=mysql_query($query) or die (mysql_error());
$num=mysql_numrows($result);
$i=0;
while ($i<$num){
$handle=mysql_result($result,$i,"handle"
;
$email2=mysql_result($result,$i,"email2"
;
$passwrd=mysql_result($result,$i,"passwrd"
;
//add From: header
$headers = "From: webmaster@$SERVER_NAME\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = uniqid("HTMLDEMO"
;
//tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/alternative" .
"; boundary = $boundary\r\n\r\n";
//message to people with clients who don't
//understand MIME
$headers .= "Important notice from webmaster\r\n\r\n";
//plain text version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/plain; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("Dear $handle,\r\n Please login with these details username:$handle. Pasword:$passwrd."
);
//HTML version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("Dear $handle,<p>
Please login with these details username:$handle. Pasword:$passwrd"
);
$recipient = "$email2";
$subject = "Important notice from webmaster";
$message = "";
$extra = "From: webmaster@$SERVER_NAME\nReply-To: webmaster@$SERVER_NAME";
mail ($recipient, $subject, $message, $headers) or die("No go"
;
++$i;
}
But this sends 8 emails to each account!Can anyone explain why this does so? I think it must be a problem with the loop or something. Thanks in advance.
$username="********";
$password="********";
$database="********";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"

$query="SELECT email2,handle,passwrd FROM profiles WHERE status = 'old'";
$result=mysql_query($query) or die (mysql_error());
$num=mysql_numrows($result);
$i=0;
while ($i<$num){
$handle=mysql_result($result,$i,"handle"

$email2=mysql_result($result,$i,"email2"

$passwrd=mysql_result($result,$i,"passwrd"

//add From: header
$headers = "From: webmaster@$SERVER_NAME\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = uniqid("HTMLDEMO"

//tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/alternative" .
"; boundary = $boundary\r\n\r\n";
//message to people with clients who don't
//understand MIME
$headers .= "Important notice from webmaster\r\n\r\n";
//plain text version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/plain; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("Dear $handle,\r\n Please login with these details username:$handle. Pasword:$passwrd."

//HTML version of message
$headers .= "--$boundary\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode("Dear $handle,<p>
Please login with these details username:$handle. Pasword:$passwrd"

$recipient = "$email2";
$subject = "Important notice from webmaster";
$message = "";
$extra = "From: webmaster@$SERVER_NAME\nReply-To: webmaster@$SERVER_NAME";
mail ($recipient, $subject, $message, $headers) or die("No go"

++$i;
}
But this sends 8 emails to each account!Can anyone explain why this does so? I think it must be a problem with the loop or something. Thanks in advance.