Swiftmailer邮件进入垃圾邮件文件夹 [英] Swiftmailer mails go into SPAM Folder

查看:114
本文介绍了Swiftmailer邮件进入垃圾邮件文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ headers =\r\\\
。 MIME-Version:1.0。 \r\\\
;
$ headers。=Content-type:text / html; charset = iso-8859-1。 \r\\\
;

$ message = Swift_Message :: newInstance()
- > setSubject($ subject)
- > setFrom(array('from@mail.com'=> 'from Address'))
- > setTo(array('to@mail.com'=>'To Address'))
- > setBody($ message_plain_txt)
- > addPart($ message,'text / html')
;
if($ file_name)
{
$ message-> attach(Swift_Attachment :: fromPath($ file_path));
}

$ result = $ mailer-> send($ message);

在这种情况下,$ filepath是用户从一个文件附加文件时使用的tmp路径表单和$ file_name是tmp文件名称$ _FILES ['file'] ['name']。



在此设置中,我可以发送邮件,但是当有一个附件,邮件进入SPAM文件夹。如果没有附件,那么邮件进入收件箱。



当我从某个位置上传文件而不是从表单发送附件时,此设置工作正常。 / p>

我认为这与电子邮件标题有关,但我无法弄清错误。



可以通过修改标题到


$ b $来获得它的工作b

  $ headers =MIME-Version:1.0。 \r\\\
;
$ headers。=Content-type:text / plain; charset = iso-8859-1\\\
;


解决方案

添加以下标题以避免进入垃圾邮件文件夹:

  $ headers。=Message-ID:& SERVER_NAME'] > \r\\\

$ headers。=X-Mailer:PHP v.phpversion()。\r\\\
;


$headers = "\r\n" . "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$message = Swift_Message::newInstance()
                ->setSubject($subject)
                ->setFrom(array('from@mail.com' => 'From Address'))
                ->setTo(array('to@mail.com' => 'To Address'))
                ->setBody($message_plain_txt)
                ->addPart($message, 'text/html')
        ;
if ($file_name)
        {
            $message->attach(Swift_Attachment::fromPath($file_path));
        }

$result = $mailer->send($message);

In this case $filepath is the tmp path which I am using when a user attaches a files from a form and $file_name is the tmp file name $_FILES['file']['name'].

In this setup I am able to send mails but when there is an attachment, the mail goes into SPAM folder. If there is no attachment then mail goes into inbox.

This setup works perfectly fine when I am uploading a file from a location and not sending the attachment from a form.

I think it has got something to do with the email headers, but i am not able to figure out the error.

Can some one please help me with what mistake I am doing here.

Got it working by modifying headers to

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";

解决方案

Add the following headers to avoid going to spam folder:

$headers .= "Message-ID: <".time()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";         

这篇关于Swiftmailer邮件进入垃圾邮件文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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