Php email form with checkboxes

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.

 

* Post Your Comments

Name:
Phone:
Email:
Products:  
Tomato: Bitter Gourd: Capsicum:
Chillies: Ladies Finger: Cabbage:
Bottle Gourd: Drumstick: Beans:
Location:
Comments:
 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:

 
Name: "> Department: Email: "> Phone: ">
Message: Human Verification:
+ 3 = 5
  ?> "; else $response = " "; > //response messages $not_human = "Human verification incorrect."; $missing_content = "Please supply all information."; $email_invalid = "Email Address Invalid."; $message_unsent = "Message was not sent. Try Again."; $message_sent = "Thanks! Your message has been sent."; //user posted variables $name = $_POST['message_name']; $email = $_POST['message_email']; $phone = $_POST['phone_number']; $message = $_POST['message_text']; $human = $_POST['message_human']; //php mailer variables $to = $admin_email; $subject = "Someone sent a message from "; $headers = 'From: '. $email . "\r\n" . 'Reply-To: ' . $email . "\r\n"; $tel = 'Contact no: ' . $phone; if(!$human == 0) < if($human != 2) generate_response("error", $not_human); //not human! else < //validate email if(!filter_var($email, FILTER_VALIDATE_EMAIL)) generate_response("error", $email_invalid); else //email is valid < //validate presence of name and message if(empty($name) || empty($message))< generate_response("error", $missing_content); >else //ready to go! < $sent = mail($to, $subject, $message . $tel , $headers); if($sent) generate_response("success", $message_sent); //message sent! else generate_response("error", $message_unsent); //message wasn't sent >> > > else if ($_POST['submitted']) generate_response("error", $missing_content); ?> 

Источник

PHP Contact form with checkboxes

I’m having a terrible time trying to get my contact form to work. I have almost no php experience. I am trying to make this form e-mail to myself but have no idea what I am doing basically. I need it to e-mail a copy of the form to my e-mail and also make sure the checkboxes show which boxes were clicked. If anyone could help I would appreciate it. Here is my html

 
 None
 Coffee
 Vending
 Water Coolers
 Cafeteria

Try turning on warnings. It may help diagnose the issue. Also, double check the spelling of your e-mail address to be sure that it is correct.

2 Answers 2

also you shouldn’t have the same name=»name» in your html, for company it should be name=»company». This will then get passed to post variable $_POST[‘company’]

I actually caught that too. The test emails I was getting had no name and company name under name. Thanks

Here is a sample code, which uses SELECT , CHECKBOX , TEXTBOX to get you going:

  
Regulatory Revenue Enhancement
 // Clean up the input values foreach($_POST as $key => $value) < $_POST[$key] = stripslashes($_POST[$key]); $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key])); >$esponsor = trim(strip_tags(stripslashes($_POST['esponsor']))); $sponsorinform = trim(strip_tags(stripslashes($_POST['sponsorinform']))); $pj_regulatory = trim(strip_tags(stripslashes($_POST['pj_regulatory']))); $pj_revenhancement = trim(strip_tags(stripslashes($_POST['pj_revenhancement']))); echo $esponsor; //displays the text entered echo $sponsorinform; //displays YES or NO echo $pj_regulatory; echo $pj_revenhancement; $sentMailSubject = "Project Request From $customerfname $customerlname"; // To send HTML mail, the Content-type header must be set $sentHeader = 'MIME-Version: 1.0' . "\r\n"; $sentHeader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers //$to = 'aidan@example.com' . ', '; // note the comma //$to .= 'wez@example.com'; // ^^^^^ for multiple email address $sentHeader .= 'From: ' . $customerfname . ' ' . "\r\n"; $sentMailBody = "TEST"; $toEmail = "youremail@yourdomain.com, someoneelse@some.com"; mail($toEmail, $sentMailSubject, $sentMailBody, $sentHeader); //send to us 

Источник

how to submit form checkboxes to an email address?

I have created an html file accompanied with a php script. The php script will send the form in html to my email address. I tested it and everything is perfect but only the checkboxes. the php script sends me only one option of the checked checkboxes. how to fix this? Please help and thank you in advance. MY HTML FILE

     

Name*

Email address*

Select your gender*

Male        Female

Select your age*



1) From where did you hear about Angrybullet2 ?

Search engines (google, yahoo, bing, … )
From a friend
From YouTube
Other


2) Are you subscribed to Angrybullet2 ?

Yes, I am
No, but I wish to subscribe
No, I am not, and I won't subscribe
I don't have a YouTube account


3) How many videos of Angrybullet2 did you watch ?

None
1-2
3-4
5-9
10 and more


4) Did you enjoy watching videos from Angrybullet2 ?

Yes, I did
No, I didn't
I watched none of your videos


5) What was the type of the video(s) you watched ?

Tutorial(s) (how to)
Sound effect(s)
Experiment(s)
I watched none of your videos


6) Do you have any suggestion in order to make Angrybullet2 better ?

Источник

Читайте также:  Html style width example
Оцените статью