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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
<?php
error_reporting(E_ALL); ini_set("display_errors", 1); //Display errors
echo "<br>"; echo "<br>";
$code_site = "MPSHF";
echo " <h4> <input type=button style='font-size:100%; color:black;' onclick=window.location.href='Menu_Principal.php'; value=' Retour au Site choisi ' /></h4>";
echo "<br>";
// include_once ("fonctions.php"); dump_post();
// echo " On récupère le fichier (ou le array des fichiers) à envoyer : ";
// $nb_fic = count($_FILES['files']);
// echo "nb_fic (ou nbre de champs du array) = ".$nb_fic; echo "<br>";
// echo '<pre>';
// print_r($_FILES);
// echo '</pre>';
// echo "<br>";
if (get_magic_quotes_gpc()){
$nom = stripslashes(htmlentities($_POST['nom']));
$email_from = stripslashes(htmlentities($_POST['email']));
$message = stripslashes(htmlentities($_POST['message']));
}else{
//Eviter les insertions de scripts dans le cas d'un e-mail HTML
$nom = htmlentities($_POST['nom']);
$email_from = htmlentities($_POST['email']);
$message = htmlentities($_POST['message']);
}
// Check if mail host allow \r
if(preg_match("#@(hotmail|live|msn).[a-z]{2,4}$#", $email_from)) { $passage_ligne = "\n"; }else{ $passage_ligne = "\r\n"; }
$email_to = "michel.aubi85@gmail.com"; // yourmail@gmail.com"; //Recipient
$email_subject = "Mail avec (une ou des) PJ (peut-être !)"; // Contact for you"; //Subject
$boundary = md5(rand()); // Random boundary key
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$headers = "From: \"".$nom."\"<".$email_from.">" . $passage_ligne; //Sender
$headers.= "Reply-to: \"".$nom."\" <".$email_from.">" . $passage_ligne; //Sender
$headers.= "MIME-Version: 1.0" . $passage_ligne; //MIME Version
$headers.= 'Content-Type: multipart/mixed; boundary='.$boundary .' '. $passage_ligne; //Content (2 versions ex:text/plain et text/html et aussi des PJ )
$email_message = '--' . $boundary . $passage_ligne; //Opening boundary
$email_message .= "Content-Type: text/plain; charset=\"utf-8\"" . $passage_ligne; //Content type
$email_message .= "Content-Transfer-Encoding: 8bit" . $passage_ligne; //Encoding
$email_message .= $passage_ligne .clean_string($message). $passage_ligne; //Content
// Attachment du (ou des) fichier(s) à joindre
if(isset($_FILES["files"]) && $_FILES['files']['name'] != "") { // Check if file exists (array ou un seul fichier)
echo 'En 74, Dans ATTACHEMENT : Informations sur le(s) fichier(s) à attacher au mail :'; echo "<br>";
echo '<pre>';
print_r($_FILES);
echo '</pre>';
$nom_fichier = $_FILES['files']['name']; // NOM du fichier
// $nom_fichier = $uploadfile;
$source = $_FILES['files']['tmp_name']; // Répertoire tmp
$type_fichier = $_FILES['files']['type']; // echo "Type_fichier : ".$type_fichier; echo "<br>"; echo "<br>";
$taille_fichier = $_FILES['files']['size']; // Taille du fichier
if($nom_fichier != ".htaccess"){ // Check if it's not a .htaccess file
if($type_fichier == "image/jpeg" || $type_fichier == "image/jpg" || $type_fichier == "application/pdf"){ // Soit jpeg or pdf
if ($taille_fichier > 0 and $taille_fichier < 2000000) { // Taille est bien comprise entre 0 et 2mb maxi
$tabRemplacement = array("é"=>"e", "è"=>"e", "à"=>"a"); // Changing special characters
echo "Fichier en cours d'expédition : ".$source; echo "<br>"; // exit;
$handle = fopen($source, 'r'); // Ouverture du fichier
$content = fread($handle, $taille_fichier); // lecture du fichier
$encoded_content = chunk_split(base64_encode($content)); // Découpage
$f = fclose($handle); // Fermeture du fichier
$email_message .= $passage_ligne . "--" . $boundary . $passage_ligne; // Second boundary opening
$email_message .= 'Content-type:'.$type_fichier.';name="'.$nom_fichier.'"'."\n"; // Content type (application/pdf or image/jpeg)
$email_message .= 'Content-Disposition: attachment; filename="'.$nom_fichier.'"'."\n"; // Inform there is an attachment
$email_message .= 'Content-transfer-encoding:base64'."\n"; // Encoding
$email_message .= "\n"; // Blank line. IMPORTANT !
$email_message .= $encoded_content."\n"; // Attachment
}else{
$email_message .= $passage_ligne ."On a tenté de vous envoyer une PJ (".$nom_fichier.") mais sa taille (".$taille_fichier.") était trop élevée (2Mb maxi).". $passage_ligne;
}
}else{
$email_message .= $passage_ligne ."On a tenté de vous envoyer une pièce jointe avec un format non autorisé (".$type_fichier.").". $passage_ligne;
}
}else{
$email_message .= $passage_ligne ."On a tenté de vous envoyer une pièce jointe au format prohibé .htaccess.". $passage_ligne;
}
}
$email_message .= $passage_ligne . "--" . $boundary . "--" . $passage_ligne; //Closing boundary
// echo "<br>"; echo " Voici le message complet, prêt à partir : "; echo "<br>"; echo "".$email_message; echo "<br>"; echo "<br>"; echo "<br>"; exit;
if(mail($email_to,$email_subject, $email_message, $headers) == true) { //Sending mail
echo "<h3> Le message avec (UNE) pj est bien parti !!! </h3> ";
echo "<br>";
echo " <h3> <input type=button style='font-size:100%; color:black;' onclick=window.location.href='PHP_Mailer_Form.php'; value=' Retour pour un Nouvel email ' /> </h3>";
exit;
}else{
echo "<br>";echo "<br>";
echo "Le message n'a pas été envoyé !!!";
echo "<br>";echo "<br>";
echo " <h3> <input type=button style='font-size:100%; color:black;' onclick=window.location.href='PHP_Mailer_Form.php'; value=' Retour pour un Nouvel email ' /> </h3>";
exit;
}
?> |
Partager