不接收来自PHP表单的电子邮件

时间:2015-12-09 03:47:32

标签: php html forms email

我没有收到来自我的php表单/ html的电子邮件。我是制作这些表格的新手,我想知道我哪里出错了。表单在实际站点上设置正常,提交按钮将我带回主页,这就是我想要的。有人能帮我弄清楚为什么我没有收到这些电子邮件吗?

这是html:

`

<section class="contact-container">
            <div class="container mtb">
                <div class="row">
                    <div class="col-md-8 wow fadeInLeft">
                        <h4>Get in touch</h4>
                        <hr>
                            <p>Leave a comment, review, or general musings.</p><br />



<form id="contact_form" action="websitehere"  method="post">
    <label>Name: <input class="textfield" name="name" type="text" value="" /></label> 
    <label>Email: <input class="textfield" name="email" type="text" value="" /></label> 
    <label>Message: <textarea class="textarea" cols="45" name="message" rows="5"></textarea></label> 
    <input class="button" name="submit" type="submit" value="Submit" />
</form>

</div>

这是PHP:

<?php
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $human = intval($_POST['human']);

        $to = 'emailaddress@email.com'; 
        $subject = 'Message for the author ';

        $body = "From: $name\n E-Mail: $email\n Message:\n $message";

        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Please enter your name';
        }

        // Check if email has been entered and is valid
        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Please enter a valid email address';
        }

        //Check if message has been entered
        if (!$_POST['message']) {
            $errMessage = 'Please enter your message';
        }
        //Check if simple anti-bot test is correct
        if ($human !== 5) {
            $errHuman = 'Your anti-spam is incorrect';
        }

// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
    if (mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
    } else {
        $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
    }
}
    }
?>

1 个答案:

答案 0 :(得分:0)

您忘记了html代码中的human。另外,请确保您没有将此电子邮件发送到Yahoo电子邮件,因为自12月4日以来他们的php邮件存在问题。如果这不能解决您的问题,这可能会对您有所帮助:http://email.about.com/od/emailprogrammingtips/qt/How_to_Send_Email_from_a_PHP_Script.htm