PHP / CSS邮件发送到index.html#

时间:2013-02-07 17:08:36

标签: php javascript html ajax

我一直试图让这个工作一段时间,我尝试了很多尝试来解决问题,但我可能只是让事情变得更糟。我遇到的问题是,当我提交我的联系表单时,它不会发送消息,它只是将我重定向到“index.html#”

我已在下面发布了我网站的代码。如果你们能看到我遗失的任何东西,请告诉我什么。

HEAD HTML

<script src="js/jquery.validationEngine-en.js" type="text/javascript"></script>
    <script src="js/jquery.validationEngine.js" type="text/javascript"></script>

    <script>
    $(document).ready(function() {
    // SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() }, 
        $("#form1").validationEngine({
            ajaxSubmit: true,
                ajaxSubmitFile: "ajaxSubmit.php",
                ajaxSubmitMessage: "Thank you, We will contact you soon !",
            success :  false,
            failure : function() {}
        })
    });
    </script>

BODY HTML(index.html)

    <div id="contact">
            <h3>need more info?</h3>
            <form action="#" method="post">
                <fieldset>
                    <p>
                      <label for="name">Name:</label>
                  </p>
                    <p>
                      <input type="text" id="name" placeholder="Enter your full name" />

                      <label for="email">Email:</label>
                  </p>
                    <p>
                      <input type="email" id="email" placeholder="Enter your email address" />

                      <label for="message">Message:</label>
                  </p>
                    <p>
                      <textarea id="message" placeholder="Looking for a quote?"></textarea>

                      <input type="submit" value="Send message" />
                  </p>

                </fieldset>
        </form>
        <?php 
            $ToEmail = 'jordantrout0@gmail.com'; 
            $EmailSubject = 'Site contact form'; 
            $mailheader = "From: ".$_POST["email"]."\r\n"; 
            $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
            $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
            $MESSAGE_BODY = "Name: ".$_POST["name"].""; 
            $MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
            $MESSAGE_BODY .= "Message: ".nl2br($_POST["message"]).""; 
            mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
        ?>
    </div>

CSS(contact.css)

    body, div, h3, form, fieldset, input, textarea {
    margin: 0; padding: 0; border: 0; outline: none;
}

html {
    height: 100%;
}

#contact {
    float:right;
    width: 250px; margin: 60px auto; padding: 60px 30px;
    background: #9fad23; border: 1px solid #e1e1e1;
    -moz-box-shadow: 0px 0px 8px #444;
    -webkit-box-shadow: 0px 0px 8px #444;
    -webkit-border-top-left-radius: 25px;
    -webkit-border-bottom-left-radius: 25px;
    -moz-border-radius-topleft: 25px;
    -moz-border-radius-bottomleft: 25px;
    border-top-left-radius: 25px;
    border-bottom-left-radius: 25px;
}

h3 {
    font-size: 25px; color: #445668; text-transform: uppercase;
    text-align: center; margin: 0 0 25px 0;
}

label {
    float: left; clear: left; margin: 11px 20px 0 0; width: 95px;
 font-size: 12px; color: #445668; 
    text-transform: uppercase; 
}

input {
    width: 200px;
    height: 35px;
    background: #5E768D;
    background: -moz-linear-gradient(top, #546A7F 0%, #5E768D 20%); /* firefox */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#546A7F), color-stop(20%,#5E768D)); /* webkit */
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-box-shadow: 0px 1px 0px #f2f2f2;
    -webkit-box-shadow: 0px 1px 0px #f2f2f2;
    font-family: sans-serif;
    font-size: 12px;
    color: #f2f2f2;
    text-transform: uppercase;
    margin-top: 0;
    margin-right: 0;
    margin-bottom: 20px;
    margin-left: 0;
    padding-top: 5px;
    padding-right: 20px;
    padding-bottom: 0px;
    padding-left: 20px;
}
    input::-webkit-input-placeholder  {
        color: #a1b2c3; 
    }
    input:-moz-placeholder {
        color: #a1b2c3; 
    }

textarea {
    width: 200px; height: 170px; padding: 12px 20px 0px 20px; margin: 0 0 20px 0; 
    background: #5E768D;
    background: -moz-linear-gradient(top, #546A7F 0%, #5E768D 20%); /* firefox */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#546A7F), color-stop(20%,#5E768D)); /* webkit */
    border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
    -moz-box-shadow: 0px 1px 0px #f2f2f2;-webkit-box-shadow: 0px 1px 0px #f2f2f2;
    font-family: sans-serif; font-size: 12px; color: #f2f2f2; text-transform: uppercase; 
}
    textarea::-webkit-input-placeholder  {
        color: #a1b2c3;  
    }
    textarea:-moz-placeholder {
        color: #a1b2c3;
    }

input:focus, textarea:focus {
    background: #728eaa;
    background: -moz-linear-gradient(top, #668099 0%, #728eaa 20%); /* firefox */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#668099), color-stop(20%,#728eaa)); /* webkit */
}

input[type=submit] {
    width: 150px; height: 40px; float:right; padding: 10px 15px; margin: 0 15px 0 0;
    -moz-box-shadow: 0px 0px 5px #999;-webkit-box-shadow: 0px 0px 5px #999;
    border: 1px solid #556f8c;
    background: -moz-linear-gradient(top, #718DA9 0%, #415D79 100%); /* firefox */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#718DA9), color-stop(100%,#415D79)); /* webkit */
    cursor: pointer;
}

AjaxSubmit.php

    <?php

$name = $_POST['name']; // contain name of person
$email = $_POST['email']; // Email address of sender 
$web = $_POST['web']; // Your website URL
$body = $_POST['text']; // Your message 
$receiver = "jordantrout0@gmail.com" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to 
if (!empty($name) & !empty($email) && !empty($body)) {
    $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}";
    $send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
    if ($send) {
        echo 'true'; //if everything is ok,always return true , else ajax submission won't work
    }

}

?>

1 个答案:

答案 0 :(得分:0)

当然它会提交到index.html#,你告诉它:

<form action="#" method="post">

请改为尝试:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">