Anyone can provide me a code for sending checkbox value to email?
I have three checkboxes for requesting catalogs. I would like to get value for all three of them in each email.
Here is my HTML code
<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
And here is my 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>';
}
}
I would very appreciate your help!
Aucun commentaire:
Enregistrer un commentaire