我有問題,而我嘗試發送帶附件的電子郵件,我只是得到空白附件的消息,我怎麼能修復它。這裏是我的代碼:電子郵件問題,同時添加附件文件
$html2pdf = new HTML2PDF("P","A4", "fr");
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$to = "[email protected]";
$subject = "Voucher Mediskon";
$random_hash = md5(date("r", time()));
$headers = "From: Admin Mediskon<[email protected]" . $domain . ">\r\nReply-To: [email protected]" . $domain;
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode($html2pdf->Output("", "S")));
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
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Terimakasih telah membeli voucher kami. Mediskon</h2>
<p>Silakan <b>unduh (download)</b> voucher pada <b>attachment</b> yang kami kirim.</p>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/pdf; name="voucher.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
$message = ob_get_clean();
$mail_sent = @mail($to, $subject, $message, $headers);
也許清理你的文章一點點,這是很難看現在。 – 2011-04-19 03:58:24
如果這不是爲了學習MIME郵件的工作方式,請考慮使用庫。 – 2011-04-19 09:38:07