topflight Posted April 18, 2009 Share Posted April 18, 2009 I have this mass email script but it is not working please help: <?php include 'db.php'; $message = $_POST['message']; $subject = $_POST['subject']; if(isset($_POST['submit'])){ if((!$message | !$subject)){ echo'You are missing some required information please go back and fill out all the required information'; } else { $sql = mysql_query("SELECT * FROM members ORDER BY 'id' ASC"); $result = mysql_fetch_assoc($sql); $bcc = $result["email"]; for ($index=0; $index < count($bcc); $index++) { $from = 'email'; $to = 'email'; $header .= "Bcc: ".$bcc."\r\n"; $headers .= 'From: <no-reply@domain.org>' . "\r\n"; mail($to,$subject, $message, $headers); }}}?> Quote Link to comment https://forums.phpfreaks.com/topic/154646-solved-e-mail-problems/ Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 You are never looping the results returned: <?php include 'db.php'; $message = $_POST['message']; $subject = $_POST['subject']; if(isset($_POST['submit'])){ if((!$message | !$subject)){ echo'You are missing some required information please go back and fill out all the required information'; } else { $sql = mysql_query("SELECT email FROM members ORDER BY `id` ASC"); if (mysql_num_rows($sql)) { $bcc = array(); while ($result = mysql_fetch_assoc($sql)) { $bcc[] = $result["email"]; } $from = 'email'; $to = 'email'; $header = "Bcc: ".implode("\r\n", $bcc)."\r\n" $header .= 'From: <no-reply@domain.org>' . "\r\n"; mail($to, $subject, $message, $header); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154646-solved-e-mail-problems/#findComment-813200 Share on other sites More sharing options...
topflight Posted April 18, 2009 Author Share Posted April 18, 2009 when I used that code all the emails were display in the message and the message displayed at the bottom. Quote Link to comment https://forums.phpfreaks.com/topic/154646-solved-e-mail-problems/#findComment-813224 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 Sorry, my mistake, the bcc emails should be seperated by a comma not a newline: <?php include 'db.php'; $message = $_POST['message']; $subject = $_POST['subject']; if(isset($_POST['submit'])){ if((!$message | !$subject)){ echo'You are missing some required information please go back and fill out all the required information'; } else { $sql = mysql_query("SELECT email FROM members ORDER BY `id` ASC"); if (mysql_num_rows($sql)) { $bcc = array(); while ($result = mysql_fetch_assoc($sql)) { $bcc[] = $result["email"]; } $from = 'email'; $to = 'email'; $header = "Bcc: ".implode(", ", $bcc)."\r\n" $header .= 'From: <no-reply@domain.org>' . "\r\n"; mail($to, $subject, $message, $header); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154646-solved-e-mail-problems/#findComment-813228 Share on other sites More sharing options...
topflight Posted April 18, 2009 Author Share Posted April 18, 2009 I am using that code and it not sending to all the emails in the database. for the $to should I create an another account like no-reply@domain.org and for $from should it be $no-reply@domiain.org . Because that code is not sending to no one in the database. Quote Link to comment https://forums.phpfreaks.com/topic/154646-solved-e-mail-problems/#findComment-813230 Share on other sites More sharing options...
topflight Posted April 18, 2009 Author Share Posted April 18, 2009 it works thanks, just had to wait for a min. Quote Link to comment https://forums.phpfreaks.com/topic/154646-solved-e-mail-problems/#findComment-813233 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 I'm pretty sure there's a limit to the number of bcc's you can have (poss 250?). Personally I'd use a pre built system like phpmailer that handles this sort of thing for you. Quote Link to comment https://forums.phpfreaks.com/topic/154646-solved-e-mail-problems/#findComment-813246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.