Dears,
I’ve got a small issue with the PHP function mail(). I would like to send a mail with an attachment. It looks nice, except the fact that the attachment the adressee gets in his mail browser (Outlook for instance) remains coded and the owner application (MSWord for instance) cannot decode it
I give you hereunder an extract of my code :
Code:
$objet = $_POST['Objet'];
$corps = nl2br($_POST['Corps']);
$from = $_POST['From'];
$frontiere = md5(uniqid(mt_rand()));
$pj = $_FILES['PJ']['name'];
$typ = $_FILES['PJ']['type'];
$ser = $_FILES['PJ']['tmp_name'];
$tai = $_FILES['PJ']['size'];
$err = $_FILES['PJ']['error'];
//html text part
$message = '--'.$frontiere."\r\n";
$message .= 'Content-Type: text/html; charset="iso-8859-1"'."\r\n\n";
$message.= $corps;
$message.='<hr>Ce message a été envoyé depuis l\'interface WebMail du site http://www.lh1661.be <br>le '.horodate(time()).' par '.$_SESSION['prenom'].' '.$_SESSION['nom'].' ['.sectionlon($_SESSION['section']).']';
$message.="\r\n\n";
// Attached file part
$message .= '--'.$frontiere."\r\n";
$message .= 'Content-Type: '.$typ.'; name="'.$pj.'"'."\r\n\n";
$message .= 'Content-Transfer-Encoding:base64'."\r\n\n";
$message .= 'Content-Disposition:attachement; filename="'.$pj.'"'."\r\n\n";
$message .= chunk_split(base64_encode(file_get_contents($ser)))."\r\n\n";
//end of msg
$message .='--'.$frontiere.'--'."\r\n";
$sujet = 'Email lh1661.be - '.$objet;
$mailheaders = 'Mime-Version: 1.0'."\r\n";
$mailheaders .= 'From: '.$from."\r\n";
$mailheaders .= 'Reply-To: '.$from."\r\n";
$mailheaders .= 'Content-Type: multipart/mixed; boundary="'.$frontiere.'"'."\r\n\n";
if ($_POST['AR']=='O')
$mailheaders .= 'Disposition-Notification-To : '.$_SESSION['mail']."\r\n";
$mailheaders .= 'X-Mailer: PHP/' . phpversion(); [/b][/b]
mail($data['Mail'], $objet, $message, $mailheaders);
Thks in advance for your always precious help.