J'ai un problème alors que je tente d'envoyer un courriel avec fichier joint, je viens de passer le message avec pièce jointe vide, comment je peux le réparer. Voici mon code:Email Problème lors de fichiers de pièces jointes add
$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);
Peut-être nettoyer votre poste un peu, c'est assez difficile à lire tel quel. –
Si ce n'est pas dans le but d'apprendre le fonctionnement du courrier MIME, pensez à utiliser une bibliothèque. –