发送邮件时联系表单错误

时间:2016-05-20 11:47:15

标签: php email contact-form

我的联系表单没有发送消息。

验证中没有报告错误,因此我收到"消息已发送",但实际上并未发送消息。因此,配置我的邮件设置时可能存在错误

这是我的代码:

HTML:

<div class="container">
    <div class="row">
        <div class="col-lg-12 text-center">
            <h2 class="section-heading middle_heading">Contact Us</h2>
            <div class="colored-line2"></div>
            <p class="populer_des"></p>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <form class="bg_field" name="sentMessage" action="./mail/validateform.php" method="post" id="contactForm" novalidate>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
                            <p class="help-block text-danger"></p>
                        </div>
                        <div class="form-group">
                            <input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
                            <p class="help-block text-danger"></p>
                        </div>
                        <div class="form-group">
                            <input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-lg-12 text-center">
                        <div id="success"></div>
                        <button type="submit" class="btn btn-xl submit_message">Send Message</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

PHP:

if(empty($_POST['name'])        ||
    empty($_POST['email'])      ||
    empty($_POST['phone'])      ||
    empty($_POST['message'])    ||
    !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
    {
        echo "No arguments Provided!";
        return false;
    }
    $name = $_POST['name'];
    $email_address = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];

    $to = 'mail.ornithas.gr'; 
    $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\nPhone: $phone\n\nMessage:\n$message";
    $headers = "From:mail.ornithas.gr\n"; 
    $headers .= "Reply-To: $email_address"; 
    mail($to,$email_subject,$email_body,$headers);
    return true; 

3 个答案:

答案 0 :(得分:0)

标题应由&#39; \ r \ n&#39;分隔。不是&#39; \ n&#39;所以标题变量应该是

  

$ headers =&#34;来自:masudcsep@gmail.com \ r \ n&#34;;
  $ headers。=&#34;回复:   $ EMAIL_ADDRESS&#34 ;;

答案 1 :(得分:0)

检查您的$到电子邮件地址......看起来不正确。邮件发送失败。

答案 2 :(得分:-1)

  1. 检查您输入的网址是否正确:

    <form class="bg_field" name="sentMessage" action="./mail/validateform.php" method="post" id="contactForm" novalidate>
    

    这个: ./ mail / validateform.php 表示您当前目录中有一个文件夹 mail ,该文件夹还有一个名为 validateform.php的文件

  2. 检查文件名

  3. 检查文件中的代码。