我有三个复选框用于请求目录。我想在每封电子邮件中为所有这三个人获得价值。
这是我的HTML:
<input type="checkbox" name="catalog" value="Grower"/> Grower Supply Catalog <br><br>
<input type="checkbox" name="catalog" value="Specialty"/> Specialty Catalog<br><br>
<input type="checkbox" name="catalog" value="Plant"/> Plant Source Catalog
这是我的PHP:
$name = @$_POST["name"];
$email = @$_POST["email"];
$street = @$_POST["street"];
$city = @$_POST["city"];
$state = @$_POST["state"];
$zip = @$_POST["zip"];
$email = @$_POST["email"];
$phone = @$_POST["phone"];
$message = @$_POST["comment"];
$catalog =@$_POST["catalog"];
foreach($_POST['catalog'] as $value) {
$check_msg .= "Checked: $value\n";
}
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
$mailBody = "You have been contacted by $name" . PHP_EOL . PHP_EOL;
$mailBody .= (!empty($company))?'Company: '. PHP_EOL.$company. PHP_EOL . PHP_EOL:'';
$mailBody .= (!empty($quoteType))?'project Type: '. PHP_EOL.$quoteType. PHP_EOL . PHP_EOL:'';
$mailBody .= "Street :" . PHP_EOL;
$mailBody .= $street . PHP_EOL . PHP_EOL;
$mailBody .= "City :" . PHP_EOL;
$mailBody .= $city . PHP_EOL . PHP_EOL;
$mailBody .= "State :" . PHP_EOL;
$mailBody .= $state . PHP_EOL . PHP_EOL;
$mailBody .= "Zip :" . PHP_EOL;
$mailBody .= $zip . PHP_EOL . PHP_EOL;
$mailBody .= "Phone :" . PHP_EOL;
$mailBody .= $phone . PHP_EOL . PHP_EOL;
$mailBody .= $check_msg .= "Catalog : $catalog\n";
$mailBody .= "Message :" . PHP_EOL;
$mailBody .= $message . PHP_EOL . PHP_EOL;
$mailBody .= "You can contact $name via email, $email.";
$mailBody .= (isset($phone) && !empty($phone))?" Or via phone $phone." . PHP_EOL . PHP_EOL:'';
if(mail($to, $subject, $mailBody, $headers)){
echo '<div class="alert alert-success">Success! Your message has been sent.</div>';
}
}
如何将复选框值发送到电子邮件?
答案 0 :(得分:1)
使用这些元素名称的数组语法将这些值作为数组发送:
<input type="checkbox" name="catalog[]" value="Grower"/> Grower Supply Catalog <br><br>
<input type="checkbox" name="catalog[]" value="Specialty"/> Specialty Catalog<br><br>
<input type="checkbox" name="catalog[]" value="Plant"/> Plant Source Catalog
答案 1 :(得分:-1)
我认为您应该正确输入foreach()方法,键入camelCase像这样forEach()