File "email_attach.php"
Full Path: /home/analogde/www/download/CHESS_2022/email_attach.php
File size: 2.32 KB
MIME-type: text/html
Charset: 8 bit
<html>
<body>
<?php
//----------------------------------
// Construction de l'entte
//----------------------------------
$boundary = "-----=".md5(uniqid(rand()));
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header .= "\r\n";
//--------------------------------------------------
// Construction du message proprement dit
//--------------------------------------------------
$msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n";
//---------------------------------
// 1re partie du message
// Le texte
//---------------------------------
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding:8bit\r\n";
$msg .= "\r\n";
$msg .= "Ceci est un mail avec 2 fichiers joints\r\n";
$msg .= "\r\n";
//---------------------------------
// 2nde partie du message
// Le 1er fichier (inline)
//---------------------------------
$file = "01.jpg";
$fp = fopen($file, "rb"); // le b c'est pour les windowsiens
$attachment = fread($fp, filesize($file));
fclose($fp);
$attachment = chunk_split(base64_encode($attachment));
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: image/gif; name=\"$file\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: inline; filename=\"$file\"\r\n";
$msg .= "\r\n";
$msg .= $attachment . "\r\n";
$msg .= "\r\n\r\n";
//---------------------------------
// 3me partie du message
// Le 2me fichier (attachment)
//---------------------------------
$file = "02.pdf";
$fp = fopen($file, "rb");
$attachment = fread($fp, filesize($file));
fclose($fp);
$attachment = chunk_split(base64_encode($attachment));
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: image/gif; name=\"$file\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment; filename=\"$file\"\r\n";
$msg .= "\r\n";
$msg .= $attachment . "\r\n";
$msg .= "\r\n\r\n";
$msg .= "--$boundary--\r\n";
$destinataire = "patrice.delpy@neuf.fr";
$expediteur = "moi@monsite.com";
$reponse = $expediteur;
echo "Ce script envoie un mail avec 2 fichiers joints $destinataire";
mail($destinataire,
"Email avec 2 fichiers joints (dont 1 inline)",
$msg,
"Reply-to: $reponse\r\nFrom: $destinataire\r\n".$header);
?>
</body>
</html>