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('webcontact@eascna.org', 'jmr3460@comcast.net'); $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: webcontact@whatever.org" . "\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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.