PHP邮件表单正在发送到Gmail垃圾邮件

时间:2015-09-18 12:41:49

标签: php email gmail spam

有人可以帮我弄清楚为什么以下PHP导致电子邮件被发送到Gmail垃圾邮件?我尝试按照其他说明设置正确的标题,但我仍然遇到问题,我的电子邮件会进入Gmail中的垃圾邮件过滤器。

任何帮助将不胜感激!

<?php 
//set validation error flag as false
$error = false;
//check if form is submitted
if (isset($_POST['submit']))
{
    $name = trim($_POST['txt_name']);
    $fromemail = trim($_POST['txt_email']);
    $inquiry = trim($_POST['txt_inquiry']);
    $message = trim($_POST['txt_msg']);

    //name can contain only alpha characters and space
    if (!preg_match("/^[a-zA-Z ]+$/",$name))
    {
        $error = true;
        $name_error = "Please enter a real name";
    }
    if(!filter_var($fromemail,FILTER_VALIDATE_EMAIL))
    {
        $error = true;
        $fromemail_error = "Please enter a valid email address";
    }
    if(empty($inquiry))
    {
        $error = true;
        $inquiry_error = "Please enter your subject";
    }
    if(empty($message))
    {
        $error = true;
        $message_error = "Please enter your message";
    }
    if (!$error)
    {
        //send mail
        $toemail = "myemail@gmail.com";
        $subject = "inquiry from visitor " . $name;
        $body = "Here goes your Message Details: \n\n Name: $name \n From: $fromemail \n Inquiry: $inquiry \n Message: \n $message";
        $headers = "From: $fromemail\n";
        $headers .= "Reply-To: $fromemail";
        $headers .= "Return-Path: $fromemail";

        if (mail ($toemail, $inquiry, $body, $headers))
            $alertmsg  = '<div class="alert alert-success text-center">Message sent successfully.  We will get back to you shortly!</div>';
        else
            $alertmsg = '<div class="alert alert-danger text-center">There is error in sending mail.  Please try again later.</div>';
    }
}

&GT;

2 个答案:

答案 0 :(得分:1)

您发送电子邮件的服务器的IP地址可能是用于将其标记为垃圾邮件地址的其他目的。

大多数情况下,将DKIM和SPF添加到电子邮件服务器(如果使用的话)将解决此问题。

一个更好的解决方案是使用外部邮件服务,以便他们可以为您处理

答案 1 :(得分:-1)

我经常提供经验,直接通过PHP发送的邮件被识别为SPAM ......

我现在的方法是,始终使用SMTP-Server发送这些电子邮件......

this帖子可以帮到你!