当我在gmail中使用php发送电子邮件时,它进入了gmail中的垃圾邮件文件夹?我怎么能防止这种情况


When i send the email using php in gmail it went to the Spam folder in gmail? How can i prevent that?

请参阅以下 code.in 有发送用户名,password.email 已发送到Gmail。但它属于垃圾邮件 folder.it 只发生在Gmail中。

这是我的代码

$to = $email;
$subject = ' Web Site| login Details'; // Give the email a subject
$message = '
        Thanks for signing up!
        Your account has been created, you can login with the following credentials.
        ------------------------
        Username: '.$uname.'
        Password: '.$upass.'
        Web Builder login: '.$ulink.'
        ------------------------ ';
$headers .= 'From:noreply@ggg.eee.net' . "'r'n";
$headers .= 'Bcc: kae@ggg.eee.net' ."'r'n";
$headers .= 'Bcc: thi@ggg.eee.net' ."'r'n";
mail($to, $subject, $message, $headers);

电子邮件提供商将您的邮件标记为垃圾邮件的原因有很多。有时它与您的服务器和 DNS 的配置方式有关,或者有时它可能是您的消息内容。我建议使用此工具来帮助查明电子邮件的弱点,以帮助您通过大多数垃圾邮件过滤器

Mail-Tester.com

使用此代码可以正常工作

$to = Email;
  $subject = ' Web Site| login Details'; // Give the email a subject
    $message = '
        Thanks for signing up!
        Your account has been created, you can login with the following credentials.
        ------------------------
        Username: '.$uname.'
        Password: '.$upass.'
        Web Builder login: '.$ulink.'
        ------------------------ ';
    $headers = 'From: noreply@ggg.eee.net' . "'r'n" ;
    $headers .='Reply-To: '. $to . "'r'n" ;
    $headers .= 'Bcc: kae@ggg.eee.net' ."'r'n";
    $headers .= 'Bcc: thi@ggg.eee.net' ."'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,  $message ,$headers)) {
  echo('<br>'."Email Sent ;D ".'</br>');
  } 
  else 
  {
  echo("<p>Email Message delivery failed...</p>");
  }

我发现了这个问题的出路:
解决方案 1: 对标题使用双引号。

解决方案 2:问题很简单,PHP-Mail功能没有使用配置良好的SMTP服务器。

如今,电子邮件

客户端和服务器对电子邮件发送服务器执行大量检查,例如反向DNS查找,灰名单等。所有这些测试都将因 php mail() 函数而失败。如果您使用的是动态IP,那就更糟了。

使用

PHPMailer-Class 并将其配置为使用 smtp-auth 以及配置良好的专用 SMTP 服务器(本地服务器或远程服务器),您的问题就消失了。

https://github.com/PHPMailer/PHPMailer

解决方案的来源