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 –