在这种情况下,$ 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邮件进入垃圾邮件文件夹
发布评论