php - Contact form with check boxes having troubles -
i need add check boxes contact form have html.
<form action="contact.php" method="post"> name<br><input type="text" name="cf_name"><br> e-mail<br><input type="text" name="cf_email"><br> message<br><textarea name="cf_message"></textarea><br> <input type="submit" value="send"> <input type="reset" value="clear"> </form>
and here php part of code
<?php $field_name = $_post['cf_name']; $field_email = $_post['cf_email']; $field_message = $_post['cf_message']; $mail_to = 'example@example.com'; $subject = 'message site visitor '.$field_name; $body_message = 'from: '.$field_name."\n"; $body_message .= 'e-mail: '.$field_email."\n"; $body_message .= 'message: '.$field_message; $headers = 'from: '.$field_email."\r\n"; $headers .= 'reply-to: '.$field_email."\r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('thank message. contact shortly.'); window.location = 'contact.html'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('message failed. please, send email help@helpme.com'); window.location = 'contact.html'; </script> <?php } ?>
i need adding groups of check boxes can check 1 box each of groups , send email list of check boxes picked each group.
use code <form action="contact.php" method="post"> name<br><input type="text" name="cf_name"><br> e-mail<br><input type="text" name="cf_email"><br> message<br><textarea name="cf_message"></textarea><br> check boxes: <input type="checkbox" name="abc[]" value="car">car<br/> <input type="checkbox" name="abc[]" value="bus">bus<br/> <input type="submit" value="send"> <input type="reset" value="clear"> </form> <?php $field_name = $_post['cf_name']; $field_email = $_post['cf_email']; $field_message = $_post['cf_message']; // check boxess $check_box_values = "check box value: "; if(isset($_post['abc'])){ foreach($_post['abc'] $value){ $check_box_values .= $value; $check_box_values .= ', '; } } // end check boxess $mail_to = 'example@example.com'; $subject = 'message site visitor '.$field_name; $body_message = 'from: '.$field_name."\n"; $body_message .= 'e-mail: '.$field_email."\n"; $body_message .= 'message: '.$field_message."\n".$check_box_values; $headers = 'from: '.$field_email."\r\n"; $headers .= 'reply-to: '.$field_email."\r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('thank message. contact shortly.'); window.location = 'contact.html'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('message failed. please, send email help@helpme.com'); window.location = 'contact.html'; </script> <?php } ?>
Comments
Post a Comment