【发布时间】:2018-08-11 07:35:48
【问题描述】:
它在电子邮件中包含编码图像,但不会显示它。我得到的只是一个占位符。我知道图书馆,但感觉就像我很接近:)
这是一封带有附件的 html 电子邮件,而内嵌图片只是顶部的横幅。附件工作正常。
<?php
date_default_timezone_set('America/Chicago');
$heading_s_date = date("F j, Y",strtotime($start_date)); //to get format 2018-11-31 only
$heading_e_date = date("F j, Y",strtotime($end_date)); //to get format 2018-11-31 only
$subject = 'Account Updater Report for: ' . $merchant_name . '--' . $start_date . ' to ' . $end_date;;
$random_hash = md5(date('r', time()));
$headers = "From: customerservice@calligraphydallas.com\r\nReply-To: customerservice@forte.net";
$headers .= "\r\nContent-Type: multipart/html; boundary=\"PHP-mixed-".$random_hash."\"";
$image = 'banner010.jpg';
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
$inline = chunk_split(base64_encode(file_get_contents($image)));
ob_start();
?>
This is a multi-part message in MIME format.
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/mixed; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Here is your Account Updater report.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: image/jpg; name="banner010.jpg"
Content-Transfer-Encoding: base64
Content-ID: <image_identifier>
Content-Disposition: inline; filename="banner010.jpg"
<?php $headers .= $inline."\r\n"; ?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<a href="https://www.forte.net/"><img border="0" src="cid:image_identifier"></a><br>
<p><font face="Calibri"><span style="font-size: 15pt;"><b>Attached please find your Account Updater report.</b></span></font></p>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/text; name="<?php echo $filename; ?>"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
--PHP-alt-<?php echo $random_hash; ?>
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
$message = ob_get_clean();
$mail_sent = @mail( $sendto, $subject, $message, $headers );
?>
任何帮助将不胜感激。
【问题讨论】: