elino10 | Bonjour,
J'ai fait un petit script pour envoyer un mail avec au maximum deux pièces jointes
Le problème est que les pièces jointes doivent être sur le serveur.
Je souhaite donc modifier mon script pour ajouter une fonction parcourir, pour aller chercher soi même les fichiers sur notre ordinateur
Mon formulaire
Code :
- <form action="contactmail.php" method="post" name="contactmail" >
- <p>Email du destinataire : <input type="email" name="email" /></p>
- <p>Votre adresse email : <input type="email" name="my_email" /></p>
- <p>Sujet : <input type="text" name="subject" /></p>
- <p><textarea name="message" rows="10" cols="50"></textarea></p>
- <p>Piece jointe 1 : <input type="text" name="file_name1" /></p>
- <p>Piece jointe 2 : <input type="text" name="file_name2" /></p>
- <p><input type="submit" value="Envoyer" /></p>
- </form>
|
Mon script
Code :
- <?php
- $boundary = "-----=".md5(uniqid(rand()));
- $header = "MIME-Version: 1.0\r\n";
- $header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
- $header .= "\r\n";
- $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 .= $_POST['message'];;
- $msg .= "\r\n";
- $file = $_POST['file_name1'];
- $fp = fopen($file, "rb" );
- $attachment = fread($fp, filesize($file));
- fclose($fp);
- $attachment = chunk_split(base64_encode($attachment));
- //piece jointe fichier1
- $msg .= "--$boundary\r\n";
- $msg .= "Content-Type: pdf; 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";
- $file = $_POST['file_name2'];
- $fp = fopen($file, "rb" );
- $attachment = fread($fp, filesize($file));
- fclose($fp);
- $attachment = chunk_split(base64_encode($attachment));
- //piece jointe fichier2
- $msg .= "--$boundary\r\n";
- $msg .= "Content-Type: pdf; 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 = $_POST['email'];
- $expediteur = $_POST['my_email'];
- $sujet = $_POST['subject'];
- $reponse = $expediteur;
- mail($destinataire, $sujet, $msg,"Reply-to: $reponse\r\nFrom: ".$expediteur."\r\n".$header);
- ?>
|
|