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 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
Le Formulaire :
<html> <body>
<form ENCTYPE="multipart/form-data" action="./mail4.php" method=POST>
<center>
De: <input type=text name = "from" size="30"><br>
Destinataire: <input type=text name = "to" size="30"><br>
Sujet: <input type=text name = "sujet" size="30"><br><br>
Texte :<br><textarea name="message" rows="15" cols="40"></textarea><br>
<INPUT TYPE=FILE NAME="monfichier"><BR>
<input type=submit value="envoi">
</center>
</form>
</body> </html>
Le fichier de traitement :
<html> <body> <center>
<?
$name_file = $_FILES['monfichier']['name'];
// Construction de l'entête
if($_POST['to']!="")
{
$boundary = "-----=".md5(uniqid(rand()));
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header .= "\r\n";
$msg ="\r\n";
$msg .= "--$boundary\r\n";
$msg .= "Content-Transfer-Encoding:64it\r\n";
$msg .= "\r\n";
$msg .= $_POST['message'];
$msg .= "\r\n";
if($name_file!="")
{
$file = $name_file;
$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/jpeg; 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";
$msg .= "--$boundary--\r\n";
}
$destinataire = $_POST['to'];
$expediteur = $_POST['from'];
$reponse = $expediteur;
mail($destinataire, $_POST['sujet'], $msg, "Reply-to: $reponse\r\nFrom: $expediteur\r\n".$header);
}
?>
</center> </body> </html> |
Partager