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 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应