Introduction
Here is the HTML Page Code
You can change the design of the HTML page since I am not providing you the CSS code of my page so you need to redesign it.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title></title>
- <link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
- <body>
- <div class="">
- <form name="contact" method="post" action="sendmail.php" id="form1" style="float: left;
- padding: 0px">
- <h2>
- Book a Room</h2>
- <fieldset>
- <div class="row">
- <input type="text" class="input" name="name">
- Your Name:
- </div>
- <div class="row">
- <input type="text" class="input" name="email">
- E-Mail Address:
- </div>
- <div class="row">
- <input type="text" class="input" name="telephone">
- Contact No.:
- </div>
- <div class="row">
- <input type="text" name="SelectedDate1" class="input" id="SelectedDate" readonly
- onclick="GetDate(this);" />
- Check In:
- </div>
- <div class="row">
- <input type="text" name="SelectedDate2" class="input" id="Text1" readonly onclick="GetDate(this);" />
- Check Out:
- </div>
- <div class="row">
- <input type="text" class="input" name="Place">
- Pick Up/Drop:
- </div>
- <div class="row_textarea">
Additional Comments
- <textarea cols="1" rows="1" name="comments"></textarea>
- </div>
- <div class="wrapper">
- <a href="#" class="button1" onclick="document.getElementById('form1').submit()">Send</a>
- <a href="#" class="button1" onclick="document.getElementById('form1').reset()">Clear</a>
- </div>
- </fieldset> </form> </div> </form>
PHP Code
- <?php
- if (isset($_POST['email']))
- {
- // EDIT THE 2 LINES BELOW AS REQUIRED
- $email_to = "[email protected]";
- $email_subject = "Booking Received";
- function died($error)
- {
- // your error code can go here
- echo "We are very sorry, but there were error(s) found with the form you submitted. ";
- echo "These errors appear below.<br /><br />";
- echo $error . "<br /><br />";
- echo "Please go back and fix these errors.<br /><br />";
- die();
- }
- // validation expected data exists
- if (!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments']))
- {
- died('We are sorry, but there appears to be a problem with the form you submitted.');
- }
- $name = $_POST['name']; // required
- $email_from = $_POST['email']; // required
- $telephone = $_POST['telephone']; // not required
- $comments = $_POST['comments']; // required
- $checkin = $_POST['SelectedDate1']; // required
- $checkout = $_POST['SelectedDate2']; // required
- $Place = $_POST['Place']; // 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 you entered does not appear to be valid.<br />';
- }
- $string_exp = "/^[A-Za-z .'-]+$/";
- if (!preg_match($string_exp, $name))
- {
- $error_message .= 'The First Name you entered does not appear to be valid.<br />';
- }
- if (strlen($comments) < 2)
- {
- $error_message .= 'The Comments you entered do not appear to be 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($name) . "\n";
- $email_message .= "Email: " . clean_string($email_from) . "\n";
- $email_message .= "Telephone: " . clean_string($telephone) . "\n";
- $email_message .= "Comments: " . clean_string($comments) . "\n";
- $body = "Mail Send";
- $msg = 'Name:-' . $_POST['name'] . "\n" . 'Email:-' . $_POST['email'] . "\n" . 'Contact No:-' . $_POST['telephone'] . "\n" . 'Check In:-' . $_POST['SelectedDate1'] . "\n" . 'Check Out:-' . $_POST['SelectedDate2'] . "\n" . 'Place:-' . $_POST['Place'] . "\n" . 'cOMMENTS:-' . $_POST['comments'];
- mail($email_to, $email_subject, $msg);
- echo '<span style="color:#FFFFFF">Your E-mail has been sent !Thank you for contacting us. We will be in touch with you very soon.</span>';
- ?>
- <!-- include your own success html here
- if($send_email)
- {
- echo "Your E-mail has been sent !Thank you for contacting us. We will be in touch with you very soon.";
- }
- else
- {
- echo "E-mail sent was failed !";
- } -->
- <?php
- }
- ?>
This is the PHP Code. You need to create a file and name it as "sendmail.php" and paste the PHP code.
Then create another page "contact.html" and paste the HTML code there. It will for the web server but if you need to run it on localhost then you need to configure your SMTP server.
Thanks. Any further suggestions by you are welcomed in the comments.

NikitaPosted Feb 12, 2020, 2:19 AM
<section id="service-single-area"> <div class="container"> <div class="row"> <div class="col-lg-9 col-md-8 col-sm-12 col-xs-12 pull-right"> <div class="service-single-content"> <div class="appoinment-form"> <div class="title"> <h2>Make an Appoinment</h2> </div> <form id="appoinmentone" name="appointment" action="sendmail.php" method="post" enctype="text/plain" > <div class="row"> <div class="col-md-6"> <input type="text" name="name" value="" placeholder="Your Name*" required="" id="name"> <input type="email" name="email" value="" placeholder="Your Mail*" required="" id="email"> <input type="text" name="phn" value="" placeholder="Phone Number*" required="" id="phone"> <input type="date" name="date" value="" placeholder="Apointment Date*" required="" id="date"> </div> <div class="col-md-6"> <select class="selectmenu" > <option selected="selected" id="prod" name="services">Select Service</option> <option id="prod">Commercial Aquaguard</option> <option id="prod">Industrial RO Plants</option> <option id="prod">Water Cooler</option> <option >Commercial Vacuum Cleaner</option> <option>Water Ionizers</option> </select> <textarea name="message" placeholder="Your Message.." required="" id="messsage"></textarea> </div> </div> <div class="row"> <div class="col-md-12"> <form method="post"> <button class="thm-btn bg-1" type="submit" onclick="document.getElementById('appoinmentone').submit();">Submit Now</button> </form> </div> </div> </form> </div> </div> </div> </div> </div> </section>
NikitaPosted Feb 12, 2020, 2:19 AM
I want to same php code for the following html file
NikitaPosted Feb 12, 2020, 12:10 AM
I set port no. to 587 in php.ini and alsoconfigure sendmail file
NikitaPosted Feb 11, 2020, 11:55 PM
Mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in E:\xampp\htdocs\nikitaemail\sendmail.php on line 65
NikitaPosted Feb 11, 2020, 11:55 PM
Its not working give me error
NikitaPosted Feb 11, 2020, 11:10 PM
How to configure smtp server