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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| <?php
Require_once('phpmailer/class.phpmailer.php');
$maxfiles = 3;
$maxsize = 2000000;
$from_adr = 'expediteur@free.fr';
$to_adr = 'destinataire@hotmail.com';
$subject = 'Envoi de pièces jointes locales';
//============================================================
if(isset($_POST['valider'])){
// Test du nombre de fichier //
$nbr=0;
for($x=0;$x<$maxfiles;$x++)
if(!empty($_FILES['userfile']['name'][$x])) $nbr++;
if($nbr<=0) die("Aucun fichier spécifié !<br/>");
// Création du mail //
$mail = New PHPmailer();
$mail->IsHTML(true);
$mail->IsMail();
$mail->IsSMTP();
$mail->Host='smtp.free.fr';
$mail->From=$from_adr;
$mail->AddAddress($to_adr);
$mail->AddReplyTo($from_adr);
$mail->Subject=$subject;
$mail->Body='<html><body>Les fichiers sont attachés ci-dessus... <br></body></html>';
$sendok=false;
// Téléchargement des fichiers //
for($x=1;$x<=$maxfiles;$x++) {
$errorhttp=$_FILES['userfile']['error'][$x-1];
$filenamehttp=$FILES['userfile']['name'][$x-1];
$typehttp=$FILES['userfile']['type'][$x-1];
$sizehttp=$FILES['userfile']['size'][$x-1];
$tmpfilehttp=$FILES['userfile']['tmp_name'][$x-1];
if (($errorhttp)and(!empty($filenamehttp))) {
switch ($errorhttp){
case 1: echo "Erreur : Le fichier n°$x est trop grand !<br/>";break;
case 2: echo "Erreur : Le fichier n°$x est trop grand !<br/>";break;
case 3: echo "Erreur : Transfert du fichier n°$x interrompu !<br/>";break;
case 4: echo "Erreur : Le fichier n°$x est vide !<br/>";break;
}
} else {
if((!empty($filenamehttp))and($sizehttp>0)) {
if($sizehttp<=$maxsize){
if(@is_uploaded_file($tmpfilehttp)) {
if(@eregi('.php',$filenamehttp)) $filenamehttp.='.txt';
if(filesize($tmpfilehttp)==$sizehttp) {
echo "Fichier n°$x uploadé : ".$filenamehttp.
" (".round(max($sizehttp,1024)/1024)." ko)<br/>";
$mail->AddAttachment($tmpfilehttp,$filenamehttp,'Base64');
$sendok=true;
} else echo "Erreur de téléchargement du fichier n°$x !<br/>";
} else echo "Erreur de téléchargement du fichier n°$x !<br/>";
} else echo "Erreur : Le fichier n°$x est trop grand !<br/>";
} // else echo "Le fichier n°$x est introuvable ou vide !<br/>";
}
}
// Envoi du mail //
if($sendok){
if(!$mail->Send()) echo $mail->ErrorInfo."<br/>";
else echo "Mail envoyé à «".$to_adr."»<br/>";
} else echo "Aucun fichier à attacher !<br/>";
// Libération de l'objet //
$mail->SmtpClose();
unset($mail);
die ("Opération terminée.<br/>");
}
//============================================================
echo '<form method="post" enctype="multipart/form-data"'.
' onSubmit="document.getElementById(\'valider\').style.visibility=\'hidden\';">'.
'<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxsize.'"/>';
for($x=1;$x<=max($maxfiles,1);$x++)
echo ' Fichier n°'.$x.' : <input type="file" name="userfile[]" size="20"/><br/>';
echo '<br/><input type="submit" name="valider" id="valider" value="Envoyer..."/></form>';
//============================================================
?> |
Partager