13 pers. connectées au site
Wall posté le Mercredi 27 février 2008
...
- <?php
-
-
-
-
-
- function encodeHeader($input) {
- return mb_encode_mimeheader($input, "UTF-8", "B");
- }
-
- function decodeHeader($header) {
- return mb_decode_mimeheader($header);
- }
-
- function decodeSubject($string) {
-
- $elements = imap_mime_header_decode($string);
-
- $out = '';
- for($i=0; $i<count($elements); $i++) {
- if ($elements[$i]->charset == 'default' || $elements[$i]->charset == 'UNKNOWN') {
- $out .= $elements[$i]->text;
- }
- else {
- $out .= iconv($elements[$i]->charset, 'UTF-8//TRANSLIT', $elements[$i]->text);
- }
- }
-
- return $out;
- }
-
- function decodeBodyMail ($body, $charset) {
- restore_error_handler();
- error_reporting(0);
-
- if ($charset == NULL) {
- if ($body != @iconv("ISO-8859-15", "UTF-8//TRANSLIT", $body)) $body = @iconv("ISO-8859-15", "UTF-8//IGNORE", $body);
- else $body = @iconv("ISO-8859-15", "UTF-8//TRANSLIT", $body);
- }
- else {
- if ($body != @iconv($charset, "UTF-8//TRANSLIT", $body)) $body = @iconv($charset, "UTF-8//IGNORE", $body);
- else $body = @iconv($charset, "UTF-8//TRANSLIT", $body);
-
- }
-
- $error_handler = set_error_handler("userErrorHandler");
-
- return $body;
- }
-
-
-
-
-
- function clean_input ($string) {
- $string = str_replace("\r", '', $string);
- $string = str_replace("\n", '', $string);
- $string = str_replace('"', '', $string);
- $string = str_replace("\x03", '', $string);
-
- return $string;
- }
-
- class send_mail {
-
- var $headers = '';
- var $importance = false;
- var $subject = null;
-
- var $from = '';
- var $Tfrom = array();
- var $reply_to = '';
- var $Treply_to = array();
- var $to = '';
- var $Tto = array();
- var $cc = '';
- var $Tcc = array();
- var $cci = '';
- var $Tcci = array();
-
- var $body = false;
- var $files = array();
- var $size = 0;
- var $error = array();
-
- function send_mail () {
- return true;
- }
-
- function addSubject ($sujet) {
- if (strlen($sujet)>255) {
- $this->error[] = 'Le sujet du mail fait plus que 255 caractères';
- return false;
- }
-
- $this->subject = $sujet;
-
- return true;
- }
-
- function addFrom ($from) {
- $from = clean_input($from);
- $temp_from = $from;
-
-
- $from = internet_address_parse_string($from);
-
- if (!$from || $from->diff > 0) {
- $this->error[] = 'L\'adresse du champ FROM est invalide';
- return false;
- }
-
- if (strlen($from->addrlist[0]['name']) == 0) {
- $this->from = $from->addrlist[0]['addr'];
- }
- else {
- $this->from = encodeHeader($from->addrlist[0]['name']).' <'.$from->addrlist[0]['addr'].'>';
- }
-
- $this->Tfrom[] = array('name' => str_replace('"', ' ', $from->addrlist[0]['name']), 'addr' => $from->addrlist[0]['addr']);
-
- return true;
- }
-
- function addReplyTo ($reply_to) {
- $reply_to = clean_input($reply_to);
- $temp_reply_to = $reply_to;
-
-
- $reply_to = internet_address_parse_string($reply_to);
-
- if (!$reply_to || $reply_to->diff > 0) {
- $this->error[] = 'L\'adresse du champ REPLYTO est invalide';
- return false;
- }
-
- if (strlen($reply_to->addrlist[0]['name']) == 0) {
- $this->reply_to = $reply_to->addrlist[0]['addr'];
- }
- else {
- $this->reply_to = encodeHeader($reply_to->addrlist[0]['name']).' <'.$reply_to->addrlist[0]['addr'].'>';
- }
-
-
- $this->Treply_to[] = array('name' => $reply_to->addrlist[0]['name'], 'addr' => $reply_to->addrlist[0]['addr']);
- return true;
- }
-
- function addTo ($to, $qui = 'to') {
- $to = clean_input($to);
- $temp_to = $to;
-
- if (strlen($temp_to)>0) {
- $to = internet_address_parse_string($to);
-
- switch ($qui) {
- case 'to':
- if (!$to || $to->diff > 0) {
- $this->error[] = 'L\'adresse du champ TO est invalide';
- return false;
- }
- if (isset($to->addrlist) && is_array($to->addrlist)) {
- foreach ($to->addrlist AS $email) {
- if (strlen($email['name']) == 0) {
- $this->to = $this->to.$email['addr'].', ';
- }
- else {
- $this->to = $this->to.encodeHeader($email['name']).' <'.$email['addr'].'>, ';
- }
-
- $this->Tto[] = array('name' => $email['name'], 'addr' => $email['addr']);
- }
- }
- break;
-
- case 'cc':
- if (!$to || $to->diff > 0) {
- $this->error[] = 'L\'adresse du champ CC est invalide';
- return false;
- }
- if (isset($to->addrlist) && is_array($to->addrlist)) {
- foreach ($to->addrlist AS $email) {
- if (strlen($email['name']) == 0) {
- $this->cc = $this->cc.$email['addr'].', ';
- }
- else {
- $this->cc = $this->cc.encodeHeader($email['name']).' <'.$email['addr'].'>, ';
- }
-
- $this->Tcc[] = array('name' => $email['name'], 'addr' => $email['addr']);
- }
- }
- break;
-
- case 'cci':
- if (!$to || $to->diff > 0) {
- $this->error[] = 'L\'adresse du champ CCI est invalide';
- return false;
- }
- if (isset($to->addrlist) && is_array($to->addrlist)) {
- foreach ($to->addrlist AS $email) {
- if (strlen($email['name']) == 0) {
- $this->cci = $this->cci.$email['addr'].', ';
- }
- else {
- $this->cci = $this->cci.encodeHeader($email['name']).' <'.$email['addr'].'>, ';
- }
-
- $this->Tcci[] = array('name' => $email['name'], 'addr' => $email['addr']);
- }
- }
- break;
- }
- }
-
- return true;
- }
-
- function addContent($content, $type) {
-
- if ($type == 'text') {
- $this->text = $content;
- }
- elseif ($type == 'html') {
- $this->html = $content;
- }
- else {
- $this->error[] = 'Le contenu du mail n\'est ni du texte ni de l\'html';
- return false;
- }
- return true;
-
- }
-
- function addFile ($nom, $size, $type, $data, $cid = '') {
- $tmp = (object) NULL;
- $tmp->nom = encodeHeader($nom);
- $tmp->size = $size;
- $tmp->type = $type;
- $tmp->file = $data;
- $tmp->cid = $cid;
-
- if ($cid != '') $this->inline = true;
- else $this->attachments = true;
-
- $this->files[] = $tmp;
- }
-
- function boundary () {
- return '--------------'.md5(microtime()*mt_rand(0, 999));
- }
-
- function importance ($imp = 'Normal') {
- if (!( ($imp=='Normal') || ($imp=='High') || ($imp=='Low') )) $imp = 'Normal';
- if ($imp=="Normal") $this->importance = "X-Priority: 3 (Normal)\nImportance: " . $imp;
- if ($imp=="High") $this->importance = "X-Priority: 1 (Highest)\nImportance: " . $imp;
- if ($imp=="Low") $this->importance = "X-Priority: 5 (Lowest)\nImportance: " . $imp;
-
- return true;
- }
-
- function headers () {
- $this->headers .= "User-Agent: Le PHP Facile Mailer\n";
-
- return true;
- }
-
- function checkIntegrityMail() {
- if (count($this->error) == 0) {
- if (count($this->Tcci) == 0 && count($this->Tcc) == 0 && count($this->Tto) == 0) {
- $this->error[] = 'Le mail ne contient aucun destinataire';
- return false;
- }
- }
- return true;
- }
-
- function build_mail () {
- $ret = false;
-
- $this->importance();
- $this->headers();
-
- if ( ($this->importance != '') && (strlen($this->from)>0) ) {
-
-
- $this->body .= $this->headers;
-
- $this->body .= $this->importance . "\n";
-
- $this->body .= "Date: ".date('r', time())."\n";
-
- $this->body .= "From: " . $this->from . "\n";
-
-
- if (strlen($this->to)>0) {
- $this->body .= "To: ".substr($this->to, 0, -2)."\n";
- }
-
- if (strlen($this->cc)>0) {
- $this->body .= "Cc: ".substr($this->cc, 0, -2)."\n";
- }
-
- if (strlen($this->cci)>0) {
- $this->body .= "Bcc: ".substr($this->cci, 0, -2)."\n";
- }
-
- if (strlen($this->reply_to) != 0) {
- $this->body .= "Reply-To: " . $this->reply_to . "\n";
- }
-
- if (strlen($this->subject)>0) $this->body .= 'Subject: '.encodeHeader($this->subject) ."\n";
- else $this->body .= "";