I have made a very basic form mail script and I am POSTing multiple fields to it. Here's what I have: <? // Mail Settings $to = 'XXXXXXXXXXXXXX'; $subject = 'Mail from: '.$_SERVER["SERVER_NAME"].''; $from_name= 'Mailer'; $from_email = 'mail@'.$_SERVER["SERVER_NAME"].''; $headers = 'From: ' . $from_name . ' <' . $from_email . ">\r\n" . 'Reply-To: ' . $email . "\r\n"; foreach($_POST as $key => $value) $body = array($key.": ".$value); // Send the Mail mail($to , $subject, $body, $headers) or die ('Something went a little wrong.'); echo "Your form was sucessfully sent."; ?> PHP: It works but it only send one field on the form page to the email address specified... Probably something easy but I'm just beginning with PHP so don't shoot me
Try enclosing all the foreach commands in brackets, like this... foreach($_POST as $key => $value) { // Your email code here } PHP: Also, try doing a var_dump($_POST); to make sure your form is sending all the fields correctly.
just a fast notice, but i think from your code, you will only receive the data from the last field. Maybe this will fix it: instead of: foreach($_POST as $key => $value) $body = array($key.": ".$value); PHP: consider something like: $body = ""; foreach($_POST as $key => $value) $body .= $key.": ".$value."\n"; PHP:
That's also a good sugestion, compiling all the post variables in one variable rather than sending each individually. Saves time and effort on your mailserver aswell.