How can I get this form submit to work properly?
The following code is what I am using to e-mail me the contents of a form. I am having two problems with it and was hoping someone could help.
- I have checkboxes on the form, and when multiple boxes of the same group are checked, the e-mail I receive only shows the last box that was checked and not all that were checked.
- I have a
<textarea>
on the form and it doesn't show up in the e-mail sent to me either.
The PHP code:
<?php
header('Location: thank-you.html');
$from = $_POST['email'];
$to = 'email@exam开发者_运维百科ple.com';
$subject = "subject";
$message = "";
foreach ($_POST as $k=>$v)
{
if (!empty($message)) { $message .= "\n\n"; }
$message .= ucwords(str_replace('_',' ',$k)).": ".$v;
}
$headers = "From: $from";
mail($to, $subject, $message, $headers);
?>
you probably have checkbox groups like this:
<input type=checkbox name=box value='one'>
<input type=checkbox name=box value='two'>
when they should look like this (with square brackets after the name)
<input type=checkbox name=box[] value='one'>
<input type=checkbox name=box[] value='two'>
php will then store the values in an array in $_POST['box']
, which you can then join into comma delimited string inside your existing print code somewere with implode(', ', $_POST['box'])
for formatting.
精彩评论