Dragonfly CMS logo Server sponsored and hosted by
DedicatedNOW
CVS logo  
.:: Home :: Dev. Resources :: Forums ::.
Dragonfly CMS CVS Repository
 Location: / cvs / html / includes / classes / phpmailer.php
This is a web interface to the Dragonfly CMS CVS tree. You can browse the file hierarchy by picking directories. If you pick a file, you will see the revision history for that file.
Selecting a revision number will show that revision of the file. There are links at each revision to display diffs, annotate and download.
Note: Info about CVS and our commits can be found at our CVS Info Forum
File name: html/includes/classes/phpmailer.php
Revision : 10.3 (2 years 1 weeks 3 days 20 hours 31 minutes 6 seconds ago) by nanocaiordo
Changed : +3 -3 lines
Comment: 10.0.9.29


# Author Rev Line
1 djmaze 1.1 <?php
2 djmaze 1.1 ////////////////////////////////////////////////////
3 djmaze 1.1 // PHPMailer - PHP email class
4 djmaze 1.1 //
5 djmaze 1.1 // Class for sending email using either
6 djmaze 1.1 // sendmail, PHP mail(), or SMTP. Methods are
7 djmaze 1.1 // based upon the standard AspEmail(tm) classes.
8 djmaze 1.1 //
9 djmaze 1.1 // Copyright (C) 2001 - 2003 Brent R. Matzelle
10 djmaze 1.1 //
11 akamu 8.2 // License: LGPL, see cvs/documentation/LGPL.txt
12 djmaze 1.1 ////////////////////////////////////////////////////
13 djmaze 1.1  
14 djmaze 1.1 /**
15 djmaze 1.1 * PHPMailer - PHP email transport class
16 djmaze 1.1 * @package PHPMailer
17 djmaze 1.1 * @author Brent R. Matzelle
18 djmaze 1.1 * @copyright 2001 - 2003 Brent R. Matzelle
19 akamu 8.2 $Source: /cvs/html/includes/classes/phpmailer.php,v $
20 nanocaio 10.3 $Revision: 10.2 $
21 nanocaio 10.2 $Author: nanocaiordo $
22 nanocaio 10.3 $Date: 2012/01/21 12:52:59 $
23 akamu 8.1 */
24 djmaze 1.1  
25 trevor 8.5 if (!defined('CPG_NUKE')) { exit; }
26 djmaze 1.1  
27 djmaze 1.1 class PHPMailer
28 djmaze 1.1 {
29 djmaze 9.3 /////////////////////////////////////////////////
30 djmaze 9.3 // PUBLIC VARIABLES
31 djmaze 9.3 /////////////////////////////////////////////////
32 djmaze 9.3  
33 djmaze 9.3 /**
34 djmaze 9.3 * Email priority (1 = High, 3 = Normal, 5 = low).
35 djmaze 9.3 * @var int
36 djmaze 9.3 */
37 djmaze 9.3 var $Priority = 3;
38 djmaze 9.3  
39 djmaze 9.3 /**
40 djmaze 9.3 * Sets the CharSet of the message.
41 djmaze 9.3 * @var string
42 djmaze 9.3 */
43 djmaze 9.3 //var $CharSet = "iso-8859-1";
44 nanocaio 9.8 var $CharSet = 'utf-8';
45 djmaze 9.3 /**
46 djmaze 9.3 * Sets the Content-type of the message.
47 djmaze 9.3 * @var string
48 djmaze 9.3 */
49 djmaze 9.3 var $ContentType = 'text/plain';
50 djmaze 9.3  
51 djmaze 9.3 /**
52 djmaze 9.3 * Sets the Encoding of the message. Options for this are "8bit",
53 djmaze 9.3 * "7bit", "binary", "base64", and "quoted-printable".
54 djmaze 9.3 * @var string
55 djmaze 9.3 */
56 djmaze 9.3 var $Encoding = '8bit';
57 djmaze 9.3  
58 djmaze 9.3 /**
59 djmaze 9.3 * Holds the most recent mailer error message.
60 djmaze 9.3 * @var string
61 djmaze 9.3 */
62 djmaze 9.3 var $ErrorInfo = '';
63 djmaze 9.3  
64 djmaze 9.3 /**
65 djmaze 9.3 * Sets the From email address for the message.
66 djmaze 9.3 * @var string
67 djmaze 9.3 */
68 djmaze 9.3 var $From = 'root@localhost';
69 djmaze 9.3  
70 djmaze 9.3 /**
71 djmaze 9.3 * Sets the From name of the message.
72 djmaze 9.3 * @var string
73 djmaze 9.3 */
74 djmaze 9.3 var $FromName = 'Root User';
75 djmaze 9.3  
76 djmaze 9.3 /**
77 djmaze 9.3 * Sets the Sender email (Return-Path) of the message. If not empty,
78 djmaze 9.3 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
79 djmaze 9.3 * @var string
80 djmaze 9.3 */
81 djmaze 9.3 var $Sender = '';
82 djmaze 9.3  
83 djmaze 9.3 /**
84 djmaze 9.3 * Sets the Subject of the message.
85 djmaze 9.3 * @var string
86 djmaze 9.3 */
87 djmaze 9.3 var $Subject = '';
88 djmaze 9.3  
89 djmaze 9.3 /**
90 djmaze 9.3 * Sets the Body of the message. This can be either an HTML or text body.
91 djmaze 9.3 * If HTML then run IsHTML(true).
92 djmaze 9.3 * @var string
93 djmaze 9.3 */
94 djmaze 9.3 var $Body = '';
95 djmaze 9.3  
96 djmaze 9.3 /**
97 djmaze 9.3 * Sets the text-only body of the message. This automatically sets the
98 djmaze 9.3 * email to multipart/alternative. This body can be read by mail
99 djmaze 9.3 * clients that do not have HTML email capability such as mutt. Clients
100 djmaze 9.3 * that can read HTML will view the normal Body.
101 djmaze 9.3 * @var string
102 djmaze 9.3 */
103 djmaze 9.3 var $AltBody = '';
104 djmaze 9.3  
105 djmaze 9.3 /**
106 nanocaio 9.9 * Sets word wrapping on the body of the message to a given number of
107 djmaze 9.3 * characters.
108 djmaze 9.3 * @var int
109 djmaze 9.3 */
110 djmaze 9.3 var $WordWrap = 0;
111 djmaze 9.3  
112 djmaze 9.3 /**
113 djmaze 9.3 * Method to send mail: ("mail", "sendmail", or "smtp").
114 djmaze 9.3 * @var string
115 djmaze 9.3 */
116 djmaze 9.3 var $Mailer = 'mail';
117 djmaze 9.3  
118 djmaze 9.3 /**
119 djmaze 9.3 * Sets the path of the sendmail program.
120 djmaze 9.3 * @var string
121 djmaze 9.3 */
122 djmaze 9.3 var $Sendmail = '/usr/sbin/sendmail';
123 nanocaio 9.9  
124 djmaze 9.3 /**
125 djmaze 9.3 * Holds PHPMailer version.
126 djmaze 9.3 * @var string
127 djmaze 9.3 */
128 djmaze 9.7 var $Version = '1.73';
129 djmaze 9.3  
130 djmaze 9.3 /**
131 djmaze 9.3 * Sets the email address that a reading confirmation will be sent.
132 djmaze 9.3 * @var string
133 djmaze 9.3 */
134 djmaze 9.3 var $ConfirmReadingTo = '';
135 djmaze 9.3  
136 djmaze 9.3 /**
137 djmaze 9.3 * Sets the hostname to use in Message-Id and Received headers
138 djmaze 9.3 * and as default HELO string. If empty, the value returned
139 djmaze 9.3 * by SERVER_NAME is used or 'localhost.localdomain'.
140 djmaze 9.3 * @var string
141 djmaze 9.3 */
142 djmaze 9.3 var $Hostname = '';
143 djmaze 9.3  
144 djmaze 9.3  
145 djmaze 9.3 /////////////////////////////////////////////////
146 djmaze 9.3 // SMTP VARIABLES
147 djmaze 9.3 /////////////////////////////////////////////////
148 djmaze 9.3  
149 djmaze 9.3 /**
150 djmaze 9.3 * Sets the SMTP hosts. All hosts must be separated by a
151 djmaze 9.3 * semicolon. You can also specify a different port
152 djmaze 9.3 * for each host by using this format: [hostname:port]
153 djmaze 9.3 * (e.g. "smtp1.example.com:25;smtp2.example.com").
154 djmaze 9.3 * Hosts will be tried in order.
155 djmaze 9.3 * @var string
156 djmaze 9.3 */
157 djmaze 9.3 var $Host = 'localhost';
158 djmaze 9.3  
159 djmaze 9.3 /**
160 djmaze 9.3 * Sets the default SMTP server port.
161 djmaze 9.3 * @var int
162 djmaze 9.3 */
163 djmaze 9.3 var $Port = 25;
164 djmaze 9.3  
165 djmaze 9.3 /**
166 djmaze 9.3 * Sets the SMTP HELO of the message (Default is $Hostname).
167 djmaze 9.3 * @var string
168 djmaze 9.3 */
169 djmaze 9.3 var $Helo = '';
170 djmaze 9.3  
171 djmaze 9.3 /**
172 djmaze 9.3 * Sets SMTP authentication. Utilizes the Username and Password variables.
173 djmaze 9.3 * @var bool
174 djmaze 9.3 */
175 djmaze 9.3 var $SMTPAuth = false;
176 djmaze 9.3  
177 djmaze 9.3 /**
178 djmaze 9.3 * Sets SMTP username.
179 djmaze 9.3 * @var string
180 djmaze 9.3 */
181 djmaze 9.3 var $Username = '';
182 djmaze 9.3  
183 djmaze 9.3 /**
184 djmaze 9.3 * Sets SMTP password.
185 djmaze 9.3 * @var string
186 djmaze 9.3 */
187 djmaze 9.3 var $Password = '';
188 djmaze 9.3  
189 djmaze 9.3 /**
190 nanocaio 9.9 * Sets the SMTP server timeout in seconds. This function will not
191 djmaze 9.3 * work with the win32 version.
192 djmaze 9.3 * @var int
193 djmaze 9.3 */
194 djmaze 9.3 var $Timeout = 10;
195 djmaze 9.3  
196 djmaze 9.3 /**
197 djmaze 9.3 * Sets SMTP class debugging on or off.
198 djmaze 9.3 * @var bool
199 djmaze 9.3 */
200 djmaze 9.3 var $SMTPDebug = false;
201 djmaze 9.3  
202 djmaze 9.3 /**
203 nanocaio 9.9 * Prevents the SMTP connection from being closed after each mail
204 nanocaio 9.9 * sending. If this is set to true then to close the connection
205 nanocaio 9.9 * requires an explicit call to SmtpClose().
206 djmaze 9.3 * @var bool
207 djmaze 9.3 */
208 djmaze 9.3 var $SMTPKeepAlive = false;
209 djmaze 9.3  
210 djmaze 9.3 /**#@+
211 djmaze 9.3 * @access private
212 djmaze 9.3 */
213 djmaze 9.3 var $smtp = NULL;
214 djmaze 9.3 var $to = array();
215 djmaze 9.3 var $cc = array();
216 djmaze 9.3 var $bcc = array();
217 djmaze 9.3 var $ReplyTo = array();
218 djmaze 9.3 var $attachment = array();
219 djmaze 9.3 var $CustomHeader = array();
220 djmaze 9.3 var $message_type = '';
221 djmaze 9.3 var $boundary = array();
222 djmaze 9.3 var $language = array();
223 djmaze 9.3 var $error_count = 0;
224 djmaze 9.3 var $LE = "\n";
225 djmaze 9.3 /**#@-*/
226 nanocaio 9.9  
227 djmaze 9.3 /////////////////////////////////////////////////
228 djmaze 9.3 // VARIABLE METHODS
229 djmaze 9.3 /////////////////////////////////////////////////
230 djmaze 9.3  
231 djmaze 9.3 /**
232 nanocaio 9.9 * Sets message type to HTML.
233 djmaze 9.3 * @param bool $bool
234 djmaze 9.3 * @return void
235 djmaze 9.3 */
236 djmaze 9.3 function IsHTML($bool) {
237 djmaze 9.3 if($bool)
238 djmaze 9.3 $this->ContentType = 'text/html';
239 djmaze 9.3 else
240 djmaze 9.3 $this->ContentType = 'text/plain';
241 djmaze 9.3 }
242 djmaze 9.3  
243 djmaze 9.3 /**
244 djmaze 9.3 * Sets Mailer to send message using SMTP.
245 djmaze 9.3 * @return void
246 djmaze 9.3 */
247 djmaze 9.3 function IsSMTP() {
248 djmaze 9.3 $this->Mailer = 'smtp';
249 djmaze 9.3 }
250 djmaze 9.3  
251 djmaze 9.3 /**
252 djmaze 9.3 * Sets Mailer to send message using PHP mail() function.
253 djmaze 9.3 * @return void
254 djmaze 9.3 */
255 djmaze 9.3 function IsMail() {
256 djmaze 9.3 $this->Mailer = 'mail';
257 djmaze 9.3 }
258 djmaze 9.3  
259 djmaze 9.3 /**
260 djmaze 9.3 * Sets Mailer to send message using the $Sendmail program.
261 djmaze 9.3 * @return void
262 djmaze 9.3 */
263 djmaze 9.3 function IsSendmail() {
264 djmaze 9.3 $this->Mailer = 'sendmail';
265 djmaze 9.3 }
266 djmaze 9.3  
267 djmaze 9.3 /**
268 nanocaio 9.9 * Sets Mailer to send message using the qmail MTA.
269 djmaze 9.3 * @return void
270 djmaze 9.3 */
271 djmaze 9.3 function IsQmail() {
272 djmaze 9.3 $this->Sendmail = '/var/qmail/bin/sendmail';
273 djmaze 9.3 $this->Mailer = 'sendmail';
274 djmaze 9.3 }
275 djmaze 9.3  
276 djmaze 9.3  
277 djmaze 9.3 /////////////////////////////////////////////////
278 djmaze 9.3 // RECIPIENT METHODS
279 djmaze 9.3 /////////////////////////////////////////////////
280 djmaze 9.3  
281 djmaze 9.3 /**
282 nanocaio 9.9 * Adds a "To" address.
283 djmaze 9.3 * @param string $address
284 djmaze 9.3 * @param string $name
285 djmaze 9.3 * @return void
286 djmaze 9.3 */
287 djmaze 9.3 function AddAddress($address, $name = '') {
288 djmaze 9.3 $cur = count($this->to);
289 djmaze 9.3 $this->to[$cur][0] = trim($address);
290 djmaze 9.3 $this->to[$cur][1] = $name;
291 djmaze 9.3 }
292 djmaze 9.3  
293 djmaze 9.3 /**
294 djmaze 9.3 * Adds a "Cc" address. Note: this function works
295 djmaze 9.3 * with the SMTP mailer on win32, not with the "mail"
296 nanocaio 9.9 * mailer.
297 djmaze 9.3 * @param string $address
298 djmaze 9.3 * @param string $name
299 djmaze 9.3 * @return void
300 djmaze 9.3 */
301 djmaze 9.3 function AddCC($address, $name = '') {
302 djmaze 9.3 $cur = count($this->cc);
303 djmaze 9.3 $this->cc[$cur][0] = trim($address);
304 djmaze 9.3 $this->cc[$cur][1] = $name;
305 djmaze 9.3 }
306 djmaze 9.3  
307 djmaze 9.3 /**
308 djmaze 9.3 * Adds a "Bcc" address. Note: this function works
309 djmaze 9.3 * with the SMTP mailer on win32, not with the "mail"
310 nanocaio 9.9 * mailer.
311 djmaze 9.3 * @param string $address
312 djmaze 9.3 * @param string $name
313 djmaze 9.3 * @return void
314 djmaze 9.3 */
315 djmaze 9.3 function AddBCC($address, $name = '') {
316 djmaze 9.3 $cur = count($this->bcc);
317 djmaze 9.3 $this->bcc[$cur][0] = trim($address);
318 djmaze 9.3 $this->bcc[$cur][1] = $name;
319 djmaze 9.3 }
320 djmaze 9.3  
321 djmaze 9.3 /**
322 nanocaio 9.9 * Adds a "Reply-to" address.
323 djmaze 9.3 * @param string $address
324 djmaze 9.3 * @param string $name
325 djmaze 9.3 * @return void
326 djmaze 9.3 */
327 djmaze 9.3 function AddReplyTo($address, $name = '') {
328 djmaze 9.3 $cur = count($this->ReplyTo);
329 djmaze 9.3 $this->ReplyTo[$cur][0] = trim($address);
330 djmaze 9.3 $this->ReplyTo[$cur][1] = $name;
331 djmaze 9.3 }
332 djmaze 9.3  
333 djmaze 9.3  
334 djmaze 9.3 /////////////////////////////////////////////////
335 djmaze 9.3 // MAIL SENDING METHODS
336 djmaze 9.3 /////////////////////////////////////////////////
337 djmaze 9.3  
338 djmaze 9.3 /**
339 djmaze 9.3 * Creates message and assigns Mailer. If the message is
340 djmaze 9.3 * not sent successfully then it returns false. Use the ErrorInfo
341 nanocaio 9.9 * variable to view description of the error.
342 djmaze 9.3 * @return bool
343 djmaze 9.3 */
344 djmaze 9.3 function Send() {
345 djmaze 9.3 $header = '';
346 djmaze 9.3 $body = '';
347 djmaze 9.3 $result = true;
348 djmaze 9.3  
349 djmaze 9.3 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
350 djmaze 9.3 {
351 djmaze 9.3 $this->SetError($this->Lang('provide_address'));
352 djmaze 9.3 return false;
353 djmaze 9.3 }
354 djmaze 9.3  
355 djmaze 9.3 // Set whether the message is multipart/alternative
356 djmaze 9.3 if(!empty($this->AltBody))
357 djmaze 9.3 $this->ContentType = 'multipart/alternative';
358 djmaze 9.3  
359 djmaze 9.3 $this->SetMessageType();
360 djmaze 9.3 $header .= $this->CreateHeader();
361 djmaze 9.3 $body = $this->CreateBody();
362 djmaze 9.3  
363 djmaze 9.3 if($body == '') { return false; }
364 djmaze 9.3  
365 djmaze 9.3 // Choose the mailer
366 djmaze 9.3 if($this->Mailer == 'sendmail')
367 djmaze 9.3 {
368 djmaze 9.3 if(!$this->SendmailSend($header, $body))
369 djmaze 9.3 return false;
370 djmaze 9.3 }
371 djmaze 9.3 elseif($this->Mailer == 'mail')
372 djmaze 9.3 {
373 djmaze 9.3 if(!$this->MailSend($header, $body))
374 djmaze 9.3 return false;
375 djmaze 9.3 }
376 djmaze 9.3 elseif($this->Mailer == 'smtp')
377 djmaze 9.3 {
378 djmaze 9.3 if(!$this->SmtpSend($header, $body))
379 djmaze 9.3 return false;
380 djmaze 9.3 }
381 djmaze 9.3 else
382 djmaze 9.3 {
383 djmaze 9.3 $this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
384 djmaze 9.3 return false;
385 djmaze 9.3 }
386 djmaze 9.3  
387 djmaze 9.3 return true;
388 djmaze 9.3 }
389 nanocaio 9.9  
390 djmaze 9.3 /**
391 nanocaio 9.9 * Sends mail using the $Sendmail program.
392 djmaze 9.3 * @access private
393 djmaze 9.3 * @return bool
394 djmaze 9.3 */
395 djmaze 9.3 function SendmailSend($header, $body) {
396 djmaze 9.3 if ($this->Sender != '')
397 djmaze 9.3 $sendmail = sprintf('%s -oi -f %s -t', $this->Sendmail, $this->Sender);
398 djmaze 9.3 else
399 djmaze 9.3 $sendmail = sprintf('%s -oi -t', $this->Sendmail);
400 djmaze 9.3  
401 djmaze 9.3 if(!$mail = popen($sendmail, 'w'))
402 djmaze 9.3 {
403 djmaze 9.3 $this->SetError($this->Lang('execute') . $this->Sendmail);
404 djmaze 9.3 return false;
405 djmaze 9.3 }
406 djmaze 9.3  
407 djmaze 9.3 fputs($mail, $header);
408 djmaze 9.3 fputs($mail, $body);
409 nanocaio 9.9  
410 djmaze 9.3 $result = pclose($mail) >> 8 & 0xFF;
411 djmaze 9.3 if($result != 0)
412 djmaze 9.3 {
413 djmaze 9.3 $this->SetError($this->Lang('execute') . $this->Sendmail);
414 djmaze 9.3 return false;
415 djmaze 9.3 }
416 djmaze 9.3  
417 djmaze 9.3 return true;
418 djmaze 9.3 }
419 djmaze 9.3  
420 djmaze 9.3 /**
421 nanocaio 9.9 * Sends mail using the PHP mail() function.
422 djmaze 9.3 * @access private
423 djmaze 9.3 * @return bool
424 djmaze 9.3 */
425 djmaze 9.3 function MailSend($header, $body) {
426 djmaze 9.3 $to = '';
427 djmaze 9.3 for($i = 0; $i < count($this->to); $i++)
428 djmaze 9.3 {
429 djmaze 9.3 if($i != 0) { $to .= ', '; }
430 djmaze 9.3 $to .= $this->to[$i][0];
431 djmaze 9.3 }
432 djmaze 9.3  
433 djmaze 9.3 if ($this->Sender != '' && CAN_MOD_INI)
434 djmaze 9.3 {
435 djmaze 9.3 $old_from = ini_get('sendmail_from');
436 djmaze 9.3 ini_set('sendmail_from', $this->Sender);
437 djmaze 9.3 $params = sprintf('-oi -f %s', $this->Sender);
438 djmaze 9.3 $rt = mail($to, $this->EncodeHeader($this->Subject), $body, $header, $params);
439 djmaze 9.3 }
440 djmaze 9.3 else
441 djmaze 9.3 $rt = mail($to, $this->EncodeHeader($this->Subject), $body, $header);
442 djmaze 9.3  
443 djmaze 9.3 if (isset($old_from))
444 djmaze 9.3 ini_set('sendmail_from', $old_from);
445 djmaze 9.3  
446 djmaze 9.3 if(!$rt)
447 djmaze 9.3 {
448 djmaze 9.3 $this->SetError($this->Lang('instantiate'));
449 djmaze 9.3 return false;
450 djmaze 9.3 }
451 djmaze 9.3  
452 djmaze 9.3 return true;
453 djmaze 9.3 }
454 djmaze 9.3  
455 djmaze 9.3 /**
456 djmaze 9.3 * Sends mail via SMTP using PhpSMTP (Author:
457 djmaze 9.3 * Chris Ryan). Returns bool. Returns false if there is a
458 djmaze 9.3 * bad MAIL FROM, RCPT, or DATA input.
459 djmaze 9.3 * @access private
460 djmaze 9.3 * @return bool
461 djmaze 9.3 */
462 djmaze 9.3 function SmtpSend($header, $body) {
463 djmaze 9.6 require_once(CORE_PATH.'classes/smtp.php');
464 djmaze 9.3 $error = '';
465 djmaze 9.3 $bad_rcpt = array();
466 djmaze 9.3  
467 djmaze 9.3 if(!$this->SmtpConnect())
468 djmaze 9.3 return false;
469 djmaze 9.3  
470 djmaze 9.3 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
471 djmaze 9.3 if(!$this->smtp->Mail($smtp_from))
472 djmaze 9.3 {
473 djmaze 9.3 $error = $this->Lang('from_failed') . $smtp_from;
474 djmaze 9.3 $this->SetError($error);
475 djmaze 9.3 $this->smtp->Reset();
476 djmaze 9.3 return false;
477 djmaze 9.3 }
478 djmaze 9.3  
479 djmaze 9.3 // Attempt to send attach all recipients
480 djmaze 9.3 for($i = 0; $i < count($this->to); $i++)
481 djmaze 9.3 {
482 djmaze 9.3 if(!$this->smtp->Recipient($this->to[$i][0]))
483 djmaze 9.3 $bad_rcpt[] = $this->to[$i][0];
484 djmaze 9.3 }
485 djmaze 9.3 for($i = 0; $i < count($this->cc); $i++)
486 djmaze 9.3 {
487 djmaze 9.3 if(!$this->smtp->Recipient($this->cc[$i][0]))
488 djmaze 9.3 $bad_rcpt[] = $this->cc[$i][0];
489 djmaze 9.3 }
490 djmaze 9.3 for($i = 0; $i < count($this->bcc); $i++)
491 djmaze 9.3 {
492 djmaze 9.3 if(!$this->smtp->Recipient($this->bcc[$i][0]))
493 djmaze 9.3 $bad_rcpt[] = $this->bcc[$i][0];
494 djmaze 9.3 }
495 djmaze 9.3  
496 djmaze 9.3 if(count($bad_rcpt) > 0) // Create error message
497 djmaze 9.3 {
498 djmaze 9.3 for($i = 0; $i < count($bad_rcpt); $i++)
499 djmaze 9.3 {
500 djmaze 9.3 if($i != 0) { $error .= ', '; }
501 djmaze 9.3 $error .= $bad_rcpt[$i];
502 djmaze 9.3 }
503 djmaze 9.3 $error = $this->Lang('recipients_failed') . $error;
504 djmaze 9.3 $this->SetError($error);
505 djmaze 9.3 $this->smtp->Reset();
506 djmaze 9.3 return false;
507 djmaze 9.3 }
508 djmaze 9.3  
509 djmaze 9.3 if(!$this->smtp->Data($header . $body))
510 djmaze 9.3 {
511 djmaze 9.3 $this->SetError($this->Lang('data_not_accepted'));
512 djmaze 9.3 $this->smtp->Reset();
513 djmaze 9.3 return false;
514 djmaze 9.3 }
515 djmaze 9.3 if($this->SMTPKeepAlive == true)
516 djmaze 9.3 $this->smtp->Reset();
517 djmaze 9.3 else
518 djmaze 9.3 $this->SmtpClose();
519 djmaze 9.3  
520 djmaze 9.3 return true;
521 djmaze 9.3 }
522 djmaze 9.3  
523 djmaze 9.3 /**
524 nanocaio 9.9 * Initiates a connection to an SMTP server. Returns false if the
525 djmaze 9.3 * operation failed.
526 djmaze 9.3 * @access private
527 djmaze 9.3 * @return bool
528 djmaze 9.3 */
529 djmaze 9.3 function SmtpConnect() {
530 djmaze 9.3 if($this->smtp == NULL) { $this->smtp = new SMTP(); }
531 djmaze 9.3  
532 djmaze 9.3 $this->smtp->do_debug = $this->SMTPDebug;
533 djmaze 9.3 $hosts = explode(';', $this->Host);
534 djmaze 9.3 $index = 0;
535 nanocaio 9.9 $connection = ($this->smtp->Connected());
536 djmaze 9.3  
537 djmaze 9.3 // Retry while there is no connection
538 djmaze 9.3 while($index < count($hosts) && $connection == false)
539 djmaze 9.3 {
540 nanocaio 10.2 $server = parse_url($hosts[$index]);
541 nanocaio 10.2 $host = isset($server['scheme']) ? $server['scheme'].'://'.$server['host'] : $server['host'];
542 nanocaio 10.2 $port = isset($server['port']) ? $server['port'] : $this->Port;
543 djmaze 9.3  
544 djmaze 9.3 if($this->smtp->Connect($host, $port, $this->Timeout))
545 djmaze 9.3 {
546 djmaze 9.3 if ($this->Helo != '')
547 djmaze 9.3 $this->smtp->Hello($this->Helo);
548 djmaze 9.3 else
549 djmaze 9.3 $this->smtp->Hello($this->ServerHostname());
550 nanocaio 9.9  
551 djmaze 9.3 if($this->SMTPAuth)
552 djmaze 9.3 {
553 nanocaio 9.9 if(!$this->smtp->Authenticate($this->Username,
554 djmaze 9.3 $this->Password))
555 djmaze 9.3 {
556 djmaze 9.3 $this->SetError($this->Lang('authenticate'));
557 djmaze 9.3 $this->smtp->Reset();
558 djmaze 9.3 $connection = false;
559 djmaze 9.3 }
560 djmaze 9.3 }
561 djmaze 9.3 $connection = true;
562 djmaze 9.3 }
563 djmaze 9.3 $index++;
564 djmaze 9.3 }
565 djmaze 9.3 if(!$connection)
566 djmaze 9.3 $this->SetError($this->Lang('connect_host'));
567 djmaze 9.3  
568 djmaze 9.3 return $connection;
569 djmaze 9.3 }
570 djmaze 9.3  
571 djmaze 9.3 /**
572 djmaze 9.3 * Closes the active SMTP session if one exists.
573 djmaze 9.3 * @return void
574 djmaze 9.3 */
575 djmaze 9.3 function SmtpClose() {
576 djmaze 9.3 if($this->smtp != NULL)
577 djmaze 9.3 {
578 djmaze 9.3 if($this->smtp->Connected())
579 djmaze 9.3 {
580 djmaze 9.3 $this->smtp->Quit();
581 djmaze 9.3 $this->smtp->Close();
582 djmaze 9.3 }
583 djmaze 9.3 }
584 djmaze 9.3 }
585 djmaze 9.3  
586 djmaze 9.3 /**
587 nanocaio 9.9 * Sets the language for all class error messages. Returns false
588 djmaze 9.3 * if it cannot load the language file. The default language type
589 djmaze 9.3 * is English.
590 djmaze 9.3 * @param string $lang_type Type of language (e.g. Portuguese: "br")
591 djmaze 9.3 * @param string $lang_path Path to the language file directory
592 djmaze 9.3 * @access public
593 djmaze 9.3 * @return bool
594 djmaze 9.3 */
595 djmaze 9.3 function SetLanguage($lang_path = '') {
596 djmaze 9.3 global $currentlang, $language, $PHPMAILER_LANG;
597 djmaze 9.3 $this->language = $PHPMAILER_LANG;
598 djmaze 9.3 return true;
599 djmaze 9.3 }
600 djmaze 9.3  
601 djmaze 9.3 /////////////////////////////////////////////////
602 djmaze 9.3 // MESSAGE CREATION METHODS
603 djmaze 9.3 /////////////////////////////////////////////////
604 djmaze 9.3  
605 djmaze 9.3 /**
606 nanocaio 9.9 * Creates recipient headers.
607 djmaze 9.3 * @access private
608 djmaze 9.3 * @return string
609 djmaze 9.3 */
610 djmaze 9.3 function AddrAppend($type, $addr) {
611 djmaze 9.5 $addr_str = array();
612 djmaze 9.5 for ($i = 0; $i < count($addr); $i++) {
613 djmaze 9.5 if (empty($addr[$i][1])) {
614 djmaze 9.5 $addr_str[] = $addr[$i][0];
615 djmaze 9.5 } else {
616 djmaze 9.5 $addr_str[] = $this->EncodeHeader($addr[$i][1], 'phrase').' <'.$addr[$i][0].'>';
617 djmaze 9.5 }
618 djmaze 9.3 }
619 djmaze 9.5 return $type.': '.implode(', ', $addr_str).$this->LE;
620 djmaze 9.3 }
621 nanocaio 9.9  
622 djmaze 9.3 /**
623 djmaze 9.3 * Wraps message for use with mailers that do not
624 djmaze 9.3 * automatically perform wrapping and for quoted-printable.
625 nanocaio 9.9 * Original written by philippe.
626 djmaze 9.3 * @access private
627 djmaze 9.3 * @return string
628 djmaze 9.3 */
629 djmaze 9.3 function WrapText($message, $length, $qp_mode = false) {
630 djmaze 9.3 $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
631 djmaze 9.3  
632 djmaze 9.3 $message = $this->FixEOL($message);
633 djmaze 9.3 if (substr($message, -1) == $this->LE)
634 djmaze 9.3 $message = substr($message, 0, -1);
635 djmaze 9.3  
636 djmaze 9.3 $line = explode($this->LE, $message);
637 djmaze 9.3 $message = '';
638 djmaze 9.3 for ($i=0 ;$i < count($line); $i++)
639 djmaze 9.3 {
640 djmaze 9.3 $line_part = explode(' ', $line[$i]);
641 djmaze 9.3 $buf = '';
642 djmaze 9.3 for ($e = 0; $e<count($line_part); $e++)
643 djmaze 9.3 {
644 djmaze 9.3 $word = $line_part[$e];
645 djmaze 9.3 if ($qp_mode && (strlen($word) > $length))
646 djmaze 9.3 {
647 djmaze 9.3 $space_left = $length - strlen($buf) - 1;
648 djmaze 9.3 if ($e != 0)
649 djmaze 9.3 {
650 djmaze 9.3 if ($space_left > 20)
651 djmaze 9.3 {
652 djmaze 9.3 $len = $space_left;
653 djmaze 9.3 if (substr($word, $len - 1, 1) == '=')
654 djmaze 9.3 $len--;
655 djmaze 9.3 elseif (substr($word, $len - 2, 1) == '=')
656 djmaze 9.3 $len -= 2;
657 djmaze 9.3 $part = substr($word, 0, $len);
658 djmaze 9.3 $word = substr($word, $len);
659 djmaze 9.3 $buf .= ' ' . $part;
660 djmaze 9.3 $message .= $buf . sprintf('=%s', $this->LE);
661 djmaze 9.3 }
662 djmaze 9.3 else
663 djmaze 9.3 {
664 djmaze 9.3 $message .= $buf . $soft_break;
665 djmaze 9.3 }
666 djmaze 9.3 $buf = '';
667 djmaze 9.3 }
668 djmaze 9.3 while (strlen($word) > 0)
669 djmaze 9.3 {
670 djmaze 9.3 $len = $length;
671 djmaze 9.3 if (substr($word, $len - 1, 1) == '=')
672 djmaze 9.3 $len--;
673 djmaze 9.3 elseif (substr($word, $len - 2, 1) == '=')
674 djmaze 9.3 $len -= 2;
675 djmaze 9.3 $part = substr($word, 0, $len);
676 djmaze 9.3 $word = substr($word, $len);
677 djmaze 9.3  
678 djmaze 9.3 if (strlen($word) > 0)
679 djmaze 9.3 $message .= $part . sprintf('=%s', $this->LE);
680 djmaze 9.3 else
681 djmaze 9.3 $buf = $part;
682 djmaze 9.3 }
683 djmaze 9.3 }
684 djmaze 9.3 else
685 djmaze 9.3 {
686 djmaze 9.3 $buf_o = $buf;
687 nanocaio 9.9 $buf .= ($e == 0) ? $word : (' ' . $word);
688 djmaze 9.3  
689 djmaze 9.3 if (strlen($buf) > $length && $buf_o != '')
690 djmaze 9.3 {
691 djmaze 9.3 $message .= $buf_o . $soft_break;
692 djmaze 9.3 $buf = $word;
693 djmaze 9.3 }
694 djmaze 9.3 }
695 djmaze 9.3 }
696 djmaze 9.3 $message .= $buf . $this->LE;
697 djmaze 9.3 }
698 djmaze 9.3  
699 djmaze 9.3 return $message;
700 djmaze 9.3 }
701 nanocaio 9.9  
702 djmaze 9.3 /**
703 djmaze 9.3 * Set the body wrapping.
704 djmaze 9.3 * @access private
705 djmaze 9.3 * @return void
706 djmaze 9.3 */
707 djmaze 9.3 function SetWordWrap() {
708 djmaze 9.3 if($this->WordWrap < 1)
709 djmaze 9.3 return;
710 nanocaio 9.9  
711 djmaze 9.3 switch($this->message_type)
712 djmaze 9.3 {
713 djmaze 9.3 case 'alt':
714 djmaze 9.3 // fall through
715 djmaze 9.7 case 'alt_attachments':
716 djmaze 9.3 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
717 djmaze 9.3 break;
718 djmaze 9.3 default:
719 djmaze 9.3 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
720 djmaze 9.3 break;
721 djmaze 9.3 }
722 djmaze 9.3 }
723 djmaze 9.3  
724 djmaze 9.3 /**
725 nanocaio 9.9 * Assembles message header.
726 djmaze 9.3 * @access private
727 djmaze 9.3 * @return string
728 djmaze 9.3 */
729 djmaze 9.3 function CreateHeader() {
730 djmaze 9.3 $result = '';
731 nanocaio 9.9  
732 djmaze 9.3 // Set the boundaries
733 djmaze 9.3 $uniq_id = md5(uniqid(time()));
734 djmaze 9.3 $this->boundary[1] = 'b1_' . $uniq_id;
735 djmaze 9.3 $this->boundary[2] = 'b2_' . $uniq_id;
736 djmaze 9.3  
737 djmaze 9.3 $result .= $this->HeaderLine('Date', $this->RFCDate());
738 djmaze 9.3 if($this->Sender == '')
739 djmaze 9.3 $result .= $this->HeaderLine('Return-Path', trim($this->From));
740 djmaze 9.3 else
741 djmaze 9.3 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
742 nanocaio 9.9  
743 djmaze 9.3 // To be created automatically by mail()
744 trevor 9.4 if($this->Mailer != 'mail')
745 djmaze 9.3 {
746 djmaze 9.3 if(count($this->to) > 0)
747 djmaze 9.3 $result .= $this->AddrAppend('To', $this->to);
748 djmaze 9.3 else if (count($this->cc) == 0)
749 djmaze 9.3 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
750 djmaze 9.3 if(count($this->cc) > 0)
751 djmaze 9.3 $result .= $this->AddrAppend('Cc', $this->cc);
752 djmaze 9.3 }
753 djmaze 9.3  
754 djmaze 9.3 $from = array();
755 djmaze 9.3 $from[0][0] = trim($this->From);
756 djmaze 9.3 $from[0][1] = $this->FromName;
757 nanocaio 9.9 $result .= $this->AddrAppend('From', $from);
758 djmaze 9.3 // sendmail and mail() extract Bcc from the header before sending
759 djmaze 9.3 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0))
760 djmaze 9.3 $result .= $this->AddrAppend('Bcc', $this->bcc);
761 djmaze 9.3  
762 djmaze 9.3 if(count($this->ReplyTo) > 0)
763 djmaze 9.3 $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
764 djmaze 9.3  
765 djmaze 9.3 // mail() sets the subject itself
766 djmaze 9.3 if($this->Mailer != 'mail')
767 djmaze 9.3 $result .= $this->HeaderLine('Subject', $this->EncodeHeader(trim($this->Subject)));
768 djmaze 9.3  
769 djmaze 9.3 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
770 djmaze 9.3 $result .= $this->HeaderLine('X-Priority', $this->Priority);
771 djmaze 9.5 //X-MSMail-Priority: Normal
772 djmaze 9.5 //X-MimeOLE
773 djmaze 9.3 $result .= $this->HeaderLine('X-Mailer', "PHPMailer [version " . $this->Version . "]");
774 nanocaio 9.9  
775 nanocaio 10.3 $ip = Dragonfly_Net::ipn();
776 nanocaio 9.9 $backtrace = debug_backtrace();
777 nanocaio 9.9 $src = 'unknown';
778 nanocaio 9.9 for ($i=0; $i<=count($backtrace); ++$i) {
779 nanocaio 9.9 if (isset($backtrace[$i]['function']) && 'send_mail' === $backtrace[$i]['function']) {
780 nanocaio 10.1 $src = str_replace(BASEDIR, '', $backtrace[$i]['file']);
781 nanocaio 9.9 $backtrace = NULL;
782 nanocaio 9.9 break;
783 nanocaio 9.9 }
784 nanocaio 9.9 }
785 nanocaio 9.9 $result .= $this->HeaderLine('X-DF-MailerSRC', $src . ' for ' . decode_ip($ip));
786 nanocaio 9.9  
787 djmaze 9.3 if($this->ConfirmReadingTo != '')
788 djmaze 9.3 {
789 nanocaio 9.9 $result .= $this->HeaderLine('Disposition-Notification-To',
790 djmaze 9.3 '<' . trim($this->ConfirmReadingTo) . '>');
791 djmaze 9.3 }
792 djmaze 9.3  
793 djmaze 9.3 // Add custom headers
794 djmaze 9.3 for($index = 0; $index < count($this->CustomHeader); $index++)
795 djmaze 9.3 {
796 nanocaio 9.9 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
797 djmaze 9.3 $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
798 djmaze 9.3 }
799 djmaze 9.3 $result .= $this->HeaderLine('MIME-Version', '1.0');
800 djmaze 9.3  
801 djmaze 9.3 switch($this->message_type)
802 djmaze 9.3 {
803 djmaze 9.3 case 'plain':
804 djmaze 9.3 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
805 djmaze 9.3 $result .= sprintf('Content-Type: %s; charset="%s"',
806 djmaze 9.3 $this->ContentType, $this->CharSet);
807 djmaze 9.3 break;
808 djmaze 9.3 case 'attachments':
809 djmaze 9.3 // fall through
810 djmaze 9.3 case 'alt_attachments':
811 djmaze 9.3 if($this->InlineImageExists())
812 djmaze 9.3 {
813 nanocaio 9.9 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
814 nanocaio 9.9 "multipart/related", $this->LE, $this->LE,
815 djmaze 9.3 $this->boundary[1], $this->LE);
816 djmaze 9.3 }
817 djmaze 9.3 else
818 djmaze 9.3 {
819 djmaze 9.3 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
820 djmaze 9.3 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
821 djmaze 9.3 }
822 djmaze 9.3 break;
823 djmaze 9.3 case 'alt':
824 djmaze 9.3 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
825 djmaze 9.3 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
826 djmaze 9.3 break;
827 djmaze 9.3 }
828 djmaze 9.3  
829 djmaze 9.3 if($this->Mailer != 'mail')
830 djmaze 9.3 $result .= $this->LE.$this->LE;
831 djmaze 9.3  
832 djmaze 9.3 return $result;
833 djmaze 9.3 }
834 djmaze 9.3  
835 djmaze 9.3 /**
836 djmaze 9.3 * Assembles the message body. Returns an empty string on failure.
837 djmaze 9.3 * @access private
838 djmaze 9.3 * @return string
839 djmaze 9.3 */
840 djmaze 9.3 function CreateBody() {
841 djmaze 9.3 $result = '';
842 djmaze 9.3  
843 djmaze 9.3 $this->SetWordWrap();
844 djmaze 9.3  
845 djmaze 9.3 switch($this->message_type)
846 djmaze 9.3 {
847 djmaze 9.3 case 'alt':
848 nanocaio 9.9 $result .= $this->GetBoundary($this->boundary[1], '',
849 djmaze 9.3 'text/plain', '');
850 djmaze 9.3 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
851 djmaze 9.3 $result .= $this->LE.$this->LE;
852 nanocaio 9.9 $result .= $this->GetBoundary($this->boundary[1], '',
853 djmaze 9.3 'text/html', '');
854 nanocaio 9.9  
855 djmaze 9.3 $result .= $this->EncodeString($this->Body, $this->Encoding);
856 djmaze 9.3 $result .= $this->LE.$this->LE;
857 nanocaio 9.9  
858 djmaze 9.3 $result .= $this->EndBoundary($this->boundary[1]);
859 djmaze 9.3 break;
860 djmaze 9.3 case 'plain':
861 djmaze 9.3 $result .= $this->EncodeString($this->Body, $this->Encoding);
862 djmaze 9.3 break;
863 djmaze 9.3 case 'attachments':
864 djmaze 9.3 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
865 djmaze 9.3 $result .= $this->EncodeString($this->Body, $this->Encoding);
866 djmaze 9.3 $result .= $this->LE;
867 nanocaio 9.9  
868 djmaze 9.3 $result .= $this->AttachAll();
869 djmaze 9.3 break;
870 djmaze 9.3 case 'alt_attachments':
871 djmaze 9.3 $result .= sprintf('--%s%s', $this->boundary[1], $this->LE);
872 djmaze 9.3 $result .= sprintf('Content-Type: %s;%s' .
873 djmaze 9.3 "\tboundary=\"%s\"%s",
874 nanocaio 9.9 'multipart/alternative', $this->LE,
875 djmaze 9.3 $this->boundary[2], $this->LE.$this->LE);
876 nanocaio 9.9  
877 djmaze 9.3 // Create text body
878 nanocaio 9.9 $result .= $this->GetBoundary($this->boundary[2], '',
879 djmaze 9.3 'text/plain', '') . $this->LE;
880 djmaze 9.3  
881 djmaze 9.3 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
882 djmaze 9.3 $result .= $this->LE.$this->LE;
883 nanocaio 9.9  
884 djmaze 9.3 // Create the HTML body
885 nanocaio 9.9 $result .= $this->GetBoundary($this->boundary[2], '',
886 djmaze 9.3 'text/html', '') . $this->LE;
887 nanocaio 9.9  
888 djmaze 9.3 $result .= $this->EncodeString($this->Body, $this->Encoding);
889 djmaze 9.3 $result .= $this->LE.$this->LE;
890 djmaze 9.3  
891 djmaze 9.3 $result .= $this->EndBoundary($this->boundary[2]);
892 nanocaio 9.9  
893 djmaze 9.3 $result .= $this->AttachAll();
894 djmaze 9.3 break;
895 djmaze 9.3 }
896 djmaze 9.3 if($this->IsError())
897 djmaze 9.3 $result = '';
898 djmaze 9.3  
899 djmaze 9.3 return $result;
900 djmaze 9.3 }
901 djmaze 9.3  
902 djmaze 9.3 /**
903 djmaze 9.3 * Returns the start of a message boundary.
904 djmaze 9.3 * @access private
905 djmaze 9.3 */
906 djmaze 9.3 function GetBoundary($boundary, $charSet, $contentType, $encoding) {
907 djmaze 9.3 $result = '';
908 djmaze 9.3 if($charSet == '') { $charSet = $this->CharSet; }
909 djmaze 9.3 if($contentType == '') { $contentType = $this->ContentType; }
910 djmaze 9.3 if($encoding == '') { $encoding = $this->Encoding; }
911 djmaze 9.3  
912 trevor 9.4 $result .= $this->TextLine('--' . $boundary);
913 estlane 9.11 $result .= sprintf('Content-Type: %s; charset="%s"',
914 djmaze 9.3 $contentType, $charSet);
915 djmaze 9.3 $result .= $this->LE;
916 djmaze 9.3 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
917 djmaze 9.3 $result .= $this->LE;
918 nanocaio 9.9  
919 djmaze 9.3 return $result;
920 djmaze 9.3 }
921 nanocaio 9.9  
922 djmaze 9.3 /**
923 djmaze 9.3 * Returns the end of a message boundary.
924 djmaze 9.3 * @access private
925 djmaze 9.3 */
926 djmaze 9.3 function EndBoundary($boundary) {
927 nanocaio 9.9 return $this->LE . '--' . $boundary . '--' . $this->LE;
928 djmaze 9.3 }
929 nanocaio 9.9  
930 djmaze 9.3 /**
931 djmaze 9.3 * Sets the message type.
932 djmaze 9.3 * @access private
933 djmaze 9.3 * @return void
934 djmaze 9.3 */
935 djmaze 9.3 function SetMessageType() {
936 djmaze 9.3 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
937 djmaze 9.3 $this->message_type = 'plain';
938 djmaze 9.3 else
939 djmaze 9.3 {
940 djmaze 9.3 if(count($this->attachment) > 0)
941 djmaze 9.3 $this->message_type = 'attachments';
942 djmaze 9.3 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
943 djmaze 9.3 $this->message_type = 'alt';
944 djmaze 9.3 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
945 djmaze 9.3 $this->message_type = 'alt_attachments';
946 djmaze 9.3 }
947 djmaze 9.3 }
948 djmaze 9.3  
949 djmaze 9.3 /**
950 djmaze 9.3 * Returns a formatted header line.
951 djmaze 9.3 * @access private
952 djmaze 9.3 * @return string
953 djmaze 9.3 */
954 djmaze 9.3 function HeaderLine($name, $value) {
955 djmaze 9.3 return $name . ': ' . $value . $this->LE;
956 djmaze 9.3 }
957 djmaze 9.3  
958 djmaze 9.3 /**
959 djmaze 9.3 * Returns a formatted mail line.
960 djmaze 9.3 * @access private
961 djmaze 9.3 * @return string
962 djmaze 9.3 */
963 djmaze 9.3 function TextLine($value) {
964 djmaze 9.3 return $value . $this->LE;
965 djmaze 9.3 }
966 djmaze 9.3  
967 djmaze 9.3 /////////////////////////////////////////////////
968 djmaze 9.3 // ATTACHMENT METHODS
969 djmaze 9.3 /////////////////////////////////////////////////
970 djmaze 9.3  
971 djmaze 9.3 /**
972 djmaze 9.3 * Adds an attachment from a path on the filesystem.
973 djmaze 9.3 * Returns false if the file could not be found
974 djmaze 9.3 * or accessed.
975 djmaze 9.3 * @param string $path Path to the attachment.
976 djmaze 9.3 * @param string $name Overrides the attachment name.
977 djmaze 9.3 * @param string $encoding File encoding (see $Encoding).
978 djmaze 9.3 * @param string $type File extension (MIME) type.
979 djmaze 9.3 * @return bool
980 djmaze 9.3 */
981 nanocaio 9.9 function AddAttachment($path, $name = '', $encoding = 'base64',
982 djmaze 9.3 $type = 'application/octet-stream') {
983 djmaze 9.3 if(!is_file($path))
984 djmaze 9.3 {
985 djmaze 9.3 $this->SetError($this->Lang('file_access') . $path);
986 djmaze 9.3 return false;
987 djmaze 9.3 }
988 djmaze 9.3  
989 djmaze 9.3 $filename = basename($path);
990 djmaze 9.3 if($name == '')
991 djmaze 9.3 $name = $filename;
992 djmaze 9.3  
993 djmaze 9.3 $cur = count($this->attachment);
994 djmaze 9.3 $this->attachment[$cur][0] = $path;
995 djmaze 9.3 $this->attachment[$cur][1] = $filename;
996 djmaze 9.3 $this->attachment[$cur][2] = $name;
997 djmaze 9.3 $this->attachment[$cur][3] = $encoding;
998 djmaze 9.3 $this->attachment[$cur][4] = $type;
999 djmaze 9.3 $this->attachment[$cur][5] = false; // isStringAttachment
1000 djmaze 9.3 $this->attachment[$cur][6] = 'attachment';
1001 djmaze 9.3 $this->attachment[$cur][7] = 0;
1002 djmaze 9.3  
1003 djmaze 9.3 return true;
1004 djmaze 9.3 }
1005 djmaze 9.3  
1006 djmaze 9.3 /**
1007 djmaze 9.3 * Attaches all fs, string, and binary attachments to the message.
1008 djmaze 9.3 * Returns an empty string on failure.
1009 djmaze 9.3 * @access private
1010 djmaze 9.3 * @return string
1011 djmaze 9.3 */
1012 djmaze 9.3 function AttachAll() {
1013 djmaze 9.3 // Return text of body
1014 djmaze 9.3 $mime = array();
1015 djmaze 9.3  
1016 djmaze 9.3 // Add all attachments
1017 djmaze 9.3 for($i = 0; $i < count($this->attachment); $i++)
1018 djmaze 9.3 {
1019 djmaze 9.3 // Check for string attachment
1020 djmaze 9.3 $bString = $this->attachment[$i][5];
1021 djmaze 9.3 if ($bString)
1022 djmaze 9.3 $string = $this->attachment[$i][0];
1023 djmaze 9.3 else
1024 djmaze 9.3 $path = $this->attachment[$i][0];
1025 djmaze 9.3  
1026 djmaze 9.3 $filename = $this->attachment[$i][1];
1027 djmaze 9.3 $name = $this->attachment[$i][2];
1028 djmaze 9.3 $encoding = $this->attachment[$i][3];
1029 djmaze 9.3 $type = $this->attachment[$i][4];
1030 djmaze 9.3 $disposition = $this->attachment[$i][6];
1031 djmaze 9.3 $cid = $this->attachment[$i][7];
1032 nanocaio 9.9  
1033 djmaze 9.3 $mime[] = sprintf('--%s%s', $this->boundary[1], $this->LE);
1034 djmaze 9.3 $mime[] = sprintf('Content-Type: %s; name="%s"%s', $type, $name, $this->LE);
1035 djmaze 9.3 $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
1036 djmaze 9.3  
1037 djmaze 9.3 if($disposition == 'inline')
1038 djmaze 9.3 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1039 djmaze 9.3  
1040 nanocaio 9.9 $mime[] = sprintf('Content-Disposition: %s; filename="%s"%s',
1041 djmaze 9.3 $disposition, $name, $this->LE.$this->LE);
1042 djmaze 9.3  
1043 djmaze 9.3 // Encode as string attachment
1044 djmaze 9.3 if($bString)
1045 djmaze 9.3 {
1046 djmaze 9.3 $mime[] = $this->EncodeString($string, $encoding);
1047 djmaze 9.3 if($this->IsError()) { return ''; }
1048 djmaze 9.3 $mime[] = $this->LE.$this->LE;
1049 djmaze 9.3 }
1050 djmaze 9.3 else
1051 djmaze 9.3 {
1052 nanocaio 9.9 $mime[] = $this->EncodeFile($path, $encoding);
1053 djmaze 9.3 if($this->IsError()) { return ''; }
1054 djmaze 9.3 $mime[] = $this->LE.$this->LE;
1055 djmaze 9.3 }
1056 djmaze 9.3 }
1057 djmaze 9.3  
1058 djmaze 9.3 $mime[] = sprintf('--%s--%s', $this->boundary[1], $this->LE);
1059 djmaze 9.3  
1060 djmaze 9.3 return join('', $mime);
1061 djmaze 9.3 }
1062 nanocaio 9.9  
1063 djmaze 9.3 /**
1064 djmaze 9.3 * Encodes attachment in requested format. Returns an
1065 djmaze 9.3 * empty string on failure.
1066 djmaze 9.3 * @access private
1067 djmaze 9.3 * @return string
1068 djmaze 9.3 */
1069 djmaze 9.3 function EncodeFile ($path, $encoding = 'base64') {
1070 djmaze 9.3 if(!$fd = fopen($path, 'rb'))
1071 djmaze 9.3 {
1072 djmaze 9.3 $this->SetError($this->Lang('file_open') . $path);
1073 djmaze 9.3 return '';
1074 djmaze 9.3 }
1075 djmaze 9.3 $file_buffer = fread($fd, filesize($path));
1076 djmaze 9.3 $file_buffer = $this->EncodeString($file_buffer, $encoding);
1077 djmaze 9.3 fclose($fd);
1078 djmaze 9.3  
1079 djmaze 9.3 return $file_buffer;
1080 djmaze 9.3 }
1081 djmaze 9.3  
1082 djmaze 9.3 /**
1083 djmaze 9.3 * Encodes string to requested format. Returns an
1084 djmaze 9.3 * empty string on failure.
1085 djmaze 9.3 * @access private
1086 djmaze 9.3 * @return string
1087 djmaze 9.3 */
1088 djmaze 9.3 function EncodeString ($str, $encoding = 'base64') {
1089 djmaze 9.3 $encoded = '';
1090 djmaze 9.3 switch(strtolower($encoding)) {
1091 djmaze 9.3 case 'base64':
1092 djmaze 9.3 // chunk_split is found in PHP >= 3.0.6
1093 djmaze 9.3 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1094 djmaze 9.3 break;
1095 djmaze 9.3 case '7bit':
1096 djmaze 9.3 case '8bit':
1097 djmaze 9.3 $encoded = $this->FixEOL($str);
1098 djmaze 9.3 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1099 djmaze 9.3 $encoded .= $this->LE;
1100 djmaze 9.3 break;
1101 djmaze 9.3 case 'binary':
1102 djmaze 9.3 $encoded = $str;
1103 djmaze 9.3 break;
1104 djmaze 9.3 case 'quoted-printable':
1105 djmaze 9.3 $encoded = $this->EncodeQP($str);
1106 djmaze 9.3 break;
1107 djmaze 9.3 default:
1108 djmaze 9.3 $this->SetError($this->Lang('encoding') . $encoding);
1109 djmaze 9.3 break;
1110 djmaze 9.3 }
1111 djmaze 9.3 return $encoded;
1112 djmaze 9.3 }
1113 djmaze 9.3  
1114 djmaze 9.3 /**
1115 nanocaio 9.9 * Encode a header string to best of Q, B, quoted or none.
1116 djmaze 9.3 * @access private
1117 djmaze 9.3 * @return string
1118 djmaze 9.3 */
1119 djmaze 9.3 function EncodeHeader ($str, $position = 'text') {
1120 djmaze 9.3 $x = 0;
1121 nanocaio 9.9  
1122 djmaze 9.3 switch (strtolower($position)) {
1123 djmaze 9.3 case 'phrase':
1124 djmaze 9.3 if (!preg_match('/[\200-\377]/', $str)) {
1125 djmaze 9.3 // Can't use addslashes as we don't know what value has magic_quotes_sybase.
1126 djmaze 9.3 $encoded = addcslashes($str, "\0..\37\177\\\"");
1127 djmaze 9.5 if ($str == $encoded && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
1128 djmaze 9.5 return $encoded;
1129 djmaze 9.3 else
1130 djmaze 9.5 return "\"$encoded\"";
1131 djmaze 9.3 }
1132 djmaze 9.3 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1133 djmaze 9.3 break;
1134 djmaze 9.3 case 'comment':
1135 djmaze 9.3 $x = preg_match_all('/[()"]/', $str, $matches);
1136 djmaze 9.3 // Fall-through
1137 djmaze 9.3 case 'text':
1138 djmaze 9.3 default:
1139 djmaze 9.3 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1140 djmaze 9.3 break;
1141 djmaze 9.3 }
1142 djmaze 9.3  
1143 djmaze 9.3 if ($x == 0)
1144 djmaze 9.3 return ($str);
1145 djmaze 9.3  
1146 djmaze 9.3 $maxlen = 75 - 7 - strlen($this->CharSet);
1147 djmaze 9.3 // Try to select the encoding which should produce the shortest output
1148 djmaze 9.3 if (strlen($str)/3 < $x) {
1149 djmaze 9.3 $encoding = 'B';
1150 djmaze 9.3 $encoded = base64_encode($str);
1151 djmaze 9.3 $maxlen -= $maxlen % 4;
1152 djmaze 9.3 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1153 djmaze 9.3 } else {
1154 djmaze 9.3 $encoding = 'Q';
1155 djmaze 9.3 $encoded = $this->EncodeQ($str, $position);
1156 djmaze 9.3 $encoded = $this->WrapText($encoded, $maxlen, true);
1157 djmaze 9.3 $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
1158 djmaze 9.3 }
1159 djmaze 9.3  
1160 djmaze 9.3 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1161 djmaze 9.3 $encoded = trim(str_replace("\n", $this->LE, $encoded));
1162 nanocaio 9.9  
1163 djmaze 9.3 return $encoded;
1164 djmaze 9.3 }
1165 nanocaio 9.9  
1166 djmaze 9.3 /**
1167 nanocaio 9.9 * Encode string to quoted-printable.
1168 djmaze 9.3 * @access private
1169 djmaze 9.3 * @return string
1170 djmaze 9.3 */
1171 djmaze 9.3 function EncodeQP ($str) {
1172 djmaze 9.3 $encoded = $this->FixEOL($str);
1173 djmaze 9.3 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1174 djmaze 9.3 $encoded .= $this->LE;
1175 djmaze 9.3  
1176 djmaze 9.3 // Replace every high ascii, control and = characters
1177 djmaze 9.3 $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
1178 djmaze 9.3 "'='.sprintf('%02X', ord('\\1'))", $encoded);
1179 djmaze 9.3 // Replace every spaces and tabs when it's the last character on a line
1180 djmaze 9.3 $encoded = preg_replace("/([\011\040])".$this->LE."/e",
1181 djmaze 9.3 "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
1182 djmaze 9.3  
1183 djmaze 9.3 // Maximum line length of 76 characters before CRLF (74 + space + '=')
1184 djmaze 9.3 $encoded = $this->WrapText($encoded, 74, true);
1185 djmaze 9.3  
1186 djmaze 9.3 return $encoded;
1187 djmaze 9.3 }
1188 djmaze 9.3  
1189 djmaze 9.3 /**
1190 nanocaio 9.9 * Encode string to q encoding.
1191 djmaze 9.3 * @access private
1192 djmaze 9.3 * @return string
1193 djmaze 9.3 */
1194 djmaze 9.3 function EncodeQ ($str, $position = 'text') {
1195 djmaze 9.3 // There should not be any EOL in the string
1196 djmaze 9.3 $encoded = preg_replace("[\r\n]", '', $str);
1197 djmaze 9.3  
1198 djmaze 9.3 switch (strtolower($position)) {
1199 djmaze 9.3 case 'phrase':
1200 djmaze 9.10 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", '\'=\'.bin2hex("$1")', $encoded);
1201 djmaze 9.3 break;
1202 djmaze 9.3 case 'comment':
1203 djmaze 9.10 $encoded = preg_replace("/([\(\)\"])/e", '\'=\'.bin2hex("$1")', $encoded);
1204 djmaze 9.3 case 'text':
1205 djmaze 9.3 default:
1206 djmaze 9.3 // Replace every high ascii, control =, ? and _ characters
1207 djmaze 9.3 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1208 djmaze 9.3 "'='.sprintf('%02X', ord('\\1'))", $encoded);
1209 djmaze 9.3 break;
1210 djmaze 9.3 }
1211 nanocaio 9.9  
1212 djmaze 9.3 // Replace every spaces to _ (more readable than =20)
1213 djmaze 9.3 $encoded = str_replace(' ', '_', $encoded);
1214 djmaze 9.3  
1215 djmaze 9.3 return $encoded;
1216 djmaze 9.3 }
1217 djmaze 9.3  
1218 djmaze 9.3 /**
1219 djmaze 9.3 * Adds a string or binary attachment (non-filesystem) to the list.
1220 djmaze 9.3 * This method can be used to attach ascii or binary data,
1221 djmaze 9.3 * such as a BLOB record from a database.
1222 djmaze 9.3 * @param string $string String attachment data.
1223 djmaze 9.3 * @param string $filename Name of the attachment.
1224 djmaze 9.3 * @param string $encoding File encoding (see $Encoding).
1225 djmaze 9.3 * @param string $type File extension (MIME) type.
1226 djmaze 9.3 * @return void
1227 djmaze 9.3 */
1228 nanocaio 9.9 function AddStringAttachment($string, $filename, $encoding = 'base64',
1229 djmaze 9.3 $type = 'application/octet-stream') {
1230 djmaze 9.3 // Append to $attachment array
1231 djmaze 9.3 $cur = count($this->attachment);
1232 djmaze 9.3 $this->attachment[$cur][0] = $string;
1233 djmaze 9.3 $this->attachment[$cur][1] = $filename;
1234 djmaze 9.3 $this->attachment[$cur][2] = $filename;
1235 djmaze 9.3 $this->attachment[$cur][3] = $encoding;
1236 djmaze 9.3 $this->attachment[$cur][4] = $type;
1237 djmaze 9.3 $this->attachment[$cur][5] = true; // isString
1238 djmaze 9.3 $this->attachment[$cur][6] = 'attachment';
1239 djmaze 9.3 $this->attachment[$cur][7] = 0;
1240 djmaze 9.3 }
1241 nanocaio 9.9  
1242 djmaze 9.3 /**
1243 nanocaio 9.9 * Adds an embedded attachment. This can include images, sounds, and
1244 nanocaio 9.9 * just about any other document. Make sure to set the $type to an
1245 nanocaio 9.9 * image type. For JPEG images use "image/jpeg" and for GIF images
1246 djmaze 9.3 * use "image/gif".
1247 djmaze 9.3 * @param string $path Path to the attachment.
1248 nanocaio 9.9 * @param string $cid Content ID of the attachment. Use this to identify
1249 djmaze 9.3 * the Id for accessing the image in an HTML form.
1250 djmaze 9.3 * @param string $name Overrides the attachment name.
1251 djmaze 9.3 * @param string $encoding File encoding (see $Encoding).
1252 nanocaio 9.9 * @param string $type File extension (MIME) type.
1253 djmaze 9.3 * @return bool
1254 djmaze 9.3 */
1255 nanocaio 9.9 function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64',
1256 djmaze 9.3 $type = 'application/octet-stream') {
1257 nanocaio 9.9  
1258 djmaze 9.3 if(!is_file($path))
1259 djmaze 9.3 {
1260 djmaze 9.3 $this->SetError($this->Lang('file_access') . $path);
1261 djmaze 9.3 return false;
1262 djmaze 9.3 }
1263 djmaze 9.3  
1264 djmaze 9.3 $filename = basename($path);
1265 djmaze 9.3 if($name == '')
1266 djmaze 9.3 $name = $filename;
1267 djmaze 9.3  
1268 djmaze 9.3 // Append to $attachment array
1269 djmaze 9.3 $cur = count($this->attachment);
1270 djmaze 9.3 $this->attachment[$cur][0] = $path;
1271 djmaze 9.3 $this->attachment[$cur][1] = $filename;
1272 djmaze 9.3 $this->attachment[$cur][2] = $name;
1273 djmaze 9.3 $this->attachment[$cur][3] = $encoding;
1274 djmaze 9.3 $this->attachment[$cur][4] = $type;
1275 djmaze 9.3 $this->attachment[$cur][5] = false; // isStringAttachment
1276 djmaze 9.3 $this->attachment[$cur][6] = 'inline';
1277 djmaze 9.3 $this->attachment[$cur][7] = $cid;
1278 nanocaio 9.9  
1279 djmaze 9.3 return true;
1280 djmaze 9.3 }
1281 nanocaio 9.9  
1282 djmaze 9.3 /**
1283 djmaze 9.3 * Returns true if an inline attachment is present.
1284 djmaze 9.3 * @access private
1285 djmaze 9.3 * @return bool
1286 djmaze 9.3 */
1287 djmaze 9.3 function InlineImageExists() {
1288 djmaze 9.3 $result = false;
1289 djmaze 9.3 for($i = 0; $i < count($this->attachment); $i++)
1290 djmaze 9.3 {
1291 djmaze 9.3 if($this->attachment[$i][6] == 'inline')
1292 djmaze 9.3 {
1293 djmaze 9.3 $result = true;
1294 djmaze 9.3 break;
1295 djmaze 9.3 }
1296 djmaze 9.3 }
1297 nanocaio 9.9  
1298 djmaze 9.3 return $result;
1299 djmaze 9.3 }
1300 djmaze 9.3  
1301 djmaze 9.3 /////////////////////////////////////////////////
1302 djmaze 9.3 // MESSAGE RESET METHODS
1303 djmaze 9.3 /////////////////////////////////////////////////
1304 djmaze 9.3  
1305 djmaze 9.3 function ClearAll() {
1306 djmaze 9.3 $this->ClearAllRecipients();
1307 djmaze 9.3 $this->ReplyTo = array();
1308 djmaze 9.3 $this->attachment = array();
1309 djmaze 9.3 $this->CustomHeader = array();
1310 djmaze 9.3 }
1311 djmaze 9.3  
1312 djmaze 9.3 /**
1313 djmaze 9.3 * Clears all recipients assigned in the TO array. Returns void.
1314 djmaze 9.3 * @return void
1315 djmaze 9.3 */
1316 djmaze 9.3 function ClearAddresses() {
1317 djmaze 9.3 $this->to = array();
1318 djmaze 9.3 }
1319 djmaze 9.3  
1320 djmaze 9.3 /**
1321 djmaze 9.3 * Clears all recipients assigned in the CC array. Returns void.
1322 djmaze 9.3 * @return void
1323 djmaze 9.3 */
1324 djmaze 9.3 function ClearCCs() {
1325 djmaze 9.3 $this->cc = array();
1326 djmaze 9.3 }
1327 djmaze 9.3  
1328 djmaze 9.3 /**
1329 djmaze 9.3 * Clears all recipients assigned in the BCC array. Returns void.
1330 djmaze 9.3 * @return void
1331 djmaze 9.3 */
1332 djmaze 9.3 function ClearBCCs() {
1333 djmaze 9.3 $this->bcc = array();
1334 djmaze 9.3 }
1335 djmaze 9.3  
1336 djmaze 9.3 /**
1337 djmaze 9.3 * Clears all recipients assigned in the ReplyTo array. Returns void.
1338 djmaze 9.3 * @return void
1339 djmaze 9.3 */
1340 djmaze 9.3 function ClearReplyTos() {
1341 djmaze 9.3 $this->ReplyTo = array();
1342 djmaze 9.3 }
1343 djmaze 9.3  
1344 djmaze 9.3 /**
1345 djmaze 9.3 * Clears all recipients assigned in the TO, CC and BCC
1346 djmaze 9.3 * array. Returns void.
1347 djmaze 9.3 * @return void
1348 djmaze 9.3 */
1349 djmaze 9.3 function ClearAllRecipients() {
1350 djmaze 9.3 $this->to = array();
1351 djmaze 9.3 $this->cc = array();
1352 djmaze 9.3 $this->bcc = array();
1353 djmaze 9.3 }
1354 djmaze 9.3  
1355 djmaze 9.3 /**
1356 djmaze 9.3 * Clears all previously set filesystem, string, and binary
1357 djmaze 9.3 * attachments. Returns void.
1358 djmaze 9.3 * @return void
1359 djmaze 9.3 */
1360 djmaze 9.3 function ClearAttachments() {
1361 djmaze 9.3 $this->attachment = array();
1362 djmaze 9.3 }
1363 djmaze 9.3  
1364 djmaze 9.3 /**
1365 djmaze 9.3 * Clears all custom headers. Returns void.
1366 djmaze 9.3 * @return void
1367 djmaze 9.3 */
1368 djmaze 9.3 function ClearCustomHeaders() {
1369 djmaze 9.3 $this->CustomHeader = array();
1370 djmaze 9.3 }
1371 djmaze 9.3  
1372 djmaze 9.3  
1373 djmaze 9.3 /////////////////////////////////////////////////
1374 djmaze 9.3 // MISCELLANEOUS METHODS
1375 djmaze 9.3 /////////////////////////////////////////////////
1376 djmaze 9.3  
1377 djmaze 9.3 /**
1378 djmaze 9.3 * Adds the error message to the error container.
1379 djmaze 9.3 * Returns void.
1380 djmaze 9.3 * @access private
1381 djmaze 9.3 * @return void
1382 djmaze 9.3 */
1383 djmaze 9.3 function SetError($msg) {
1384 djmaze 9.3 $this->error_count++;
1385 djmaze 9.3 $this->ErrorInfo = $msg;
1386 djmaze 9.3 }
1387 djmaze 9.3  
1388 djmaze 9.3 /**
1389 nanocaio 9.9 * Returns the proper RFC 822 formatted date.
1390 djmaze 9.3 * @access private
1391 djmaze 9.3 * @return string
1392 djmaze 9.3 */
1393 djmaze 9.3 function RFCDate() {
1394 djmaze 9.3 $tz = date('Z');
1395 djmaze 9.3 $tzs = ($tz < 0) ? '-' : '+';
1396 djmaze 9.3 $tz = abs($tz);
1397 djmaze 9.3 $tz = ($tz/3600)*100 + ($tz%3600)/60;
1398 djmaze 9.3 $result = sprintf('%s %s%04d', date('D, j M Y H:i:s'), $tzs, $tz);
1399 djmaze 9.3  
1400 djmaze 9.3 return $result;
1401 djmaze 9.3 }
1402 djmaze 9.3  
1403 djmaze 9.3 /**
1404 nanocaio 9.9 * Returns the appropriate server variable. Should work with both
1405 nanocaio 9.9 * PHP 4.1.0+ as well as older versions. Returns an empty string
1406 djmaze 9.3 * if nothing is found.
1407 djmaze 9.3 * @access private
1408 djmaze 9.3 * @return mixed
1409 djmaze 9.3 */
1410 djmaze 9.3 function ServerVar($varName) {
1411 djmaze 9.3 if(!isset($_SERVER))
1412 djmaze 9.3 {
1413 djmaze 9.3 global $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
1414 djmaze 9.3 $_SERVER = $HTTP_SERVER_VARS;
1415 djmaze 9.3 if(!isset($_SERVER['REMOTE_ADDR']))
1416 djmaze 9.3 $_SERVER = $HTTP_ENV_VARS; // must be Apache
1417 djmaze 9.3 }
1418 nanocaio 9.9  
1419 djmaze 9.3 if(isset($_SERVER[$varName]))
1420 djmaze 9.3 return $_SERVER[$varName];
1421 djmaze 9.3 else
1422 trevor 9.4 return '';
1423 djmaze 9.3 }
1424 djmaze 9.3  
1425 djmaze 9.3 /**
1426 djmaze 9.3 * Returns the server hostname or 'localhost.localdomain' if unknown.
1427 djmaze 9.3 * @access private
1428 djmaze 9.3 * @return string
1429 djmaze 9.3 */
1430 djmaze 9.3 function ServerHostname() {
1431 djmaze 9.3 if ($this->Hostname != '')
1432 djmaze 9.3 $result = $this->Hostname;
1433 djmaze 9.3 elseif ($this->ServerVar('SERVER_NAME') != '')
1434 djmaze 9.3 $result = $this->ServerVar('SERVER_NAME');
1435 djmaze 9.3 else
1436 djmaze 9.3 $result = 'localhost.localdomain';
1437 djmaze 9.3  
1438 djmaze 9.3 return $result;
1439 djmaze 9.3 }
1440 djmaze 9.3  
1441 djmaze 9.3 /**
1442 djmaze 9.3 * Returns a message in the appropriate language.
1443 djmaze 9.3 * @access private
1444 djmaze 9.3 * @return string
1445 djmaze 9.3 */
1446 djmaze 9.3 function Lang($key) {
1447 djmaze 9.3 /*
1448 djmaze 9.3 if(count($this->language) < 1)
1449 djmaze 9.3 $this->SetLanguage(); // set the default language
1450 djmaze 9.3 */
1451 djmaze 9.3 if(isset($this->language[$key]))
1452 djmaze 9.3 return $this->language[$key];
1453 djmaze 9.3 else
1454 djmaze 9.3 return 'function Lang:Language string failed to load: ' . $key;
1455 djmaze 9.3 }
1456 nanocaio 9.9  
1457 djmaze 9.3 /**
1458 djmaze 9.3 * Returns true if an error occurred.
1459 djmaze 9.3 * @return bool
1460 djmaze 9.3 */
1461 djmaze 9.3 function IsError() {
1462 djmaze 9.3 return ($this->error_count > 0);
1463 djmaze 9.3 }
1464 djmaze 9.3  
1465 djmaze 9.3 /**
1466 nanocaio 9.9 * Changes every end of line from CR or LF to CRLF.
1467 djmaze 9.3 * @access private
1468 djmaze 9.3 * @return string
1469 djmaze 9.3 */
1470 djmaze 9.3 function FixEOL($str) {
1471 djmaze 9.3 $str = str_replace("\r\n", "\n", $str);
1472 djmaze 9.3 $str = str_replace("\r", "\n", $str);
1473 djmaze 9.3 $str = str_replace("\n", $this->LE, $str);
1474 djmaze 9.3 return $str;
1475 djmaze 9.3 }
1476 djmaze 9.3  
1477 djmaze 9.3 /**
1478 nanocaio 9.9 * Adds a custom header.
1479 djmaze 9.3 * @return void
1480 djmaze 9.3 */
1481 djmaze 9.3 function AddCustomHeader($custom_header) {
1482 trevor 9.4 $this->CustomHeader[] = explode(':', $custom_header, 2);
1483 djmaze 9.3 }
1484 djmaze 1.1 }
1485 djmaze 1.7  
1486 djmaze 1.7 global $CLASS;
1487 djmaze 1.7 $CLASS['mail'] = new PHPMailer();


Code Credits - Privacy Policy