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
|
protected $envoiCarte;
protected $mime;
// En-têtes du message
protected $hdrs;
public function __construct($envoiCarte) {
$this->envoiCarte = $envoiCarte;
$this->hdrs = array(
'From' => $envoiCarte->getFrom(),
'Subject' => $envoiCarte->getSujet(),
'Content-Transfer-Encoding' => '8bit');
// CRÉATION D'UN OBJET Mail_mime
$this->mime = new Mail_mime("\r\n");
}
public function envoiHTML() {
$urlCarte = ENTREPOT_FILE."cartes/".$this->envoiCarte->getIdCarte().".png";
// CRÉATION DES DONNÉES DU MESSAGE
// Corps du message au format HTML, incluant une image
$html = "<html><head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"> </head><body>";
$html .= $this->envoiCarte->getMessage();
$html.= "</body></html>";
// mettre le contenu du message en texte et HTML
$this->mime->setHTMLBody($html);
// ajouter la pièce jointe
$this->mime->addAttachment($urlCarte, 'image/png', 'carte.png', true, 'base64');
//ajouter la gestion des accents
$mimeparams=array();
$mimeparams['text_encoding']="8bit";
$mimeparams['text_charset']="UTF-8";
$mimeparams['html_charset']="UTF-8";
$mimeparams['Content-Type'] = 'text/html; charset="UTF-8"';
$mimeparams['head_charset']="UTF-8";
// ENVOI DU MESSAGE
$body = $this->mime->get($mimeparams);
$hdrs = $this->mime->headers($this->hdrs);
$mail=& Mail::factory('mail');
/* envoyer le message à tous les destinataires */
$tab = explode(",", $this->envoiCarte->getTo());
foreach ($tab as $to) {
//supprimer les espaces résiduels avant et après une adresse mail
$to = str_replace(CHR(32),"",$to);
$mail->send($to, $hdrs,$body);
} |
Partager