jmr3460 Posted December 10, 2010 Share Posted December 10, 2010 Hey guys, I have an array for sending email from a form and don't know why it is only sending mail to the first email. Can anyone help? $web_contacts = array('[email protected]', '[email protected]'); $table = "<table>\n".$fullname.$email.$comments."</table>\n"; foreach($web_contacts as $web_contact){ $sender = $_POST['email']; $to = trim($web_contact); $subject = "Feedback from Web Form"; $headers = "From: [email protected]" . "\r\n" . "Reply-To: $sender" . "\r\n" . "X-Mailer: PHP/" . phpversion(); $headers .= "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $body = "<html><body>".$table."</body></html>"; $mail = mail($to, $subject, $body, $headers); if($mail){ header("Location: thank_you.php?action=feedback"); exit(); } else{ echo "The Server had a hicup please contact the webcontact and let us know when and where this happened."; } } Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/221183-email-array/ Share on other sites More sharing options...
Jocka Posted December 10, 2010 Share Posted December 10, 2010 if($mail){ header("Location: thank_you.php?action=feedback"); exit(); } A: Once u navigate away i would assume the foreach loop stops B: Exit ends the foreach loop Link to comment https://forums.phpfreaks.com/topic/221183-email-array/#findComment-1145217 Share on other sites More sharing options...
jmr3460 Posted December 10, 2010 Author Share Posted December 10, 2010 OK I will look at that. Thanks for the reply Link to comment https://forums.phpfreaks.com/topic/221183-email-array/#findComment-1145228 Share on other sites More sharing options...
jmr3460 Posted December 10, 2010 Author Share Posted December 10, 2010 What I found was that when I create an array there is a key created and for me to reference all of then I counted the number of values in the array and then sent an email one at a time until the array key value was equal to the number that was counted in the array. I probably should have done it with a for loop. Anyway I got it to work for now. I am going to work on it later this weekend for a better and cleaner script. All of my other scripts draw the email from a database and I used a while loop. Link to comment https://forums.phpfreaks.com/topic/221183-email-array/#findComment-1145243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.