Subversion Repositories Applications.annuaire

Compare Revisions

Ignore whitespace Rev 273 → Rev 274

/trunk/controleurs/MessageControleur.php
218,26 → 218,32
 
foreach($destinataires as $destinataire) {
// Définition d'un mail en text simple et html
$entetes .= 'From: '.$expediteur."\r\n";
$entetes .= 'MIME-Version: 1.0' . "\r\n";
$entetes .= "Content-Type: multipart/alternative; boundary=\"".$limite."\";\r\n";
// Définition d'un mail en texte simple et html
$entetes .= "X-Sender: <http://www.tela-botanica.org>\n";
$entetes .= "X-Mailer: PHP\n";
$entetes .= "X-auth-smtp-user: annuaire@tela-botanica.org \n";
$entetes .= "X-abuse-contact: annuaire@tela-botanica.org \n";
$entetes .= "Date: ".date("D, j M Y G:i:s O")."\n";
$entetes .= 'From: '.$expediteur."\n";
// multipart/alternative signifie même contenu de la forme la plus simple à la plus complexe
$entetes .= "Content-Type: multipart/alternative; boundary=\"".$limite."\";\n\n";
$contenu = "";
$contenu .= "\r\n--".$limite."\r\n";
$contenu .= "Content-Type: text/plain;";
$contenu .= "charset=\"".Config::get('appli_encodage')."\";\r\n";
$contenu .= "Content-Transfer-Encoding: quoted-printable;\r\n";
$contenu .= "\r\n";
$contenu .= $message_texte;
// message en texte plein
$contenu .= "--".$limite."\n";
$contenu .= "Content-Type: text/plain; charset=\"".Config::get('appli_encodage')."\";\n";
$contenu .= "Content-Transfer-Encoding: 7bit;\n\n";
$contenu .= $message_texte."\n";
$contenu .= "\r\n--".$limite."\r\n";
// le message en html est préféré s'il est lisible
$contenu .= "--".$limite."\n";
$contenu .= "Content-Type: text/html;";
$contenu .= "charset=\"".Config::get('appli_encodage')."\";\r\n";
$contenu .= "Content-Transfer-Encoding: quoted-printable;\r\n";
$contenu .= "\r\n";
$contenu .= $message_antislashe;
$contenu .= "charset=\"".Config::get('appli_encodage')."\";\n";
$contenu .= "Content-Transfer-Encoding: 7bit;\n\n";
$contenu .= $message_antislashe."\n";
$contenu .= "--".$limite."--\n";
$sujet = $this->encoderChainePourEnvoiMail($sujet);
248,7 → 254,88
return true;
}
public function envoyerMailAvecPieceJointe($expediteur, $destinataires, $sujet, $message, $piece_jointe = null, $nom_fichier, $type_mime = 'text/plain') {
 
if(!is_array($destinataires)) {
$destinataires = array($destinataires);
}
$message_antislashe = $this->encoderChainePourEnvoiMail($message);
$message_texte = $this->filtrerChaine($message);
$message_html = $message_antislashe;
$limite = "_----------=_parties_".md5(uniqid (rand()));
$limite_partie_message = "_----------=_parties_".md5(uniqid (rand() + 1));
 
foreach($destinataires as $destinataire) {
// Définition d'un mail avec différents type de contenu
$entetes .= "X-Sender: <http://www.tela-botanica.org>\n";
$entetes .= "X-Mailer: PHP\n";
$entetes .= "X-auth-smtp-user: annuaire@tela-botanica.org \n";
$entetes .= "X-abuse-contact: annuaire@tela-botanica.org \n";
$entetes .= "Date: ".date("D, j M Y G:i:s O")."\n";
$entetes .= 'From: '.$expediteur."\n";
$entetes .= 'MIME-Version: 1.0' . "\n";
// Définition d'un type de contenu mixed (mail (texte + html) + piece jointe)
$entetes .= "Content-Type: multipart/mixed; boundary=\"".$limite."\";\n\n";
$contenu = "";
// Première sous partie : contenu du mail
$contenu .= "\n--".$limite."\n";
// Définition d'un type de contenu alternatif pour l'envoi en html et texte
$contenu .= "Content-Type: multipart/alternative; boundary=\"".$limite_partie_message."\";\n";
// Version texte
$contenu .= "\n--".$limite_partie_message."\n";
$contenu .= "Content-Type: text/plain;";
$contenu .= "charset=\"".Config::get('appli_encodage')."\";\n";
$contenu .= "Content-Transfer-Encoding: 7bit;\n";
$contenu .= "\n";
$contenu .= $message_texte."\n";
// Version html
$contenu .= "--".$limite_partie_message."\n";
$contenu .= "Content-Type: text/html;";
$contenu .= "charset=\"".Config::get('appli_encodage')."\";\n";
$contenu .= "Content-Transfer-Encoding: 7bit;\n";
$contenu .= "\n";
$contenu .= nl2br($message_antislashe)."\n";
$contenu .= "\n--".$limite_partie_message."--\n";
$contenu .= "--".$limite."\n";
// Seconde sous partie : pièce jointe
if($piece_jointe != null) {
$attachment = chunk_split(base64_encode($piece_jointe));
$contenu .= "Content-Type: ".$type_mime."; name=\"".$nom_fichier."\"\n";
$contenu .= "Content-Transfer-Encoding: base64\n";
$contenu .= "Content-Disposition: attachment; filename=\"".$nom_fichier."\"\n";
$contenu .= "X-Attachment-Id: ".md5($attachment)."\n\n";
$contenu .= $attachment;
$contenu .= "\n--".$limite."--\n";
}
if(!mail('hommecanard@hotmail.com', mb_encode_mimeheader($sujet), $contenu, $entetes)) {
return false;
}
}
return true;
}
 
/**
* Avec des l'informations d'expéditions données en paramètres, décide si un mail peut être envoyé directement
* ou bien s'il doit être stocké et soumis à modération
442,25 → 529,6
 
}
private function envoyerMailAvecPieceJointe($chemin, $type_mime_fichier) {
/* Pièce jointe, on va dire que notre fichier s'appelle bidule.doc et qu'il se situe dans le répertoire courant */
$fichier=file_get_contents($chemin);
/* On utilise aussi chunk_split() qui organisera comme il faut l'encodage fait en base 64 pour se conformer aux standards */
$fichier=chunk_split( base64_encode($fichier) );
//Écriture de la pièce jointe
$body = $body . "--" .$boundary. "\n
Content-Type: application/msword; name=\"nom_fichier\"\r\n
Content-Transfer-Encoding: base64\r\n
Content-Disposition: attachment; filename=\"nom_fichier\"\r\n\n
$fichier";
//Fermeture de la frontière
$body = $body . "--" . $boundary ."--";
}
private function filtrerChaine($message) {
return strip_tags($message);
467,6 → 535,7
}
private function encoderChainePourEnvoiMail($chaine) {
return stripslashes($chaine);
return $chaine;
}
}
?>