[RESOLU] Fonction mail + Upload pièces jointes

Eléphanteau du PHP | 36 Messages

06 mars 2015, 18:47

Bonjour,

j'essaye de faire un formulaire qui envoie un mail pouvant contenir différentes pièces jointes.

Mon mail part bien avec le contenu et les informations sont bonnes....

Toutefois la ou les pièces jointes font 0Ko...

Est-ce que quelqu'un aurait une idée ?

Merci

Code : Tout sélectionner

if(isset($_POST["id"]) && $_POST["id"] == "_envoiClient") { $errors = array(); $_fichiermailpdf = array(); $termsmail = array(); $mail_contenu = utf8d(trim($_POST['_mailclient'])); $path = './files/mails/'; if(!is_dir(''. $path .''. clean($ad_nom) .'-'. clean($ad_prenom) .'')) { mkdir(''. $path .''. clean($ad_nom) .'-'. clean($ad_prenom) .'', 0777, true); } foreach ($_FILES['_fichiermailpdf']['name'] as $file => $key) { $_fichiermailpdf['name'] = $_FILES['_fichiermailpdf']['name'][$file]; $_fichiermailpdf['type'] = $_FILES['_fichiermailpdf']['type'][$file]; $_fichiermailpdf ['size'] = $_FILES['_fichiermailpdf']['size'][$file]; $_fichiermailpdf['tmp_name'] = $_FILES['_fichiermailpdf']['tmp_name'][$file]; $valid_formats = array('pdf'); if(strlen($_fichiermailpdf['name'])) { list($txt, $ext) = explode(".", $_fichiermailpdf['name']); if(in_array($ext,$valid_formats)) { if($_fichiermailpdf['size'] < 5098888) { $actual_image_name = clean($ad_nom) .'-'. clean($ad_prenom) ."/". clean($txt) .".".$ext; $termsmail[] = $actual_image_name; if(!move_uploaded_file($_fichiermailpdf['tmp_name'], $path.$actual_image_name)) { } } } } } $mail = '[email protected]'; $boundary = md5(uniqid(microtime(), TRUE)); $sujet = 'Votre rendez-vous BSV'; $header = 'From: BSV <[email protected]>'."\r\n"; $header .= 'Bcc: Kiba <[email protected]>'."\r\n"; $header.= 'MIME-Version: 1.0'."\r\n"; $header.= 'Content-Type: multipart/mixed; boundary='. $boundary."\r\n"; $header.= 'Reply-To: [email protected]'."\r\n"; $header.= "\r\n"; $message = 'Texte affiché par des clients mail ne supportant pas le type MIME.'."\r\n\r\n"; $message.= '--'.$boundary."\r\n"; $message.= 'Content-Type: text/html; charset="iso-8859-1'."\r\n"; $message.= ' <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Template Mail</title> <style type="text/css"> body { background: #fff; font-family: "Lucida Grande", "Trebuchet MS", sans-serif; color: #292929; } </style> </head> <body> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="border: #a69f8f 1px solid;"> <tbody> <tr> <td colspan="3">&nbsp;</td> </tr> <tr> <td width="20">&nbsp;</td> <td width="560" valign="top">'. $mail_contenu .'</td> <td width="20">&nbsp;</td> </tr> <tr> <td colspan="3">&nbsp;</td> </tr> </tbody> </table> </body> </html>'."\r\n"; foreach($termsmail as $value){ $attachement = chunk_split(base64_encode(file_get_contents($value))); $message.= '--'.$boundary."\r\n"; $message.= 'Content-Type: application/pdf; name='.clean($txt)."\r\n"; $message.= 'Content-transfer-encoding:base64'."\r\n\r\n"; $message.= $attachement."\r\n"; } $message.= '--'.$boundary."\r\n"; mail($mail,utf8e($sujet),$message,utf8d($header)); }

Mammouth du PHP | 688 Messages

06 mars 2015, 19:00

pour autre chose qu'un simple email, je conseillerais d'utiliser https://github.com/Synchro/PHPMailer pour moins s'embeter.

Eléphanteau du PHP | 36 Messages

06 mars 2015, 19:51

Très bien tof73, merci !