1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| <?
$from=$_POST['from'];
$to=$_POST['to'];
$topic=$_POST['topic'];
$msg=$_POST['msg'];
$pj=$_POST['pj'];
$boundary1='----'.md5(uniqid(mt_rand()));
$headers='';
$headers.='From: "nom" <'.$from.'>'.'\n';
$headers.='Return-Path: <'.$from.'>'.'\n';
$headers.='MIME-Version: 1.0'.'\n';
$headers.='Content-Type: multipart/mixed; boundary="'.$boundary1.'"';
$message='';
$message.='This is a multi-part message in MIME format.'.'\n\n';
//mesage
$message.='--'.$boundary1.'\n';
$message.='Content-Type: text/plain; charset=ISO-8859-1;'.'\n';
$message.='Content-Transfer-Encoding: 8bit'.'\n\n';
$message.=stripslashes($msg).'\n\n';
//piece jointe
$message.='--'.$boundary1.'\n';
$message.='Content-Type: application/octet-stream'.'\n';
$message.='"name="fichier.ext"'.'\n';
$message.='Content-Transfer-Encoding: base64'.'\n';
$message.='Content-Disposition: attachment'.'\n';
$message.='filename="fichier.ext"'.'\n';
$fp=fopen('./'.$pj, "r");
$attachment=fread($fp,filesize('./'.$pj));
fclose($fp);
$message.=chunk_split(base64_encode($attachment)).'\n\n';
//fin
$message.='--'.$boundary1.'--';
if (!mail($to,$topic,$message,$headers)) {
echo "pas envoyé";
} else {
echo "envoyé";
}
?> |
Partager