联系表格不工作JS / PHP

时间:2015-06-24 14:04:29

标签: php jquery html email

我无法在HTML网站上使用此联系表单,但我无法找出原因:/

我设法将电子邮件发送到我的邮箱,但它只显示主题(这不是有用的,因为它是纯文本,有时我会得到名称。

如果您能提供帮助,请提前致谢。

DIV:

<div id="contactForm" class="shadow">
      <div class="sepContainer"></div>
      <form action="process.php" method="post" id="contact_form">
        <div class="name">
          <label for="name">Your Name:</label>
          <p> Please enter your full name</p>
          <input id="name" name="email" type="text" placeholder="e.g. Mr. John Smith" required />
        </div>
        <div class="email">
          <label for="email">Your Email:</label>
          <p> Please enter your email address</p>
          <input id="email" name="emai" type="email" placeholder="example@domain.com" required />
        </div>
        <div class="message">
          <label for="message">Your Message:</label>
          <p> Please enter your question</p>
          <textarea name="messagetext" id="message" cols="30" rows="4"></textarea>
        </div>
        <div id="loader">
          <input type="submit" value="Submit" />
        </div>
      </form>
    </div>

JS:

// Activate the contactform
$(document).ready(function() {
            $(function(){
                $('#contact_form').submit(function(e){
                    e.preventDefault();
                    var form = $(this);
                    var post_url = form.attr('action');
                    var post_data = form.serialize();
                    $('#loader', form).html('<img src="images/loader.gif" /> Please Wait...');
                    $.ajax({
                        type: 'POST',
                        url: post_url, 
                        data: post_data,
                        success: function(msg) {
                            $(form).fadeOut(500, function(){
                                form.html(msg).fadeIn();
                            });
                        }
                    });
                });
            });
            });

PHP:

<?php
$toemail = 'myemailaddress@whatever.com';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if(mail($toemail,'CFUSU Online',$message,'From:'.$email)) {
    echo 'Your email was sent succesfully.';
} else {
    echo 'There was a problem sending your email.';
}
?>

1 个答案:

答案 0 :(得分:1)

更正php代码

$toemail = 'myemailaddress@whatever.com';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['messagetext'];
if(mail($toemail,'CFUSU Online',$message,'From:'.$email)) {
    echo 'Your email was sent succesfully.';
} else {
    echo 'There was a problem sending your email.';
}