开发者

Email Problem while add attachment file

I have problem while i try to send email with attachment file, i just get message with blank attachment, how i can fix it. Here is my code:

$html2pdf = new HTML2PDF("P","A4", "fr");
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$to = "example@yahoo.com"; 
$subject = "Voucher Mediskon";
$random_hash = md5(date("r", time()));
$headers = "From: Admin Mediskon<admin@" . $domain . ">\r\nReply-To: admin@" . $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 );
开发者_开发知识库


Don't use PHP's mail function directly. It is insecure and inflexible. Plus you are reinventing the wheel. Here are two great email libraries that support HTML and file attachments:

  • SwiftMailer
  • PHPMailer


i just get message with blank attachment

So the problem is not with the email, nor is with the process of attaching the file to the email.

Have you looked at the raw data in the message to see if the attachment is null length?

Have you tried writing the generated PDF to a file to check its contents?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜