PHP + HTML HOTEL FORM -
html
<form name="contactform" method="post" action="send_form_email.php"> <table width="450px"> <tr> <td valign="top" "> <label for="first_name ">first name *</label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="last_name">last name *</label> </td> <td valign="top "> <input type="text " name="last_name " maxlength="50 " size="30 "> </td> </tr> <tr> <td valign="top "> <label for="email ">email address *</label> </td> <td valign="top "> <input type="text " name="email " maxlength="80 " size="30 "> </td> </tr> <tr> <td valign="top "> <label for="telephone ">telephone number</label> </td> <td valign="top "> <input type="text " name="telephone " maxlength="30 " size="30 "> </td> </tr> <tr> <td valign="top "> <label for="comments ">comments *</label> </td> <td valign="top "> <textarea name="comments " maxlength="1000 " cols="25 " rows="6 "></textarea> </td> </tr> <tr> <td valign="top "> <label for="room ">room</label> <td valign="top "> <select> <option value="Ηλεκτρολογοι ">type room 1</option> <option value="Γεωπονοι ">tyre room 2</option> </select> </td> <td valign="top "> </td> </tr> <tr> <td colspan="2 " style="text-align:center "> <input type="image " src="buttononclick.png " alt="submit form " /> </td> </tr> </table> </form>
php
<?php if(isset($_post['email'])) { // edit 2 lines below required $email_to = "antonis997@gmail.com"; $email_subject = "your email subject line"; function died($error) { // error code can go here echo "we sorry, there error(s) found form submitted. "; echo "these errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "please go , fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_post['first_name']) || !isset($_post['last_name']) || !isset($_post['email']) || !isset($_post['telephone']) || !isset($_post['comments']) || !isset($_post['room'])) { died('we sorry, there appears problem form submitted.'); } $first_name = $_post['first_name']; // required $last_name = $_post['last_name']; // required $email_from = $_post['email']; // required $telephone = $_post['telephone']; // not required $comments = $_post['comments']; // required $room = $_post['room']; // not required $error_message = "errrror1"; $email_exp = '/^[a-za-z0-9._%-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'the email address entered not appear valid.<br />'; } $string_exp = "/^[a-za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'the first name entered not appear valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'the last name entered not appear valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'the comments entered not appear valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "first name: ".clean_string($first_name)."\n"; $email_message .= "last name: ".clean_string($last_name)."\n"; $email_message .= "email: ".clean_string($email_from)."\n"; $email_message .= "telephone: ".clean_string($telephone)."\n"; $email_message .= "comments: ".clean_string($comments)."\n"; $email_message .= "room: ".clean_string($room)."\n"; // create email headers $headers = 'from: '.$email_from."\r\n". 'reply-to: '.$email_from."\r\n" . 'x-mailer: php/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include own success html here --> thank contacting us. in touch soon. <?php } ?>
i problem "room" value doesn't work , have checked other 1 works perfect not last one! want
you forgot add name of field select element
<form name="contactform" method="post" action="send_form_email.php"> <table width="450px"> <tr> <td valign="top"> <label for="first_name">first name *</label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="last_name">last name *</label> </td> <td valign="top"> <input type="text" name="last_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="email ">email address *</label> </td> <td valign="top"> <input type="text " name="email " maxlength="80 " size="30 "> </td> </tr> <tr> <td valign="top"> <label for="telephone ">telephone number</label> </td> <td valign="top"> <input type="text " name="telephone " maxlength="30 " size="30 "> </td> </tr> <tr> <td valign="top"> <label for="comments ">comments *</label> </td> <td valign="top"> <textarea name="comments " maxlength="1000 " cols="25 " rows="6 "></textarea> </td> </tr> <tr> <td valign="top"> <label for="room">room</label> <td valign="top"> <select name="room"> <option value="Ηλεκτρολογοι">type room 1</option> <option value="Γεωπονοι">tyre room 2</option> </select> </td> <td valign="top"> </td> </tr> <tr> <td colspan="2" style="text-align:center "> <input type="image " src="buttononclick.png" alt="submit form " /> </td> </tr> </table> </form>
php
<?php if(isset($_post['email'])) { // edit 2 lines below required $email_to = "antonis997@gmail.com"; $email_subject = "your email subject line"; function died($error) { // error code can go here echo "we sorry, there error(s) found form submitted. "; echo "these errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "please go , fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_post['first_name']) || !isset($_post['last_name']) || !isset($_post['email']) || !isset($_post['telephone']) || !isset($_post['comments']) || !isset($_post['room'])) { died('we sorry, there appears problem form submitted.'); } $first_name = $_post['first_name']; // required $last_name = $_post['last_name']; // required $email_from = $_post['email']; // required $telephone = $_post['telephone']; // not required $comments = $_post['comments']; // required $room = $_post['room']; // not required $error_message = ""; $email_exp = '/^[a-za-z0-9._%-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'the email address entered not appear valid.<br />'; } $string_exp = "/^[a-za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'the first name entered not appear valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'the last name entered not appear valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'the comments entered not appear valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "first name: ".clean_string($first_name)."\n"; $email_message .= "last name: ".clean_string($last_name)."\n"; $email_message .= "email: ".clean_string($email_from)."\n"; $email_message .= "telephone: ".clean_string($telephone)."\n"; $email_message .= "comments: ".clean_string($comments)."\n"; $email_message .= "room: ".clean_string($room)."\n"; // create email headers $headers = 'from: '.$email_from."\r\n". 'reply-to: '.$email_from."\r\n" . 'x-mailer: php/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include own success html here --> thank contacting us. in touch soon. <?php } ?>