电子邮件附件丢失样式PHP [英] Email with attachments losing style PHP

查看:89
本文介绍了电子邮件附件丢失样式PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以前,我有一些代码可以发送没有附件的电子邮件,只是启用了html的文本,所以我有自定义字体,背景颜色等等。我已经为我的代码添加了附件支持,但是有些东西导致font-family属性被忽略。



当前代码:

Hi,

Previously, I had some code to send an email without attachments, just text with html enabled so I had custom fonts, background colours etc. Now I've added attachment support to my code, but something is causing the font-family attributes to be ignored.

Current code:

<pre>$uid = md5(uniqid(time()));
        $filename = 'invoice.html';
        $file_size = filesize($filepath);
        $content = chunk_split(base64_encode(file_get_contents($filepath)));

        $headers = "From: Me <myemail.co.uk>\r\n";
        $headers .= "Reply-To: myemail.co.uk\r\n";
        $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=UTF-8" . "\r\n";
        // html is now enabled
        $headers .= $message . "\r\n\r\n";
        $headers .= "--" . $uid . "\r\n";
        $headers .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"\r\n";
        $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 . "--";



现在使用以下方式调用:


This is now called using:

mail('email@whatever', 'subject', '', $headers);



但是之前的版本,字体有效,是


But the previous version, where fonts worked, was

mail('email@whatever', 'subject', 'body', $headers); // headers are only mime-version and content-type of html





任何有助于识别问题的帮助都将受到赞赏c:



我的尝试:



-------- -------------------------------------------------- ------------------------------------------



Any help to identify the issue would be appreciated c:

What I have tried:

----------------------------------------------------------------------------------------------------

推荐答案

uid = md5(uniqid(time()));
uid = md5(uniqid(time()));


filename ='invoice.html';
filename = 'invoice.html';


file_size = filesize(
file_size = filesize(


这篇关于电子邮件附件丢失样式PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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