Jump to content

email array


jmr3460

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.