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('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.

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.