Bonsoir, j'essaie de mettre au point un formulaire qui permettrait d'envoyer un mail avec une pièce attachée, mais j'obtiens un warning.
Pouvez-vous m'aider ?
Formulaire :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <font face="Arial">
<form method="post" action="upload.php"
enctype="multipart/form-data">
<h3 align="center"> Envoi de mail</h3>
Nom : <input name=" nom" size="30" type="texte">
Prénom : <input name="prenom" size="40"
type="texte"> E-mail : <input name="E-mail"
size="50" type="texte"> <br>
<br>
Votre message : <textarea name="msg" rows="6"
cols="70" a=""></textarea> <br>
<br>
Fichier attaché : <input name="MAX_FILE_SIZE"
value="3100000" type="hidden"> <input name="file"
type="file"><br>
<br>
<input value="Envoyer" type="submit"><input
value="Annuler" type="reset"></form>
</font> |
Action (upload.php) :
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
| <?php
$nom=$_POST['nom'];
$prenom=$_POST['prenom'];
$msg=$_POST['msg'];
if (($nom=="")||($prenom=="")||($msg=="")) echo "Il manque quelque chose...";
else {
$msg=str_replace(array("\r", "\n"), array('', '<br>'), $msg);
echo "Le texte est :".$msg."<br>";
$chemin_destination = 'upload/';
move_uploaded_file($_FILES['file']['tmp_name'], $chemin_destination.$_FILES['file']['name']);
$adr_file=$chemin_destination.$_FILES['file']['name'];
//-----------------------------------------------
//DECLARE LES VARIABLES
//-----------------------------------------------
$email_expediteur='---';
$email_reply='---';
$destinataire='---';
$message="test";
//-----------------------------------------------
//HEADERS DU MAIL
//-----------------------------------------------
$headers = 'From: "Nom" <'.$email_expediteur.'>'."\n";
$headers .= 'Return-Path: <'.$email_reply.'>'."\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-Type: multipart/mixed; boundary="'.$frontiere.'"';
$message .= '--'.$frontiere.'--'."\n";
//-----------------------------------------------
//PIECE JOINTE
//-----------------------------------------------
$message .= 'Content-Type: image/jpeg; name='.$adr_file."\n";
$message .= 'Content-Transfer-Encoding: base64'."\n";
$message .= 'Content-Disposition:attachement; filename='.$adr_file."\n\n";
$message .= chunk_split(base64_encode(file_get_contents($adr_file)))."\n";
if(mail($destinataire,"test",$message,$headers))
{
echo 'Le mail a été envoyé';
}
else
{
echo 'Le mail n\'a pu être envoyé';
}
}
?> |
Pour cet upload avec pièce attachée, j'ai pris un code trouvé sur ce forum.
Warning :
Warning: mail() [function.mail]: Spam detecte, mail non envoye. in /mnt/163/sda/2/6/laurentschmitt18/mail/upload.php on line 44
Partager