Does anyone have any idea why the script below sends about 6 copies of the email created to each person ?
<?
header ("Pragma: no-cache");
header ("Cache-Control: no-cache, must-revalidate");
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
include("includes/connect.php3");
include("includes/sendmail.inc");
?>
<head><title> MAILER</title></head></body>
<?
$headers .= "X-Sender: <synergy@ndirect.co.uk>\n";
$headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "Return-Path: <synergy@ndirect.co.uk>\n"; /
$fromaddress="synergy@ndirect.co.uk";
$subject="Test";
$body="test";
$sql = "SELECT * FROM stevetest where mail<>' ' ";
$match2= mysql_query("$sql");
while ($result2 = mysql_fetch_array($match2))
{ ++$i;
mailfrom($fromaddress, $result2[mail], $subject, $body, $headers) ;
echo "$i Mailed $result2[mail]<br>";
}
echo "Finished Mailing<br>";
?></body>
connect.php3 connects to my database
sendmail.inc is below
<?
function mailfrom($fromaddress, $toaddress, $subject, $body, $headers) {
$fp = popen('/usr/sbin/sendmail -f'.$fromaddress.' '.$toaddress,"w");
if(!$fp) return false;
fputs($fp, "To: $toaddress\n");
fputs($fp, "Subject: $subject\n");
fputs($fp, $headers."\n\n");
fputs($fp, $body);
fputs($fp, "\n");
pclose($fp);
return true;
}
?>
Steve