source: trunk/spip/esqueleto-redcta/plugins/spip-listes_1_9_2/inc/spiplistes_mail.inc.php @ 90

Last change on this file since 90 was 90, checked in by guille, 15 years ago

importacion de spip-listes-1_9_2

File size: 3.8 KB
Line 
1<?php
2
3        include_spip('phpmailer/class.phpmailer');
4        include_spip('phpmailer/class.smtp');
5
6        class phpMail extends PHPMailer {
7
8                function phpMail($email, $objet, $message_html, $message_texte, $charset) {
9               
10                        $fromname = $GLOBALS['meta']['nom_site'];
11
12                        if ($GLOBALS['meta']['spiplistes_charset_envoi']!=$GLOBALS['meta']['charset']){
13                        include_spip('inc/charsets');
14                        $fromname = unicode2charset(charset2unicode($fromname),$GLOBALS['meta']['spiplistes_charset_envoi']);
15                        }
16
17                        $this->FromName    =  $fromname ; 
18                       
19                        $this->CharSet  = $charset ;
20                $this->Mailer   = 'mail';
21                        $this->Subject  = $objet;
22                        $this->AddAddress($email); 
23                       
24                        if ($smtp_sender =  $GLOBALS['meta']['smtp_sender']) {
25                                $this->Sender = $GLOBALS['meta']['spip_lettres_smtp_sender'];
26                        }
27                       
28                        $envoi_par_smtp =  $GLOBALS['meta']['mailer_smtp'] ;
29
30                        if($envoi_par_smtp == "oui"){
31                                if ($smpt_server =  $GLOBALS['meta']['smtp_server']) {
32                                $this->IsSMTP(); // telling the class to use SMTP
33                                $this->Mailer   = 'smtp';
34                                    $this->Host         =  $GLOBALS['meta']['smtp_server'];
35                                    $this->Port         =  $GLOBALS['meta']['smtp_port'];
36                                       
37                                        $smtp_identification =  $GLOBALS['meta']['smtp_identification'] ;
38
39                                        if ($smtp_identification == "oui") {
40                                            $this->SMTPAuth = true;
41                                            $this->Username =  $GLOBALS['meta']['smtp_login'];
42                                            $this->Password =  $GLOBALS['meta']['smtp_pass'];
43                                        } else {
44                                            $this->SMTPAuth = false;
45                                        }
46                                }
47                        }
48                        if (!empty($message_html) AND !empty($message_texte)) {
49                        $this->Body = $message_html;
50                        $this->AltBody = $message_texte;
51                                //$this->spiplistes_JoindreImagesHTML();
52                        }
53                        if (!empty($message_texte) AND empty($message_html)) {
54                               
55                                        $this->IsHTML(false);
56                                        $this->Body = $message_texte;
57                               
58                        }
59                }
60                function SetAddress($address, $name = "") {
61                        $this->to=array();
62                        $this->AddAddress($address,$name);
63                }       
64
65        /**
66         * d'apres SPIP-Lettres : plugin de gestion de lettres d'information
67         * inutilisé mais ca pourra peut etre servir pour emabarquer les images
68         * Copyright (c) 2006
69         * Agence Atypik Creations
70         * 
71         * 
72         **/
73
74                function spiplistes_JoindreImagesHTML() {
75                        $image_types = array(
76                                                                'gif'   => 'image/gif',
77                                                                'jpg'   => 'image/jpeg',
78                                                                'jpeg'  => 'image/jpeg',
79                                                                'jpe'   => 'image/jpeg',
80                                                                'bmp'   => 'image/bmp',
81                                                                'png'   => 'image/png',
82                                                                'tif'   => 'image/tiff',
83                                                                'tiff'  => 'image/tiff',
84                                                                'swf'   => 'application/x-shockwave-flash'
85                                                        );
86                        while (list($key,) = each($image_types))
87                                $extensions[] = $key;
88
89                        preg_match_all('/"([^"]+\.('.implode('|', $extensions).'))"/Ui', $this->Body, $images);
90
91                        for ($i=0; $i<count($images[1]); $i++) {
92                                if (file_exists('../'.$images[1][$i])) {
93                                        $html_images[] = '../'.$images[1][$i];
94                                        $this->Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
95                                }
96                                if (file_exists($images[1][$i])) {
97                                        $html_images[] = $images[1][$i];
98                                        $this->Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
99                                }
100                        }
101
102                        $images = array();
103                        preg_match_all("/'([^']+\.(".implode('|', $extensions)."))'/Ui", $this->Body, $images);
104
105                        for ($i=0; $i<count($images[1]); $i++) {
106                                if (file_exists('../'.$images[1][$i])) {
107                                        $html_images[] = '../'.$images[1][$i];
108                                        $this->Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
109                                }
110                                if (file_exists($images[1][$i])) {
111                                        $html_images[] = $images[1][$i];
112                                        $this->Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
113                                }
114                        }
115
116                        if (!empty($html_images)) {
117                                $html_images = array_unique($html_images);
118                                sort($html_images);
119                                for ($i=0; $i<count($html_images); $i++) {
120                                        $cid = md5(uniqid(time()));
121                                        $this->AddEmbeddedImage($html_images[$i], $cid);
122                                        $this->Body = str_replace(basename($html_images[$i]), "cid:$cid", $this->Body);
123                                }
124                        }
125                }
126
127        }
128
129?>
Note: See TracBrowser for help on using the repository browser.