Using Mail_Mime to send attachment to GMail, receiving “noname” attachment

不羁岁月 提交于 2019-12-03 16:21:02

Have you tried adding a Content-Type variable to your addAttachment() arguments list? For example, if you knew the user was uploading .pdf documents, you would do the following:

$Filepath = $Uploads_folder.$Filename;
$content_type = "Application/pdf";
$mime->addAttachment($Filepath, $content_type);

Recently, I had to implement a service that send an email from android app via an apache server of mine.

This server runs sendmail service.

I tested 3 domains.

  1. @naver.com
  2. @gmail.com
  3. @does.kr

I'v test several codes and realized that the 'boundary' header matters So much.


My first boundary was nothing.

Content-Type: multipart/mixed; boundary=;

I sent emails with 2 attached files and that header.

The email looked fine in does.kr and naver.com.

But it didn't in gmail.com. I saw 'noname' files, which is a problem that hasn't been solved yet since 2007 as far as I know.


My second boundary was "----=part56d7fa8d7a369", made of unique() of php.

Content-Type: multipart/mixed; boundary=----=part56d7fa8d7a369;

I sent emails with the same files except the header.

The email looked fine in does.kr and gmail.com.

But it didn't in naver.com. I saw nothing but title in the naver.com.


The only difference was that 'boundary' and the result was quite different.

So, I had to ramify my code to make different 'boundary' depending on the email address.

And it worked great.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!