Elvin,
Thanks for replying. I see what you want to do now. However, just a suggestion: if the newsletter is public (ie not just between people who know each other) then you probably want to avoid putting everybody in the "To:" field of the e-mail. Basically, people are not going to be very pleased if their e-mail address is published to everybody else on the newsletter mailing list.
If that is the case, then despite the overhead, you would want to do a separate mail() to each address. Alternatively, send it "To:" yourself and put everyone in a "Bcc:" field, but I'm not sure if there is a limit to how many address you can "Bcc:" to.
Here's one solution:
<?
$conn = mysql_connect("localhost","username","passwd");
if( !$conn ) {
echo "Error connecting: ",mysql_error();
exit();
}
$res = mysql_query("SELECT email FROM yourtable", $conn);
if( !$res || mysql_num_rows($res)<1 ) {
echo "Error: ",mysql_error($conn);
exit();
}
$mailbcc = mysql_result($res,0,"email");
for( $i = 1; $i < mysql_num_rows($res); $i++ ) {
$mailbcc .= ", " . mysql_result($res,$i,"email");
}
if( !mail("elvin@eircom.net","Newsletter Subject","Newsletter Body","bcc: ".$mailbcc."\n") ) {
echo "Error: mail sending failed";
exit();
}
?>
That is fairly rough and you'll have to customise it, but it should do the job. Only your address will be visible to all the recipients then. The alternative is to do this:
<?
$conn = mysql_connect("localhost","username","passwd");
if( !$conn ) {
echo "Error connecting: ",mysql_error();
exit();
}
$res = mysql_query("SELECT email FROM yourtable", $conn);
if( !$res || mysql_num_rows($res)<1 ) {
echo "Error: ",mysql_error($conn);
exit();
}
for( $i = 0; $i < mysql_num_rows($res); $i++ ) {
if( !mail(mysql_result($res,$i,"email"),"Newsletter Subject","Newsletter Body") ) {
echo "Error sending mail to ",mysql_result($res,$i,"email");
}
}
?>
Which would send a separate e-mail to every person. This would have a much higher overhead than the Bcc route.
Hope this helps,
Louis