PHP mail() 表单发送到 GMAIL 垃圾邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12188334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:00:59  来源:igfitidea点击:

PHP mail() form sending to GMAIL spam

phpgmailhtml-email

提问by user1040259

I know this problem has been addressed a few times on here. I tried following the directions for setting proper headers, I still run into problems with my emails going into the spam filter in Gmail.

我知道这个问题已经在这里解决了几次。我尝试按照设置正确标题的说明进行操作,但我的电子邮件进入 Gmail 中的垃圾邮件过滤器时仍然遇到问题。

If anyone can please take a look at what I've tried, I'd really appreciate it. The code below is without the headers added as explained here: http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/

如果有人可以请看一下我尝试过的内容,我将不胜感激。下面的代码没有按照此处的说明添加标题:http: //www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/

Thanks in advance.

提前致谢。

define("WEBMASTER_EMAIL", '[email protected]');
if($post)
{
    $name    = stripslashes($_POST['name']);
    $email   = trim($_POST['email']);
    $subject = trim($_POST['subject']);
    $message = stripslashes($_POST['message']);

    $error = '';

    // Check name
    if(!$name)
        $error .= 'Name required! ';

    // Check email
    if(!$email)
        $error .= 'E-mail required! ';

    if($email && !ValidateEmail($email))
        $error .= 'E-mail address is not valid! ';

    // Check message
    if(!$message)
        $error .= "Please enter your message!";

    if(!$error)
    {

        $mail = mail(WEBMASTER_EMAIL, $subject, $message,
            "From: ".$name." <".$email.">\r\n"
            ."Reply-To: ".$email."\r\n"
            ."X-Mailer: PHP/" . phpversion());

        if($mail)
            echo 'OK';
    }
    else
        echo '<div class="errormsg">'.$error.'</div>';
}

回答by Erfan Safarpoor

Use this code:

使用 此代码

 $to = Email;
 $subject = subject ;
 $body = "<div> hi hi .. </div>";

    $headers = 'From: YourLogoName [email protected]' . "\r\n" ;
    $headers .='Reply-To: '. $to . "\r\n" ;
    $headers .='X-Mailer: PHP/' . phpversion();
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";   
if(mail($to, $subject, $body,$headers)) {
  echo('<br>'."Email Sent ;D ".'</br>');
  } 
  else 
  {
  echo("<p>Email Message delivery failed...</p>");
  }

回答by iHaveacomputer

I think this is your issue:

我认为这是你的问题:

 "From: ".$name." <".$email.">\r\n"

since you are not gmail, hotmail or your users email provider, you cannot have "From: otherdomain.com" and then deliver the mail via "mail.yourdomain.com" - this will most likely move your mail to the spam folder.

由于您不是 gmail、hotmail 或您的用户电子邮件提供商,因此您不能拥有“发件人:otherdomain.com”,然后通过“mail.yourdomain.com”发送邮件 - 这很可能会将您的邮件移至垃圾邮件文件夹。

Try

尝试

 "From: YourWebsiteName <[email protected]>\r\n"
."Reply-To: ".$name." <".$email.">\r\n"

instead.

反而。

ALso: your code is very unsave and a prime spam target - google "email header injection php"!

另外:您的代码非常未保存并且是主要的垃圾邮件目标 - 谷歌“电子邮件标头注入 php”!

回答by DevWL

Google tends to discipline not only the websites but also service providers who used to have many users spamming across the network. If you are signed up to one of these service providers that google recognizes as spammers this might be the reason why your php mail() messages drops in to spam box in gmail. Try to chat about this issue with your server provider.

谷歌不仅对网站进行处罚,而且对曾经有许多用户通过网络发送垃圾邮件的服务提供商进行处罚。如果您注册了 Google 识别为垃圾邮件发送者的这些服务提供商之一,这可能就是您的 php mail() 消息落入 Gmail 中的垃圾邮件箱的原因。尝试与您的服务器提供商讨论此问题。

In that case you will get a warning from google in your "spam" message:

在这种情况下,您将在“垃圾邮件”消息中收到来自谷歌的警告:

"Why is this message in Spam? We've found that lots of messages from home.pl are spam. Learn more"

“为什么此邮件会出现在垃圾邮件中?我们发现来自 home.pl 的许多邮件都是垃圾邮件。了解更多信息”