source: extensions/Mail_supervisor/include/function_test_send.php @ 4323

Last change on this file since 4323 was 4323, checked in by cljosse, 14 years ago

[mail_supervisor] Improvement of the management of the spammers.

File size: 7.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if ( !defined('PHPWG_ROOT_PATH')) 
25{
26  die('Hacking attempt!');
27}
28
29
30
31function test_envoie($message,$group_name,$group_id)
32{
33    global $infos_message,$erreur_message ,$conf,$user,$conf_mail,$mail_données,$args,$lang ;
34        $mailto=""; 
35       
36 load_language('plugin.lang', MAIL_SUPERV_PATH);
37 
38//==================================================================================
39if (!isset($infos_message))
40        {
41        $infos_message = "";
42        }
43if (!isset($erreur_message))
44        {
45        $erreur_message = '';
46        }
47if (!isset($mails_données))
48        {
49        $mails_données = Get_Datas();
50        }               
51if (!isset($conf_mail))
52  {
53        $conf_mail = get_mail_configuration();
54  }
55          if (isset($args))
56  { 
57    $infos_message=memo_var($args);
58  }else{
59        $args = array();
60        }
61//=====================================================================================================
62
63 
64
65$groups=get_liste($group_id);
66
67 
68//=======================================================================================
69  if (count($groups) > 0)
70  {
71       $args['Bcc']=$groups;
72   }   else {
73       $mailto = $conf_mail['formated_email_webmaster']; 
74   } 
75   
76        $args['from'] = $conf_mail['formated_email_webmaster'];
77       
78      if (function_exists('get_user_language_desc') and isset($message) and $message <> '')
79        $message = get_user_language_desc($message)."\n\n";
80     
81 
82        //==================================================================
83         $message_texte=sprintf(
84        l10n('message_texte %s %s %s %s'),
85        format_date( date("Y-m-d H:i:s")),
86                $group_name,
87                $message,
88                $args['from']
89        );     
90        //==================================================================
91        $message_html = $message_texte;
92
93       
94 //==========================================================================
95
96        $args['subject']="Plugin Piwigo TEST";
97        $args['content']=$message_html;
98                $infos_message .="To :" . $mailto;
99               
100        $ret= pwg_mail($mailto , $args); 
101        if ( $group_name <> '' or $mailto <> '' )
102        {       
103                if ($group_name<>'') {
104                 $infos_message .=  '<br />'.  sprintf( l10n('An information email was sent to group "%s"'), $group_name ).'<br />';
105                        }
106                        if ($mailto <> '') {
107                                $infos_message .=  '<br />'.  sprintf( l10n('mail_sent_to'), $mailto ).'<br />';
108                                }
109                 
110        }else{
111               $infos_message .='<br />'.l10n('no_receiver_available') ;
112        }
113       
114}
115//===============================================================================================================
116function mail_attachement($args)
117{
118 global $infos_message,$erreur_message ,$conf,$user,$conf_mail,$mail_données,$lang ;
119
120    $mails_données = Get_Datas();
121          if (!isset($conf_mail))
122  {
123    $conf_mail = get_mail_configuration();
124  }
125
126 load_language('plugin.lang', MAIL_SUPERV_PATH);
127
128                $nom ='piwigo_logo_sombre_214x100.png'; 
129                $fichier=PHPWG_ROOT_PATH.'admin/template/goto/theme/roma/images/piwigo_logo_sombre_214x100.png' ;
130                $typemime='image/jpeg';
131                               
132                $fd = fopen( $fichier, "r" ); 
133                $contenu = fread( $fd, filesize( $fichier ) ); 
134                fclose( $fd ); 
135                $piecejointe  = chunk_split(base64_encode($contenu)); 
136               
137               
138         $from=$args['from'];
139$to="";
140
141     $message_texte=sprintf(
142        l10n('message_texte %s %s %s'),
143        format_date( date("Y-m-d H:i:s")),
144                $to,
145                $from
146        );     
147               
148 
149        $message_html =         '<img src="'.PHPWG_ROOT_PATH.'admin/template/goto/theme/roma/images/piwigo_logo_sombre_214x100.png" />';
150         ob_start();   
151 
152        echo str_replace("\n","<br />",$message_texte);
153       
154         $message_html .= ob_get_contents()."\n";
155         //ob_flush();
156        ob_end_clean();
157
158       $limite=$conf_mail['boundary_key'];   
159                $headers =   date("Y-m-d H:i:s") ."\n"; 
160
161  //=======================================================================================
162                $headers = "From: ".$args['from']."\n";
163                $headers.= "Reply-To: ".$args['from']."\n";
164                $nb_destinataires=0;
165$destinataire = $conf_mail['email_webmaster'];
166
167 
168                if (!empty($args['Cc']))
169                {$nb_destinataires += count($args['Cc']);
170                 $to= explode(',', $args['Cc']);
171                 $headers       .= get_strict_email_list($to) ;
172                   
173                }
174                if (!empty($args['Bcc']))
175                {  $nb_destinataires += count($args['Bcc']); 
176            $to = implode(',', $args['Bcc']);
177            $headers    .= 'Bcc :'.get_strict_email_list($to)."\n" ;
178                   
179                }
180
181  $headers.= 'Content-Type: multipart/alternative;'."\n";
182  $headers.= '  boundary="---='.$limite.'";'."\n";
183  $headers.= '  reply-type=original'."\n";
184  $headers.= 'MIME-Version: 1.0'."\n";
185  $headers.= 'X-Mailer: Piwigo Mailer'."\n";
186
187  //Le message en texte simple pour les navigateurs qui n'acceptent pas le HTML
188    $texte = "This is a multi-part message in MIME format.\n"; 
189       
190        $texte .= "-----=".$limite."\n"; 
191        $texte .= "Ceci est un message est au format MIME.\n"; 
192        $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; 
193        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
194        $texte .= $message_texte ; 
195                $texte .= "\n\n"; 
196               
197                $texte .= "-----=".$limite."\n"; 
198        $texte .= 'Content-Type: text/html; charset="UTF-8"'."\n"; 
199        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
200        $texte .= $message_html; 
201        $texte .= "\n\n"; 
202         
203
204
205                $attachement = "-----=".$limite."\n"; 
206                $attachement .= "Content-Type: ".$typemime."; name=\"".$nom."\"\n"; 
207                $attachement .= "Content-Transfer-Encoding: base64\n"; 
208                $attachement .= "Content-Disposition: attachment; filename=\"".$nom."\"\n\n"; 
209                $attachement .= $piecejointe; 
210                $attachement .= "\n\n\n-----=".$limite."\n"; 
211
212
213  $ret=false;
214
215ob_start();
216
217    $ret= mail( $destinataire, $args['subject'], $texte.$attachement, $headers); 
218   $message =  ob_get_contents() ;
219        //ob_flush();
220   ob_end_clean();
221   if (($message)<>"") {
222   $erreur_message .=  $message ;
223   $infos_message =  "-------------------";
224   }
225
226   
227    return  $ret;
228 
229}
230
231 
232?>
Note: See TracBrowser for help on using the repository browser.