Avoid emails being considered as spam when sent vi

2019-04-16 08:46发布

I’m using the code below to send emails via a contact form. Issue is that the emails go to the spam box every time (in outlook, gmail, etc). I suspect that this due to the fact that there’s a url (the web page URL) in the body of the e-mail. Therefore I was wondering if there’s some workaround (apart for tagging these emails as non-spam in gmail and outlook) in order to keep the URL (I want to keep it) but have the emails not considered as spam. Maybe by re-constructing the URL so that it does not look like a URL? Surely big companies have tips & tricks for that? Many 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( "dsfds@sfss.com", "Nouveau message de: ".$_POST['name'], $_POST['message'] ."\n From site: ". $_SERVER['HTTP_REFERER']., "From:" . $_POST['email'] . "\r\n" . "BCC: dsfds@gmail.com" );

}
?>

1条回答
我想做一个坏孩纸
2楼-- · 2019-04-16 09:35

Send headers with it, like this:

$to      = 'example@example.com';
$header = "From: noreply@example.com\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=utf-8\r\n"; 
$header.= "X-Priority: 1\r\n"; 

mail($to, $subject, $message, $header);
查看更多
登录 后发表回答