无法从简单的ajax php联系人接收电子邮件

时间:2015-01-31 07:54:04

标签: php contact contact-form

您好我正在尝试在php中开发一个简单的联系表单。我做了很多研究,但似乎无法解决这个问题。

以下是HTML代码:

<form id="contact-form" action="contact.php" method="post" class="clearfix">
                    <div class="contact-box-hide">
                        <div class="col-sm-6">
                            <input type="text"  class="form-control" id="first_name" name="first_name" required placeholder="First Name">
                            <span class="first-name-error"></span>
                        </div>
                        <div class="col-sm-6">
                            <input type="text"  class="form-control" id="last_name" name="last_name" required placeholder="Last Name">
                            <span class="last-name-error"></span>
                        </div>
                        <div class="col-sm-6">
                            <input type="email" class="form-control"  id="contact_email" name="contact_email" required placeholder="Email Address">
                            <span class="contact-email-error"></span>
                        </div>
                        <div class="col-sm-6">
                            <input type="text"  class="form-control" id="subject" name="contact_subject" required placeholder="Subject">
                            <span class="contact-subject-error"></span>
                        </div>
                        <div class="col-sm-10">
                            <textarea class="form-control" rows="5" id="message" name="message" required placeholder="Message"></textarea>
                            <span class="contact-message-error"></span>
                        </div>
                        <div class="col-sm-2">
                            <button id="contact-submit" class="btn custom-btn col-xs-12" type="submit" name="submit"><i class="fa fa-rocket"></i></button>
                            <span id="contact-loading" class="btn custom-btn col-xs-12"> <i class="fa fa-refresh fa-spin"></i> </span>
                        </div>
                    </div><!-- /.contact-box-hide -->
                    <div class="contact-message"></div>

                </form><!-- /#contact-form -->

这是PHP部分:

<?php
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $contact_email = $_POST['contact_email'];
    $contact_subject = $_POST['contact_subject'];
    $message = $_POST['message'];
    $subject = "New Message from Website Form";
    $submit = $_POST['submit'];

    if($submit){

        //Prepare Email
        $from = 'From: My Website'."\r\n"; 
        $to = 'odeleon@outlook.com'; 
        $subject = "Message from United Passions for Christ.org";
        $body = "".
            "From: ".$first_name."\n".
            "E-mail: ".$contact_email."\n".
            "Message: ".$message."\n";

        //Send email
        if(mail($to, $subject, $body, $from)){
            echo '<p>Your message has been sent!</p>';
        }

    }

    ?>

他联系表单显示OK,用户点击提交时没有任何php错误。但是,电子邮件从未出现在我的收件箱中。有什么想法吗?

我有什么遗漏吗?

2 个答案:

答案 0 :(得分:0)

尝试

if(isset($_POST['submit'])){
 //your code to submit
}

答案 1 :(得分:0)

检查 php.ini 文件配置,您可以在 / etc / 目录中找到它。 请参阅此http://www.tutorialspoint.com/php/php_sending_emails.htm