dsi36131 2018-05-19 19:33
浏览 16
已采纳

为什么通过联系表发送的邮件都会转到垃圾邮箱? 我的代码出了什么问题?

I'm using the code below for the messages sent via the contact form of my website. The issue is that all the messages arrive in the spam box. I suspect that this is because of this part "From:" . $_POST['email']

What are your thoughts on this issue?

Thanks,

<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {

  // detect & prevent header injections
  $test = "/(content-type|bcc:|cc:|to:)/i";
  foreach ( $_POST as $key => $val ) {
    if ( preg_match( $test, $val ) ) {
      exit;
    }
  }

  //send email
 mail( "XYZ****@hotmail.com", "New message from: ".$_POST['name'], $_POST['message']."
From page: ". str_replace("http://", "", $_SERVER['HTTP_REFERER']), "From:" . $_POST['email'] . "
" . "BCC: ABC****@gmail.com" );

}
?>
  • 写回答

1条回答 默认 最新

  • duansan9435 2018-05-19 19:51
    关注

    To Make Your PHP mail() Emails Less Spammy Use Headers

    $headers .= "Reply-To: The Sender <sender@sender.com>
    ";
    $headers .= "Return-Path: The Sender <sender@sender.com>
    ";
    $headers .= "From: The Sender <senter@sender.com>
    ";
    

    But headers are good for more than just setting details about the sender. They are also important for setting the content type, the email priority, and more. Here are how some additional headers look.

    $headers .= "Organization: Sender Organization
    ";
    $headers .= "MIME-Version: 1.0
    ";
    $headers .= "Content-type: text/plain; charset=iso-8859-1
    ";
    $headers .= "X-Priority: 3
    ";
    $headers .= "X-Mailer: PHP". phpversion() ."
    "
    

    Be sure to replace the fourth parameter with the $headers variable as shown below.

    mail("recipient@recipient.com", "Message", "A simple message.", $headers);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题