即使成功发送邮件功能,也无法接收电子邮件

时间:2017-07-23 14:33:05

标签: javascript php jquery ajax html5

我已经设置了一个表单,可以在点击发送时发送电子邮件。为了测试它,我对脚本中的值进行了硬编码。我甚至得到了成功的信息"是的"当我点击发送但无法接收电子邮件时。检查电子邮件地址是否正确并检查垃圾邮件文件夹。如果我错过了什么,请建议。谢谢。

HTML

<form action="mail/contact_me.php" method="post" role="form" id="formid" class="footer-custom-form footer-custom-hr">
    <div class="row">
        <div class="col-md-12">
            <div class="form-group">
                <input type="text" class="form-control" name="name" placeholder="Your Name..." required>
            </div>
        </div>
    </div>
   <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <input type="text" class="form-control" name="phone" placeholder="Phone">
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <input type="email" class="form-control" name="email" placeholder="Your Email Address" required>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="form-group">
                <textarea class="form-control" name="message" rows="8" placeholder="Your Message" required></textarea>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="">
            <input class="footer-form-btn" type="submit" value="Send message">
        </div>
    </div>
</form>

JS

$(function () {
    $('form#formid').on('submit', function (e) {

      e.preventDefault();

      $.ajax({
        type: 'post',
        url: '../mail/contact_me.php',
        data: $('form#formid').serialize(),
        success: function () {
            alert("yes"); //<-- I get this alert after submit
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert("no");
        }
      });
    });
});

PHP

<?php
//hardcoded for testing
$name = 'testname';
$email_address = 'testemail@gmail.com';
$subject = 'testsubject';
$message = 'testmessage';

// Create the email and send the message
$to = 'myemail@gmail.com'; // I have my actual email here
$email_subject = "Website Contact Form:  $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\nSubject: $subject\n\nMessage:\n$message";
$headers = "From: noreply@test.com\n"; 
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>

0 个答案:

没有答案