contact.php给出了成功消息,但没有发送电子邮件?

时间:2015-05-18 17:35:06

标签: php html email

我已经查了一下这个并找到了一些解决方案,但是没有一个能在我的情况下真正起作用并且有一个像TON一样,但到目前为止大多数都不是我正在努力的方向,它们是通常情况要复杂得多,因为我缺乏php而无法遵循。

我正在设置一个联系页面,一切似乎都很好,但实际上并没有因为某种原因发送电子邮件。

    <div class="contact-form">
            <form action="contact.php" class="form-horizontal" method=
            "post">
                    <div class="form-group">
                            <label class="col-sm-2 control-label" for=
                            "name">Name</label>

                            <div class="col-sm-10">
                                    <input class="form-control" id="name"
                                    name="name" placeholder=
                                    "First & Last Name" type="text" value=
                                    "<?php echo htmlspecialchars($_POST['name']); ?>">
                                    <?php echo "<p class='text-danger'>$errName</p>";?>
                            </div>
                    </div>

                    <div class="form-group">
                            <label class="col-sm-2 control-label" for=
                            "email">Email</label>

                            <div class="col-sm-10">
                                    <input class="form-control" id="email"
                                    name="email" placeholder=
                                    "example@domain.com" type="email"
                                    value="<?php echo htmlspecialchars($_POST['email']); ?>">
                                    <?php echo "<p class='text-danger'>$errEmail</p>";?>
                            </div>
                    </div>

                    <div class="form-group">
                            <label class="col-sm-2 control-label" for=
                            "message">Message</label>

                            <div class="col-sm-10">
                                    <textarea class="form-control" name=
                                    "message" rows="4">
                                    <?php echo htmlspecialchars($_POST['message']);?>
                            </textarea> <?php echo "<p class='text-danger'>$errMessage</p>";?>
                            </div>
                    </div>

                    <div class="form-group">
                            <label class="col-sm-2 control-label" for=
                            "human">2 + 3 = ?</label>

                            <div class="col-sm-10">
                                    <input class="form-control" id="human"
                                    name="human" placeholder="Your Answer"
                                    type="text">
                                    <?php echo "<p class='text-danger'>$errHuman</p>";?>
                            </div>
                    </div>

                    <div class="form-group">
                            <div class="col-sm-10 col-sm-offset-2">
                                    <input class="btn btn-primary" id=
                                    "submit" name="submit" type="submit"
                                    value="Send">
                            </div>
                    </div>

                    <div class="form-group">
                            <div class="col-sm-10 col-sm-offset-2">
                                    <?php echo $result; ?>
                            </div>
                    </div>
            </form>
    </div>

这是在top

的contact.php页面中
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

    if ($_POST["submit"]) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $human = intval($_POST['human']);
        $from = 'Demo Contact Form'; 
        $to = 'Isetmyemailherealready@editedforprivacy.com'; 
        $subject = 'Message from Contact Demo ';

        $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>';
    }
}
    }
?>

我对PHP没有任何经验,所以我从哪里开始无能为力,我为此查找了一个php指南,并且到目前为止,但现在我被卡住了,因为它说它发送了电子邮件(给我“谢谢你?我将保持联系”的消息),但我从未收到任何电子邮件。

0 个答案:

没有答案