2
我试图在电子邮件正文中嵌入带有png图标的base64图像,但是无论是获取空图像,还是获取原始代码而不是html。我基于Stackoverflow中的其他内容玩过不同的内容类型,我认为它应该是第一个多部分/替代,然后是多部分/混合,但是我不确定哪部分应该进入电子邮件的标题和什么去了电子邮件正文。对此,我无法获得任何好的教程。也许有人知道一些工具,将普通的HTML文档转换为嵌入式图像?在电子邮件正文中嵌入base64图像
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: multipart/alternative; boundary='boundary1'" . "\r\n";
$headers .= "From: StudentOpen <[email protected]>" . "\r\n";
$headers .= "Reply-To: [email protected]" . "\r\n";
$subject = $GLOBALS['tpl']['win_mail_subject'];
$emailText = '';
$emailText .= "Content-type:multipart/mixed; boundary='boundary1'" . "\r\n";
$emailText .= "Content-type:multipart/alternative; boundary='boundary2'" . "\r\n";
$emailText .= '--boundry1' . "\r\n";
$emailText .= "--boundry2" . "\r\n";
$emailText .= "Content-Type: text/html; charset=UTF-8" . "\r\n";
$emailText .= "Content-Transfer-Encoding: 7bit" . "\r\n";
$emailText .= "<html>";
$emailText .= "<head>";
$emailText .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8">';
$emailText .= "</head>";
$emailText .= "<body>";
$emailText .= $GLOBALS['tpl']['howdy'].' '.$tmp_member_username.',';
$emailText .= '<br/>';
$emailText .= $GLOBALS['tpl']['win_mail_description1'];
$emailText .= '<img src="cid:facebook.png" alt="Facebook"/>';
$emailText .= '</body>';
$emailText .= '</html>';
// facebook.png
$emailText .= "--boundry2" . "\r\n";
$emailText .= "Content-Type: image/png;" . "\r\n";
$emailText .= "name='facebook.png'" . "\r\n";
$emailText .= "Content-Transfer-Encoding: base64" . "\r\n";
$emailText .= "Content-ID: <facebook.png>" . "\r\n";
$emailText .= "Content-Disposition: inline;" . "\r\n";
$emailText .= "filename='facebook.png'" . "\r\n";
$emailText .= "iVBORw0KGgoAAAA...AAElFTkSuQmCC" . "\r\n"; // base64 string
$emailText .= "--boundry2" . "\r\n";
$emailText .= "--boundry1" . "\r\n";
$body = $emailText;
mail($user_email, $subject, $body, $headers);
我该怎么做?我作为电子邮件得到的消息被搞乱了。从--boundry1开始,然后我得到原始文本。
您正在将标题放入正文中。看看https://stackoverflow.com/questions/16242489/send-a-base64-image-in-html-email –