
le 20/06/2003 à 13:30
Mail avec piece jointe
Lamoukate : c'est caca çà pour le serveur mail :)
FICHIER INDEX.PHP
<html>
<head>
<title>Formulaire</title>
</head>
<body>
<b><u>Formulaire</u> :</b><br><br>
<table>
<form action="./traite_formulaire.php" method="post" enctype="multipart/form-data">
<tr><td align="right">Votre nom : </td><td><input type="texte" name="nom" maxlength="40"></td></tr>
<tr><td align="right">Votre @ Email : </td><td><input type="texte" name="email" maxlength="125"></td></tr>
<tr><td align="right">Titre de votre message : </td><td><input type="texte" name="titre" maxlength="60"></td></tr>
<tr><td valign="top" align="right">Corps de votre message : </td><td><textarea name="corps" cols="50" rows="10">
</textarea></td></tr>
<tr><td align="right">Votre fichier image : </td><td><input name="fichier" type="file"></td></tr>
<tr><td> </td><td><br><br><input type="submit" name="ok" value="Soumettre"></td></tr>
</table>
<!— le value qui suit sert à définir la taille maximale du fichier que l'on pourra uploadé -->
<input type="hidden" name="MAX_FILE_SIZE" value="102400">
</form>
</body>
</html>
FICHIER TRAITE_FORMULAIRE.PHP
<?
// **************
// CONFIGURATION
// **************
$destinataire = "la_globule@noos.fr"; // adresse email de celui qui va rececoir le mail du visiteur
$objet = "Objet du mail"; // objet du mail qui sera envoyé à l'adresse juste au-dessus
$max_size = 100000; // Taille maximale du fichier image que l'on pourra uploade
// Contenu du mail qui sera envoyé (il s'agit en fait d'une pahe html tout conne contenant les informations du formulaire)
$message = '<html>';
$message .= '<head>';
$message .= '<title>Remplissage du formulaire par un client</title>';
$message .= '</head>';
$message .= '<body>';
$message .= '<b><u>Nom du contact</u> :</b> '.$nom.'<br>';
$message .= '<b><u>@ mail du contact</u> :</b> '.$email.'<br><br>';
$message .= '<b><u>Titre de son article</u> :</b> '.$titre.'<br><br>';
$message .= '<b><u>Corps de son message</u> :</b><br><br>'.$corps;
$message .= '</body>';
$message .= '</html>';
// **********************
// LE SCRIPT EN LUI MEME
// **********************
function email_OK ($email) {
$test_mail=eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$',$email);
if ($test_mail) {
list ($login, $domaine) = split ("@", $email,2);
/*
if (checkdnsrr ($domaine, "MX")) {
return TRUE;
}
else {
return FALSE;
}
*/
return TRUE;
}
else {
return FALSE;
}
}
if (empty($fichier)) {
echo '<body onLoad="alert(\'Aucun fichier de sélectionné...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if ($nom == "") {
echo '<body onLoad="alert(\'Le mot de passe est vide...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if ($email == "") {
echo '<body onLoad="alert(\'Aucune adresse E-amil de saisie...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if ($titre == "") {
echo '<body onLoad="alert(\'Votre titre est vide...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if ($corps == "") {
echo '<body onLoad="alert(\'Le corps de votre message est vide...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if ($fichier_size > $max_size || $fichier_size == 0) {
echo '<body onLoad="alert(\'La taille du fichier est incorrecte...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if (!$fichier || $fichier == "none") {
echo '<body onLoad="alert(\'La format du fichier est incorrect...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if (strpos($fichier_name,"\\") || strpos($fichier_name, "/")) {
echo '<body onLoad="alert(\'La format du fichier est incorrect...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if (!stristr($fichier_name, ".jpg") && !stristr($fichier_name, ".jpeg") && !stristr($fichier_name, ".gif")) {
echo '<body onLoad="alert(\'La format du fichier est incorrect...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if (!stristr($fichier_type, "gif") && !stristr($fichier_type, "pjpeg") && !stristr($fichier_type, "plain")) {
echo '<body onLoad="alert(\'La format du fichier est incorrect...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else if (file_exists("./$fichier_name")) {
echo '<body onLoad="alert(\'Le fichier existe déjà. Choisissez-en un autre...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else {
if (email_OK($email)) {
$corps = stripslashes ($corps);
$corps = nl2br ($corps);
$boundary = "-----=".md5(uniqid(rand()));
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header .= "\r\n";
$msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n";
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding:8bit\r\n";
$msg .= "\r\n";
$msg .= $message."\r\n";
$msg .= "\r\n";
$fp = fopen($fichier, "rb");
$attachment = fread($fp, filesize($fichier));
fclose($fp);
$attachment = chunk_split(base64_encode($attachment));
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: image/gif; 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";
mail($destinataire, $objet , $msg, "Reply-to: $email\r\nFrom: $email\r\n".$header);
echo '<body onLoad="alert(\'Merci pour votre contribution...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
else {
echo '<body onLoad="alert(\'Votre adresse email est invalide...\')">';
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
exit;
}
}
?>
<input type="text" name="toto" value="<?php echo $valeur; ?>">