通过PHP发送的HTML电子邮件在Gmail中被视为垃圾邮件 [英] HTML Email sent via PHP treated as spam in Gmail

查看:118
本文介绍了通过PHP发送的HTML电子邮件在Gmail中被视为垃圾邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下php脚本,该脚本从服务器上的.txt文件加载html模板,并在发送电子邮件之前使用str_replace用Email内容填充模板.

起初,我尝试将服务器上的Webmail地址硬编码到mailer_send函数的'to'字段中,该方法可以正常工作.电子邮件模板显示完美.但是,当我尝试将其发送到Gmail帐户时,它被标记为垃圾邮件,而HTML只是显示为纯文本.是否有人知道我是否需要在电子邮件中添加其他标头以确保Gmail能够正确处理它?<​​/p>

理想情况下,我想通过服务器上的Webmail向自己发送一封电子邮件,然后向用户发送自动回复,感谢他们的询问,但是如果该邮件始终被视为垃圾邮件,将无法实现.

<?php
    function mailer_send($mailer_recipient, $mailer_subject, $mailer_message){
         $mailer_headers = 'From: webmaster@example' . '\r\n' .
        'X-Mailer: PHP/' . phpversion() . '\r\n' .
        'MIME-Version: 1.0\r\n' . '\r\n' . 
        'Content-Type: text/html; charset=ISO-8859-1\r\n';
         mail($mailer_recipient, $mailer_subject, $mailer_message, $mailer_headers);
     }

$name = $_POST['inputName'];
$email = $_POST['inputEmail'];
$message = strip_tags($_POST['inputMessage']);
$template = file_get_contents('email_templates/template.txt');
$template2 = $template;
$template = str_replace('[email_content]',$message, $template);

    mailer_send('test@gmail.com','Test Email',$template);

$message2 = '<h2>Thanks..</h2><br/><p>Dear' . $name . '</p><br/><p>Thanks for your enquiry. Jason will get back to you with a quote as soon as possible.</p>';
$template2 = str_replace('[email_content]', $message2, $template2);
mailer_send($email,'Thankyou for your Enquiry',$template2);
  ?>

谢谢.

其他:

在Gmail中收到电子邮件时,它似乎忽略了发件人"标题,而只是说该电子邮件来自我的网络托管提供商服务器.

解决方案

Gmail会怀疑该电子邮件为垃圾邮件有100万个原因.

我要做的第一件事是使用正确处理标头的库-> http://swiftmailer.org/

第二,确保您的发件人主机来自与服务器相同的IP,并具有正确的MX记录.

I have the following php script which loads a html template from a .txt file on my server and uses str_replace to populate the template with the Email content before sending the email.

At first I tried hardcoding my Webmail address on my server into the 'to' field of my mailer_send function which worked fine. The Email template displayed perfectly. However, when I then tried sending it to a Gmail account, it was marked as junk and the HTML was just displayed as plain text. Does anyone know whether there are any additional headers I need to include within the Email to ensure that Gmail treats it correctly?

Ideally I would like to send an Email to myself via webmail on my server and then send an automated response to the user thanking them for their enquiry but this will not be possible if the message is always treated as spam.

<?php
    function mailer_send($mailer_recipient, $mailer_subject, $mailer_message){
         $mailer_headers = 'From: webmaster@example' . '\r\n' .
        'X-Mailer: PHP/' . phpversion() . '\r\n' .
        'MIME-Version: 1.0\r\n' . '\r\n' . 
        'Content-Type: text/html; charset=ISO-8859-1\r\n';
         mail($mailer_recipient, $mailer_subject, $mailer_message, $mailer_headers);
     }

$name = $_POST['inputName'];
$email = $_POST['inputEmail'];
$message = strip_tags($_POST['inputMessage']);
$template = file_get_contents('email_templates/template.txt');
$template2 = $template;
$template = str_replace('[email_content]',$message, $template);

    mailer_send('test@gmail.com','Test Email',$template);

$message2 = '<h2>Thanks..</h2><br/><p>Dear' . $name . '</p><br/><p>Thanks for your enquiry. Jason will get back to you with a quote as soon as possible.</p>';
$template2 = str_replace('[email_content]', $message2, $template2);
mailer_send($email,'Thankyou for your Enquiry',$template2);
  ?>

Thanks in advance.

Additional:

When the Email is received in Gmail it appears to be ignoring the From header and just saying that the Email is from my web hosting providers servers.

解决方案

Theres a million reasons why gmail would suspect the email is spam.

The first thing I would do is use a library that deals with headers correctly -> http://swiftmailer.org/

Secondly, ensure your sender host is coming from the same IP as the server and have correct MX records.

这篇关于通过PHP发送的HTML电子邮件在Gmail中被视为垃圾邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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