PHP联系表单不接收电子邮件但已确认

时间:2018-06-09 17:44:55

标签: javascript php html email

我在网站上有几种不同的表格。我从AGENCY Bootstrap主题开始,它带有一个基本的联系表单。我使用相同的方法生成了4个其他预订表格,html文件> JS文件> php文件邮寄表单详细信息。模板附带的表单工作正常,我收到电子邮件,但对于其余的表单 - 表单已被确认,我收到了#34;发送的消息",我从未收到电子邮件邮件(甚至不是垃圾邮件)。

以下是一个(预订)表格的示例:

HTML文件

    <section id="contact-tour">
    <div class="container">
        <h1>Day Tour Enquiry</h1>
        <!--<p class="item-intro text-muted">Click <a href="#book">HERE</a> for hiring conditions</p>-->
        <p>
            <i>Kindly fill this form to enquire and we will get back to you as soon as possible.
            This is not an official booking. Further details, pricing and confirmation will be sent via e-mail.
            </i>
        </p>

        <form name="enquireTour" id="bookTour">
            <div class="row" style="padding-bottom: 5px">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label for="name">Name:</label>
                        <input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Enter your name">
                        <p class="help-block text-danger"></p>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label for="surname">Surname:</label>
                        <input type="text" class="form-control" placeholder="Surname" id="surname" required data-validation-required-message="Enter your surname">
                        <p class="help-block text-danger"></p>
                    </div>
                </div>
            </div>

            <div class="row" style="padding-bottom: 5px">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label for="email">E-Mail:</label>
                        <input type="email" class="form-control" placeholder="Email" id="email" required data-validation-required-message="Enter your email address">
                        <p class="help-block text-danger"></p>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label for="phone">Phone:</label>
                        <input type="tel" class="form-control" placeholder="Phone (including area code)" id="phone" required data-validation-required-message="Enter your phone number">
                        <p class="help-block text-danger"></p>
                    </div>
                </div>
            </div>

            <div class="row" style="padding-bottom: 5px">
                <div class="col-sm-4">
                    <div class="form-group">
                        <label for="location">Tour Location:</label>
                        <select class="form-control" placeholder="Tour Location" id="location" required>
                            <option> </option>
                            <option>Gozo Day Tour</option>
                            <option>Malta Day Tour</option>
                        </select>
                        <p class="help-block text-danger"></p>
                    </div>
                </div>

                <div class="col-sm-4">
                    <div class="form-group">
                        <label for="numadults">Adults:</label>
                        <input type="number" min="0" class="form-control" placeholder="Number of Adults" id="numadults" required data-validation-required-message="Enter a number">
                        <p class="help-block text-danger"></p>
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label for="numchild">Children:</label>
                        <input type="number" min="0" class="form-control" placeholder="Number of Children (under 12 years old)" id="numchild" required data-validation-required-message="Enter a number">
                        <p class="help-block text-danger"></p>
                    </div>
                </div>
            </div>

            <div class="row" style="padding-bottom: 5px">
                <div class='col-sm-6'>
                    <div class="form-group">
                        <label for="datetime"> Date and Time: </label>
                        <div class='input-group date form_date' data-date-format="dd MM yyyy" id="datetime">
                            <input class="form-control" type="text" required />
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row" style="padding-bottom: 5px">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label for="pickup">Pick-up Location: </label>
                        <input type="text" class="form-control" placeholder="Pick-up location" id="pickup" required data-validation-required-message="Enter your pick-up location preference">
                        <p class="help-block text-danger"></p>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label for="dropoff">Drop-off Location: </label>
                        <input type="text" class="form-control" placeholder="Drop-off location" id="dropoff" required data-validation-required-message="Enter your drop-off location preference">
                        <p class="help-block text-danger"></p>
                    </div>
                </div>
            </div>

            <div class="form-group" style="padding-bottom: 10px">
                <label for="comments">Additional Comments:</label>
                <textarea class="form-control" placeholder="Additional Comments. Please provide any preferred sightseeing spots you would like to visit, if any." id="comments"></textarea>
                <p class="help-block text-danger"></p>
            </div>
            <div class="col-lg-12 text-center">
                <div id="success"></div>
                <button type="submit" class="btn btn-xl">Send</button>
            </div>
        </form>
    </div>
</section>
<script src="js/jqBootstrapValidation.js"></script>
<script src="js/tour-inquiry.js"></script>

游-inquiry.js

$(function() {    
    $("#enquireTour input,#enquireTour textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var surname = $("input#surname").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var loc = $("input#location").val();
            var total_adults = $("input#numadults").val();
            var total_child = $("input#numchild").val();
            var date = $("input#datetime").val();
            var pu_loc = $("input#pickup").val();
            var do_loc = $("input#dropoff").val();
            var comments = $("textarea#comments").val();

            $.ajax({
                url: "././mail/tour_enquiry.php",
                type: "POST",
                data: {
                    name: name,
                    surname: surname,
                    email: email,
                    phone: phone,
                    loc: loc,
                    total_adults: total_adults,
                    total_child: total_child,
                    date: date,
                    age: age,
                    pu_loc: pu_loc,
                    do_loc: do_loc,
                    addcomments: comments
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("<div class='alert alert-success'>");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("<strong>Thank you for your enquiry. We hope you to see you soon. </strong>");
                    $('#success > .alert-success')
                        .append('</div>');

                    //clear all fields
                    $('#enquireTour').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("<div class='alert alert-danger'>");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#success > .alert-danger').append($("<strong>").text("Sorry " + name + ", it seems that my mail server is not responding. Please try again later!"));
                    $('#success > .alert-danger').append('</div>');
                    //clear all fields
                    $('#enquireTour').trigger("reset");
                },
            });
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});


/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});

游-enquiry.php

<?php
// Check for empty fields
if(empty($_POST['name'])                  ||
   empty($_POST['surname'])               ||
   empty($_POST['email'])                 ||
   empty($_POST['phone'])                 ||
   empty($_POST['loc'])                   ||
   empty($_POST['total_adults'])          ||
   empty($_POST['total_child'])           ||
   empty($_POST['date'])                  ||
   empty($_POST['pu_loc'])                ||
   empty($_POST['do_loc'])                ||
   empty($_POST['comments'])              ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
   echo "No arguments Provided!";
   return false;
   }

$name = strip_tags(htmlspecialchars($_POST['name']));
$surname = strip_tags(htmlspecialchars($_POST['surname']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$loc = strip_tags(htmlspecialchars($_POST['loc']));
$total_adults = strip_tags(htmlspecialchars($_POST['total_adults']));
$total_child = strip_tags(htmlspecialchars($_POST['total_child']));
$date = strip_tags(htmlspecialchars($_POST['date']));
$pu_loc = strip_tags(htmlspecialchars($_POST['pu_loc']));
$do_loc = strip_tags(htmlspecialchars($_POST['do_loc']));
$additionalcomments = strip_tags(htmlspecialchars($_POST['comments']));

// Create the email and send the message
$to = 'correct@email-here.com';
$email_subject = "(Website) Tour Inquiry: $name $surname";
$email_body = "You have received a new Message.\n\n".
               "Here are the details:\n\n
               Name: $name\n\n
               Surname: $surname\n\n
               Email: $email_address\n\n
               Phone: $phone\n\n
               \n\n
               Date: $date\n\n
               Tour Location: $loc\n\n
               Number of Adults: $total_adults \n\n
               Number of Children: $total_child \n\n
               Pick-up Location: $pu_loc \n\n
               Drop-off Location: $do_loc \n\n
               \n\n
               Additional Comments:\n$additionalcomments";
$headers = "From: noreply@domain.com\n";
$headers .= "Reply-To: $email_address";   
mail($to,$email_subject,$email_body,$headers);
return true;         
?>

0 个答案:

没有答案