PHP / JS Mail()表格不发送 - Godaddy Plesk主持

时间:2015-03-09 18:21:26

标签: javascript php sendmail

我正在完成一个小型投资组合1页滚动页面。我找到了一个联系我/邮件表单的响应式模板。 (HTML / JS / PHP显示如下)。 我有Plesk与godaddy共享主机,从我可以看到的邮件形式不能正常运行。

有没有人对如何使这项工作有任何想法或建议。

www.rockfizz.com(更具体地说是http://rockfizz.com/#contact)网页和邮件表格是否位于底部。

所有三个相关文件 -

      contact_me.js
         index.html
         contact_me.php 
           are in the root HTTPDOCS folder.

代码

HTML

<!-- Contact Section -->
<section class="contact" id="contact">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h2>Contact me</h2>
            </div>
        </div>
    <div class="contact-form">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2">


                <form name="sentMessage" id="contactForm" novalidate action="contact_me.php" method="post">
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Name</label>
                            <input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Email Address</label>
                            <input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Phone Number</label>
                            <input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Message</label>
                            <textarea rows="5" class="form-control" placeholder="Ask me anything!" id="message" required data-validation-required-message="Please enter a message."></textarea>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <br>
                    <div id="success"></div>
                    <div class="row">
                        <div class="form-group col-xs-12 text-center">
                            <button type="submit" class="btn">SEND</button>
                        </div>
                    </div>
                </form>
            </div>
          </div>
        </div>
    </div>

</section>

JAVASCRIPT

$(function () {

$("input,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 email = $("input#email").val();
        var phone = $("input#phone").val();
        var message = $("textarea#message").val();
        var firstName = name; // For Success/Failure Message
        // Check for white space in name for Success/Fail message
        if (firstName.indexOf(' ') >= 0) {
            firstName = name.split(' ').slice(0, -1).join(' ');
        }
        $.ajax({
            url: "contact_me.php",
            type: "POST",
            data: {
                name: name,
                phone: phone,
                email: email,
                message: message
            },
            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>Your message has been sent. </strong>");
                $('#success > .alert-success')
                    .append('</div>');

                //clear all fields
                $('#contactForm').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>Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                $('#success > .alert-danger').append('</div>');
                //clear all fields
                $('#contactForm').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('');
                  });

和PHP

          <?php

           error_reporting(E_ALL);
             ini_set('display_errors', 1);

           // Check for empty fields
         if(empty($_POST['name'])       ||
          empty($_POST['email'])        ||
           empty($_POST['phone'])       ||
             empty($_POST['message'])   ||
          !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
                    {
          echo "No arguments Provided!";
           return false;
                 }

              $name = $_POST['name'];
              $email_address = $_POST['email'];
              $phone = $_POST['phone'];
              $message = $_POST['message'];

            // Create the email and send the message
                     $to = "hello@rockfizz.com";
                      $email_subject = "Rock Fizz:  $name";
                     $email_body = "You have received a new message from                          your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail:         $email_address\n\nPhone: $phone\n\nMessage:\n$message";
                $headers = "From: noreply@rockfizz.com\n";
               $headers .= "Reply-To: $email_address";  
                mail($to,$email_subject,$email_body,$headers);
                  return true;          
                     ?>

感谢您的所有帮助!

0 个答案:

没有答案