沃梦达 / 编程问答 / php问题 / 正文

PHP mail() 表单发送到 GMAIL 垃圾邮件

PHP mail() form sending to GMAIL spam(PHP mail() 表单发送到 GMAIL 垃圾邮件)

本文介绍了PHP mail() 表单发送到 GMAIL 垃圾邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经在这里解决了几次.我尝试按照设置正确标题的说明进行操作,但我的电子邮件进入 Gmail 中的垃圾邮件过滤器时仍然遇到问题.

I know this problem has been addressed a few times on here. I tried following the directions for setting proper headers, I still run into problems with my emails going into the spam filter in Gmail.

如果有人可以看看我的尝试,我将不胜感激.下面的代码没有添加标题,如下所述:http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/

If anyone can please take a look at what I've tried, I'd really appreciate it. The code below is without the headers added as explained here: http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/

提前致谢.

define("WEBMASTER_EMAIL", 'myName@mydomain.com');
if($post)
{
    $name    = stripslashes($_POST['name']);
    $email   = trim($_POST['email']);
    $subject = trim($_POST['subject']);
    $message = stripslashes($_POST['message']);

    $error = '';

    // Check name
    if(!$name)
        $error .= 'Name required! ';

    // Check email
    if(!$email)
        $error .= 'E-mail required! ';

    if($email && !ValidateEmail($email))
        $error .= 'E-mail address is not valid! ';

    // Check message
    if(!$message)
        $error .= "Please enter your message!";

    if(!$error)
    {

        $mail = mail(WEBMASTER_EMAIL, $subject, $message,
            "From: ".$name." <".$email.">
"
            ."Reply-To: ".$email."
"
            ."X-Mailer: PHP/" . phpversion());

        if($mail)
            echo 'OK';
    }
    else
        echo '<div class="errormsg">'.$error.'</div>';
}

推荐答案

使用这段代码:

 $to = Email;
 $subject = subject ;
 $body = "<div> hi hi .. </div>";

    $headers = 'From: YourLogoName info@domain.com' . "
" ;
    $headers .='Reply-To: '. $to . "
" ;
    $headers .='X-Mailer: PHP/' . phpversion();
    $headers .= "MIME-Version: 1.0
";
    $headers .= "Content-type: text/html; charset=iso-8859-1
";   
if(mail($to, $subject, $body,$headers)) {
  echo('<br>'."Email Sent ;D ".'</br>');
  } 
  else 
  {
  echo("<p>Email Message delivery failed...</p>");
  }

这篇关于PHP mail() 表单发送到 GMAIL 垃圾邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP mail() 表单发送到 GMAIL 垃圾邮件

基础教程推荐