Blank Multipart email

2020-04-11 14:12发布

I'm using PHP to send out a multipart/mixed message (plain text, html and attachments). However, whilst it works for most accounts, Yahoo, GMail and Sky seem to show blank emails. Where as everything else seems to display the email. ANY HELP WOULD BE GREATLY APPRECIATED!

My headers are

$headers .= "Content-Type: multipart/mixed; boundary=\"mixed-" . $random_hash . "-mixed\"\n";
$headers .= "MIME-Version: 1.0\n"; 

And the content is;

--mixed-7df05b31-mixed  

Content-Type: multipart/alternative; boundary="alt-7df05b31-alt"  

--alt-7df05b31-alt 

Content-Type: text/plain; charset=utf-8 

            Hello how are you? I am just checking the mailing function.

            Hopefully this will work!

            Cheers.

--alt-7df05b31-alt 

Content-Type: text/html; charset=utf-8 

<div style="font-family:Arial, Helvetica, sans-serif; font-size: 10pt;">

<div> 


            Hello how are you? I am just <b>checking</b> the mailing function.<br><br>


            Hopefully this will work!<br><br>


            Cheers.</div></div>

--alt-7df05b31-alt--

--mixed-7df05b31-mixed 

Content-Type: text/plain; name="abc.txt"  
Content-Disposition: attachment; filename="abc.txt"   
Content-Transfer-Encoding: base64

SEVMTE8gSlVTVCBURVNUSU5HIC4uLiA=

--mixed-7df05b31-mixed--

3条回答
Explosion°爆炸
2楼-- · 2020-04-11 14:50

Don't build your own MIME messages. use Swiftmailer or PHPMailer to do it for you.

查看更多
孤傲高冷的网名
3楼-- · 2020-04-11 14:59

It may be an artifact from pasting, but try removing the blank space at the end of each boundary. (Highlight the text and you'll notice the boundaries have an extra space, but the closing boundaries-- do not)

查看更多
Deceive 欺骗
4楼-- · 2020-04-11 15:01

Please verify whether your code is look like the following because the following code is working fine for me.

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= "This is a multi-part message in MIME format.\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $msg."\r\n\r\n";    
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type:application/html; name=\"".$filename."\" \r\n"; // use different content types here
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";
$headers .= "--".$uid."--";
查看更多
登录 后发表回答