PHP电子邮件包括但不显示内嵌图像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP电子邮件包括但不显示内嵌图像相关的知识,希望对你有一定的参考价值。
它将编码图像包含在电子邮件中,但不会显示它。我得到的只是一个占位符。我知道这些库,但感觉就像我太近了:)
这是一个带有附件的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
Reply-To: customerservice@forte.net";
$headers .= "
Content-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."
"; ?>
--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 );
?>
任何帮助,将不胜感激。
答案
以下是使用URL引用图像的工作原理:
<?php
date_default_timezone_set('America/Chicago');
$heading_s_date = date("F j, Y",strtotime($start_date));
$heading_e_date = date("F j, Y",strtotime($end_date));
$subject = 'Account Updater Report for: ' . $merchant_name . '--' . $start_date . ' to ' . $end_date;;
$random_hash = md5(date('r', time()));
$headers = "From: customerservice@calligraphydallas.com
Reply-To: customerservice@forte.net";
$headers .= "
Content-Type: multipart/mixed; boundary="PHP-mixed-".$random_hash.""";
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
ob_start();
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; 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: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<a href="https://www.forte.net/"><img border="0" src="http://www.calligraphydallas.com/updater/banner02.png" alt="Forte Payment Systems" width="804" height="166"></a><br>
<p><font face="Calibri"><span style="font-size: 15pt;"><b>Attached please find your Account Updater report.</b></span></font></p>
<p><font face="Calibri"><span style="font-size: 12pt;">For: <?php echo $merchant_name?></span></font><br>
<font face="Calibri"><span style="font-size: 12pt;"><?php echo $heading_s_date . ' to ' . $heading_e_date; ?></span></font><br>
<font face="Calibri"><span style="font-size: 12pt;">Created on: <?php echo date("F j, Y") . ' at ' . date("g:i a"); ?> CST</span></font><br><br>
<font face="Calibri"><span style="font-size: 13pt;"><b>Forte Customer Service:</b></span><br>
<span style="margin-left:50px; font-size:12pt;">7:00 am - 7:00 pm CST</span><br>
<span style="margin-left:50px; font-size:12pt;">866.290.5400 option 1</span><br>
<span style="margin-left:50px; font-size:12pt;">customerservice@forte.net</span></font></p>
<p> </p>
<p> </p>
<p> </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 echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
$message = ob_get_clean();
$mail_sent = @mail( $sendto, $subject, $message, $headers );
?>
所以是的....现在我只想将横幅图像内嵌而不是链接到它。
请?
另一答案
OMG我得到它工作大声笑
<?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
Reply-To: customerservice@forte.net";
$headers .= "
Content-Type: multipart/mixed; boundary="PHP-mixed-".$random_hash.""";
$image = 'banner02.png';
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
$banner = chunk_split(base64_encode(file_get_contents($image)));
ob_start();
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/related; boundary="PHP-rel-<?php echo $random_hash; ?>"
--PHP-rel-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Here is your Account Updater report.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<a href="https://www.forte.net/"><img border="0" src="cid:image_identifier" title="Forte Payment Systems" alt="Forte Payment Systems" width="804" height="166"></a><br>
<p><font face="Calibri"><span style="font-size: 15pt;"><b>Attached please find your Account Updater report.</b></span></font></p>
<p><font face="Calibri"><span style="font-size: 12pt;">For: <?php echo $merchant_name?></span></font><br>
<font face="Calibri"><span style="font-size: 12pt;"><?php echo $heading_s_date . ' to ' . $heading_e_date; ?></span></font><br>
<font face="Calibri"><span style="font-size: 12pt;">Created on: <?php echo date("F j, Y") . ' at ' . date("g:i a"); ?> CST</span></font><br><br>
<font face="Calibri"><span style="font-size: 13pt;"><b>Forte Customer Service:</b></span><br>
<span style="margin-left:50px; font-size:12pt;">7:00 am - 7:00 pm CST</span><br>
<span style="margin-left:50px; font-size:12pt;">866.290.5400 option 1</span><br>
<span style="margin-left:50px; font-size:12pt;"><a href="mailto:customerservice@forte.net">customerservice@forte.net</a></span></font><br>
<span style="margin-left:50px; font-size:12pt;"><a href="https://www.forte.net/">www.forte.net</a></span></font></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-rel-<?php echo $random_hash; ?>
Content-Type: image/png;
name="banner02.png"
Content-Transfer-Encoding: base64
Content-ID: <image_identifier>
Content-Disposition: inline;
filename="banner02.png"
<?php echo $banner; ?>
--PHP-rel-<?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 echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
$message = ob_get_clean();
$mail_sent = @mail( $sendto, $subject, $message, $headers );
?>
以上是关于PHP电子邮件包括但不显示内嵌图像的主要内容,如果未能解决你的问题,请参考以下文章