Swiftmailer邮件进入垃圾邮件文件夹

编程入门 行业动态 更新时间:2024-10-19 16:23:15
本文介绍了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'=> 'from Address')) - > setTo(array('to@mail'=>'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' => 'From Address')) ->setTo(array('to@mail' => '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邮件进入垃圾邮件文件夹

本文发布于:2023-10-12 23:51:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:垃圾邮件   文件夹   邮件   Swiftmailer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!