Multiple PHP email message function. (checkboxes)
What should I type in PHP instead of I got now to receive in mail all of the answers typed in checkboxes by user. Now I have only one. Thanks PHP:
$email_message .= "Sport: ".clean_string($_POST["sport"])."\n"; $email_message .= "Music: ".clean_string($_POST["music"])."\n";
koszykówka
sporty zimowe
jeździectwo konne festiwale
wesołe miasteczka
paintball,bilard,kręgle..
Edit: Thanks but not exactly can type different ‘names’ cause I also have one checkboxe to set all on check at once and it works with JS like this:
kluby
puby
koncerty
festiwale
wesołe miasteczka
paintball,bilard,kręgle.
1 Answer 1
I’m not 100% sure what it is you’re asking here, but if you’d like to see if a checkbox is set you can do the following:
if(isset($_POST['checkbox-name-here'])) < //it's set code here, maybe set a variable. $var = "checkbox value";>
That’s a rough example, but you should get the drift.
If you’re trying to get multiples — then give each checkbox a unique name:
koszykówka
sporty zimowe
jeździectwo konne
Then in PHP you can check if each value is set:
if(isset($_POST['sport1'])) if(isset($_POST['sport2'])) if(isset($_POST['sport3'])) $email_message .= "Sports: ".clean_string($_POST["sport1"])."\n" .clean_string($_POST["sport2"])."\n" .clean_string($_POST["sport3"])."\n";
There are much tidier ways of doing it, but that should help you work it out?
How to send checkbox values in contact form using php?
Actually am having a contact form consist of check-boxes. i am able to send all the form values to email but i don’t know how to send values of check-boxes selected in form.
echo" ;"; if (!empty($contact_name) && !empty($contact_phone) && !empty($contact_email) && !empty($contact_text)) < $to = 'rameshjoe381@gmail.com'; $subject = 'Enquiry Form Submitted.'; $body = "Name: ".$contact_name."\n\n"."Phone No: ".$contact_phone."\n\n"."Message: ".$contact_text."\n\n"."Products: ".$check_msg."\n\n"."Location: ".$contact_loc; $headers = 'From: '.$contact_email; if (@mail($to, $subject, $body, $headers)) window.location.href='index.html' "; > else< alert("Error Sending Mail."); echo " "; > >else< alert("All Fields are required."); echo " "; > > ?>
Using checkboxes to select the to email address in a contact form
I’ve created an email form that is supposed to be sent to two different email addresses depending on which check box is selected. But am having real trouble trying to make it work, Let me show you what I’m tying to do. Baring in mind the form actually works great it’s just the to email via the checkbox that’s failing me. Please Help! This is the Form section: