通过PHP联系表单发送时,避免将电子邮件视为垃圾邮件 [英] Avoid emails being considered as spam when sent via a PHP contact form

查看:155
本文介绍了通过PHP联系表单发送时,避免将电子邮件视为垃圾邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码通过联系表单发送电子邮件。
问题是电子邮件每次都会发送到垃圾邮件箱(在Outlook,Gmail等)。我怀疑这是因为在电子邮件正文中有一个网址(网页URL)。
因此,我想知道是否有一些解决方法(除了将这些电子邮件标记为gmail和Outlook中的非垃圾邮件)以保留URL(我想保留),但是电子邮件不被视为垃圾邮件。也许通过重新构造URL,使其看起来不像URL?当然,大公司有技巧&这样的技巧?
非常感谢

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" );

}
?>


推荐答案

发送头文件,如下所示:

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);

这篇关于通过PHP联系表单发送时,避免将电子邮件视为垃圾邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆