Bonjour,
j'ai recopié les codes de tes 2 pages tels quels (form.php et send.php)
ça ne marche pas !
y-a-t-il des paramétrages à réaliser (autre que l'email de destination) ?
d'avance merci
[quote="nick3340"][quote="Cyrano"]
Saisis-tu mieux expliqué comme ça ?[/quote]
Oui merci, :D j'ai bien avancé.
Tout fonctionne sauf quand le visiteur met un fichier plus gros que la taille autorisée j'ai ça comme erreur :
Warning: fread(): supplied argument is not a valid stream resource in...
Normalement il devrait avoir : "Votre fichier doit faire moins de 2mo !"
Enfin, c'est pas très grave non plus.
Mes nouvelles pages :
Page form.php
[php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.texte12 {color: #000000; font-size: 12px; font-family: verdana,arial;}
-->
</style>
</head>
<body>
<FORM METHOD="POST" ACTION="send.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="2">
<tr bgcolor="#FFBB77" class="texte12">
<td width="50%">Votre nom :</td>
<td width="50%"><input name="nom" type="text" id="nom" value=""></td>
</tr>
<tr bgcolor="#FFBB77" class="texte12">
<td width="50%">E-mail :</td>
<td width="50%"><input name="email" type="text" id="email" value=""></td>
</tr>
<tr valign="top" bgcolor="#FFBB77" class="texte12">
<td width="50%"><legend>Envoi de fichiers</legend>
</td>
<td width="50%">
<!-- champs d'envoi de fichier, de type file -->
<fieldset>
<label for="fichier">Fichier :</label>
<input type="file" name="fichier"/>
</fieldset></td>
</tr>
<tr bgcolor="#FFBB77">
<td colspan="2"><div align="center">
<!-- bouton d'envoi -->
<input type="submit" name="Submit" value="Valider">
</div></td>
</tr>
</table>
</body>
</html>
[/php]
Page send.php
[php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
function mail_attachement_html($to , $sujet , $message , $fichier , $typemime , $nomdoc , $reply , $from)
{
$limite = "_parties_". md5(uniqid (rand()));
$mail_mime = "Date: ".date("l j F Y, G:i")."\n";
$mail_mime .= "MIME-Version: 1.0\n";
$mail_mime .= "Content-Type: multipart/mixed;\n";
$mail_mime .= " boundary="----=". $limite .""\n\n";
$limite2 = "_parties_". md5 (uniqid (rand()));
/* Le message en texte simple pour les navigateurs qui n'acceptent pas le HTML */
$texte_simple .= "This is a multi-part message in MIME format.\n\n";
$texte_simple .= "------=". $limite ."\n";
$texte_simple .= "Content-Type: multipart/alternative;\n";
$texte_simple .= "\tboundary="----=". $limite2 .""\n\n";
$texte_simple .= "------=". $limite2 ."\n";
$texte_simple .= "Content-Type: text/plain; \tcharset="iso-8859-1"\n";
$texte_simple .= "Content-Transfer-Encoding: quoted-printable\n\n";
$texte_simple .= strip_tags(eregi_replace("<br>", "\n", $message));
$texte_simple .= "\n\n";
/* le message en html original */
$texte_html = "------=". $limite2 ."\n";
$texte_html .= "Content-Type: text/html; charset="iso-8859-1"\n";
$texte_html .= "Content-Transfer-Encoding: quoted-printeble\n\n";
$texte_html .= $message;
$texte_html .= "\n\n\n------=". $limite2 ."--\n";
/* le fichier */
$attachement = "------=". $limite ."\n";
$attachement .= "Content-Type: ". $typemime ."; name="". $nomdoc .""\n";
$attachement .= "Content-Transfer-Encoding: base64\n";
$attachement .= "Content-Disposition: attachment; filename="". $nomdoc .""\n\n";
$fd = fopen( $fichier, "r" );
$contenu = fread( $fd, filesize( $fichier ) );
fclose( $fd );
$attachement .= chunk_split(base64_encode($contenu));
$attachement .= "\n\n\n------=". $limite ."\n";
return mail($to, $sujet, $texte_simple.$texte_html.$attachement, "Reply-to: ". $reply ."\nFrom: ". $from ."\n".$mail_mime);
}
// ----------------- Début configuration --------------------
// On récupère les données du formulaire
$nom = $_POST['nom'];
$email = $_POST['email'];
// Notez ici l'adresse qui recevra le mail et le fichier
$to = '
[email protected]' . ', '; // notez la virgule
// L'adresse du visiteur récupérée plus haut
$to .= "$email";
// Le sujet du mail
$sujet = "Sujet";
// Votre message en html
$message = "
<head>
<title>Votre message en html</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
</head>
<body>
<table width='100%' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#FFFFFF'>
<tr>
<td><div align='center'><b> Merci $nom, Nous avons bien reçu votre fichier </b>
</div></td>
</tr>
</table>
</body>
</html>";
// Changer fichier par l'intitulé configuré dans la page formulaire.php, si vous n'avez rien modifié, laissez tel quel
$typemime = $_FILES['fichier']['type'];
$fichier = $_FILES['fichier']['tmp_name'];
$nomdoc = $_FILES['fichier']['name'];
// Adresse de réponse au mail
$reply = "
[email protected]";
// Expéditeur
$from = "
[email protected]";
// Vous pouvez ajouter ou retirer des extensions si vous le souhaitez
$extensions_ok = array('png', 'gif', 'jpg', 'jpeg', 'doc', 'rtf', 'pdf', 'xls', 'pps', 'ppt', 'zip', 'rar');
// Configurez la taille maximale du fichier en octets, ici 2mo
$taille_max = 2097152;
if(isset($_FILES['fichier']))
{
unset($erreur);
// vérifications
if( !in_array( substr(strrchr($_FILES['fichier']['name'], '.'), 1), $extensions_ok ) )
{
// Vous pouvez changez l'intitulé de la réponse d'erreur si vous le souhaitez
$erreur = 'Extension non autorisée !';
}
elseif( file_exists($_FILES['fichier']['tmp_name'])
and filesize($_FILES['fichier']['tmp_name']) > $taille_max)
{
// Vous pouvez changez l'intitulé de la réponse d'erreur si vous le souhaitez
$erreur = 'Votre fichier doit faire moins de 2mo !';
// ----------------- Fin configuration --------------------
}
else
{
mail_attachement_html($to, $sujet,$message,$fichier,$typemime,$nomdoc,$reply,$from);
}
}
?>
<p>
<!-- Erreur ? -->
<?php
if(isset($erreur)){
echo '<p>', $erreur ,'</p>';
}
?>
</p>
</body>
</html>[/php][/quote]