0

Unable to get ths form working.

Is there any easy to create html form that will simply send email upon submission?

Can anyone provide some code samples?

I tried to get it workin but it always stay there no response on email. In form i tried to get date, time, locations that can be typed, number passanger and cars, car type, name email and message.

                <form class="booking-form"> 


                        <div class="row">
                        <!--    <div class="col-xs-6 col-sm-2">
                                <fieldset class="car-type">
                                    <input type="checkbox" name="car-type" id="econo" />
                                    <label for="econo"><i class="icon-car-econo"></i>Econo</label>
                                </fieldset>
                            </div> --> 
                            <div class="col-xs-6 col-sm-2">
                                <fieldset class="car-type">
                                    <input type="checkbox" name="car-tclass="icon-car-LUXURY SEDANype" id="LUXURY SEDAN" />
                                    <label for="LUXURY SEDAN"><i class="icon-car-classic"> </i>LUXURY SEDAN</label>
                                </fieldset>
                            </div>
                            <div class="col-xs-6 col-sm-2">
                                <fieldset class="car-type">
                                    <input type="checkbox" name="car-type" id="EUROPEAN SEDAN" />
                                    <label for="EUROPEAN SEDAN"><i class="icon-car-wagon"></i>EUROPEAN SEDAN</label>
                                </fieldset>
                            </div>


                        </div>
                        <div class="row">
                            <div class="col-sm-3">
                                <fieldset>
                                    <input type="text" name="name" placeholder="Name" />
                                </fieldset>
                                <fieldset>
                                    <input type="email" name="email" placeholder="Email" />
                                </fieldset>
                            </div>
                            <div class="col-sm-3">
                                <fieldset>
                                    <input type="text" name="from1" placeholder="From" />
                                </fieldset>
                                <fieldset>
                                    <input type="text" name="to1" placeholder="To" />
                                </fieldset>
                            </div>
                            <div class="col-sm-3">
                                <fieldset>
                                    <input type="text" name="date" placeholder="Date1" class="datepicker" />
                                </fieldset>
                                <fieldset>
                                    <input type="text" name="time" placeholder="Time" class="timepicker" />
                                </fieldset>
                            </div>
                            <div class="col-sm-3">
                                <fieldset>
                                    <select name="cars">
                                        <option>Cars</option>
                                        <option>1</option>
                                        <option>2</option>
                                        <option>3</option>
                                        <option>4</option>
                                    </select>
                                </fieldset>
                                <fieldset>
                                    <select name="passengers">
                                        <option>Passengers</option>
                                        <option>1</option>
                                        <option>2</option>
                                        <option>3</option>
                                        <option>4</option>

                                    </select>
                                </fieldset>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <fieldset>
                                    <textarea name="message2" placeholder="Message"></textarea>
                                </fieldset>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12 text-center">
                                <button class="btn btn-primary">Book Now</button>
                            </div>
                        </div>
                    </form>
  • What server-side language are you using with this (PHP, C#, etc)? You need to set the action when the form is submitted
    and instead of just a button you need to have a submit button . Need more details to help further.
    – Bivo Kasaju Apr 28 '18 at 23:21
  • its only html no server language is used. – James Thomas Apr 28 '18 at 23:37
  • I'm sorry for the bad news my friend, but i don't see an email being sent just using Html. You'll need some kind of server-side back-end language to actually process the data from the form and the send the email. Html is only front-end. – Bivo Kasaju Apr 28 '18 at 23:39
  • Try this: https://stackoverflow.com/questions/7381150/how-to-send-an-email-from-javascript It's not exactly what you're looking for but the closest to sending an email. – Bivo Kasaju Apr 28 '18 at 23:40
  • so basically I need to learn more programming languages, I am right? – James Thomas Apr 29 '18 at 00:09
  • In short, yes! Good luck.. – Bivo Kasaju Apr 29 '18 at 00:11
  • can you help me to write php file to get it working I am not able to get it working.. – James Thomas May 03 '18 at 03:12

1 Answers1

0

you need a backend language

<!-- action->specify the destiny of data from form | method->indicate shipping method  -->
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
    <input type="text" name="someText" placeholder="someText">
    <input type="submit" name="sendText" value="sendText">
</form>

and with php you can send the data form form

<?php 

    $errorMessage = ''; // case the user not complete all fields of the form
    $to = 'myemail@company.com'; // destiny of message

    if( isset($_POST['sendText']) ){ // comprobate the action of the input type submit 
        $someText = $_POST['someText']; // get the value of input type text
        if( !empty($someText) ){ // comprobate if the variable is not empty
            $someText = stripslashes(trim(filter_var($someText , FILTER_SANITIZE_STRING))); // this sanitize the text for avoid the code injection
            mail($to,$someText); // this method only can send message when the web is working on server
        }else{ // show an error message if text is empty
            $errorMessage.="Please complete all fields <br>";
        }
    }

?>
  • thank you i am trying to figure this code out as php is very new to me. – James Thomas Apr 29 '18 at 00:12
  • $message = $cars . " " . $_POST['message']; $message = $passengers . " " . $_POST['message']; $message = $time . " " . $_POST['message']; $message = $date1 . " " . $_POST['message']; $message2 = "Here is a copy of your message " . $_POST['message']; $headers = "From:" . $from; $headers2 = "From:" . $to; mail($to,$subject,$message,$headers); mail($from,$subject2,$message2,$headers2); echo "Mail Sent. Thank you " . $name . ", we will contact you shortly."; } ?> – James Thomas May 01 '18 at 02:55
  • I like more the code with more separation between each word :), but in programming there are many ways to do something, this is the basic way to validate a
    with php, exist other forms to make validation of forms more advanced, with the practice you will be better, if you code its works is good :)
    – Alberto Monraz May 01 '18 at 03:05
  • this one redirects me to php file when i fill and submit form. – James Thomas May 01 '18 at 03:38
  • it's not actually staying on form after submitting nor to the specific page but redirecting to PHP file link that is handling email – James Thomas May 01 '18 at 03:55
  • in the document of your form validation with php use to redirect to index for example header('Location: index.html ') to final of all code validation of form – Alberto Monraz May 03 '18 at 19:33