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

2022-01-23 00:00:00 html-email gmail php

我知道这个问题已经在这里解决了几次.我尝试按照设置正确标题的说明进行操作,但我的电子邮件进入 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>");
  }

相关文章