blob: b84518bbdacb0d8f438a9ed8162035f7c89e32cb [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev1bd3d882011-12-22 15:38:20 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev1bd3d882011-12-22 15:38:20 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * CodeIgniter Email Class
31 *
32 * Permits email to be sent using Mail, Sendmail, or SMTP.
33 *
34 * @package CodeIgniter
35 * @subpackage Libraries
36 * @category Libraries
Derek Jonesf4a4bd82011-10-20 12:18:42 -050037 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000038 * @link http://codeigniter.com/user_guide/libraries/email.html
39 */
trita15dd4f2011-11-23 07:40:05 -050040class CI_Email {
Derek Allard2067d1a2008-11-13 22:59:24 +000041
Andrey Andreev597ea272012-11-01 22:56:26 +020042 /**
43 * Used as the User-Agent and X-Mailer headers' value.
44 *
45 * @var string
46 */
Andrey Andreev59c5b532012-03-01 14:09:51 +020047 public $useragent = 'CodeIgniter';
Andrey Andreev50814092012-03-01 12:36:12 +020048
Andrey Andreev597ea272012-11-01 22:56:26 +020049 /**
50 * Path to the Sendmail binary.
51 *
52 * @var string
53 */
54 public $mailpath = '/usr/sbin/sendmail'; // Sendmail path
55
56 /**
57 * Which method to use for sending e-mails.
58 *
59 * @var string 'mail', 'sendmail' or 'smtp'
60 */
61 public $protocol = 'mail'; // mail/sendmail/smtp
62
63 /**
64 * STMP Server host
65 *
66 * @var string
67 */
68 public $smtp_host = '';
69
70 /**
71 * SMTP Username
72 *
73 * @var string
74 */
75 public $smtp_user = '';
76
77 /**
78 * SMTP Password
79 *
80 * @var string
81 */
82 public $smtp_pass = '';
83
84 /**
85 * SMTP Server port
86 *
87 * @var int
88 */
89 public $smtp_port = 25;
90
91 /**
92 * SMTP connection timeout in seconds
93 *
94 * @var int
95 */
96 public $smtp_timeout = 5;
vlakofff3994252013-02-19 01:45:23 +010097
nisheeth-barthwalcf225572013-02-18 01:08:04 +053098 /**
nisheeth-barthwal59209de2013-02-18 17:02:13 +053099 * SMTP persistent connection
100 *
101 * @var bool
102 */
103 public $smtp_keepalive = FALSE;
Andrey Andreev597ea272012-11-01 22:56:26 +0200104
105 /**
106 * SMTP Encryption
107 *
Andrey Andreev89b67b42013-03-12 19:34:23 +0200108 * @var string empty, 'tls' or 'ssl'
Andrey Andreev597ea272012-11-01 22:56:26 +0200109 */
Andrey Andreev89b67b42013-03-12 19:34:23 +0200110 public $smtp_crypto = '';
Andrey Andreev597ea272012-11-01 22:56:26 +0200111
112 /**
113 * Whether to apply word-wrapping to the message body.
114 *
115 * @var bool
116 */
117 public $wordwrap = TRUE;
118
119 /**
120 * Number of characters to wrap at.
121 *
122 * @see CI_Email::$wordwrap
123 * @var int
124 */
125 public $wrapchars = 76;
126
127 /**
128 * Message format.
129 *
130 * @var string 'text' or 'html'
131 */
132 public $mailtype = 'text';
133
134 /**
135 * Character set (default: utf-8)
136 *
137 * @var string
138 */
139 public $charset = 'utf-8';
140
141 /**
142 * Multipart message
143 *
144 * @var string 'mixed' (in the body) or 'related' (separate)
145 */
146 public $multipart = 'mixed'; // "mixed" (in the body) or "related" (separate)
147
148 /**
149 * Alternative message (for HTML messages only)
150 *
151 * @var string
152 */
153 public $alt_message = '';
154
155 /**
156 * Whether to validate e-mail addresses.
157 *
158 * @var bool
159 */
160 public $validate = FALSE;
161
162 /**
163 * X-Priority header value.
164 *
165 * @var int 1-5
166 */
167 public $priority = 3; // Default priority (1 - 5)
168
169 /**
170 * Newline character sequence.
171 * Use "\r\n" to comply with RFC 822.
172 *
173 * @link http://www.ietf.org/rfc/rfc822.txt
174 * @var string "\r\n" or "\n"
175 */
176 public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
177
178 /**
179 * CRLF character sequence
180 *
181 * RFC 2045 specifies that for 'quoted-printable' encoding,
182 * "\r\n" must be used. However, it appears that some servers
183 * (even on the receiving end) don't handle it properly and
184 * switching to "\n", while improper, is the only solution
185 * that seems to work for all environments.
186 *
187 * @link http://www.ietf.org/rfc/rfc822.txt
188 * @var string
189 */
190 public $crlf = "\n";
191
192 /**
193 * Whether to use Delivery Status Notification.
194 *
195 * @var bool
196 */
197 public $dsn = FALSE;
198
199 /**
200 * Whether to send multipart alternatives.
201 * Yahoo! doesn't seem to like these.
202 *
203 * @var bool
204 */
205 public $send_multipart = TRUE;
206
207 /**
208 * Whether to send messages to BCC recipients in batches.
209 *
210 * @var bool
211 */
212 public $bcc_batch_mode = FALSE;
213
214 /**
215 * BCC Batch max number size.
216 *
217 * @see CI_Email::$bcc_batch_mode
218 * @var int
219 */
220 public $bcc_batch_size = 200;
221
222 // --------------------------------------------------------------------
223
224 /**
225 * Whether PHP is running in safe mode. Initialized by the class constructor.
226 *
227 * @var bool
228 */
Andrey Andreev50814092012-03-01 12:36:12 +0200229 protected $_safe_mode = FALSE;
Andrey Andreev597ea272012-11-01 22:56:26 +0200230
231 /**
232 * Subject header
233 *
234 * @var string
235 */
Andrey Andreev50814092012-03-01 12:36:12 +0200236 protected $_subject = '';
Andrey Andreev597ea272012-11-01 22:56:26 +0200237
238 /**
239 * Message body
240 *
241 * @var string
242 */
Andrey Andreev50814092012-03-01 12:36:12 +0200243 protected $_body = '';
Andrey Andreev597ea272012-11-01 22:56:26 +0200244
245 /**
246 * Final message body to be sent.
247 *
248 * @var string
249 */
Andrey Andreev50814092012-03-01 12:36:12 +0200250 protected $_finalbody = '';
Andrey Andreev597ea272012-11-01 22:56:26 +0200251
252 /**
253 * multipart/alternative boundary
254 *
255 * @var string
256 */
Andrey Andreev50814092012-03-01 12:36:12 +0200257 protected $_alt_boundary = '';
Andrey Andreev597ea272012-11-01 22:56:26 +0200258
259 /**
260 * Attachment boundary
261 *
262 * @var string
263 */
Andrey Andreev50814092012-03-01 12:36:12 +0200264 protected $_atc_boundary = '';
Andrey Andreev597ea272012-11-01 22:56:26 +0200265
266 /**
267 * Final headers to send
268 *
269 * @var string
270 */
Andrey Andreev50814092012-03-01 12:36:12 +0200271 protected $_header_str = '';
Andrey Andreev597ea272012-11-01 22:56:26 +0200272
273 /**
274 * SMTP Connection socket placeholder
275 *
276 * @var resource
277 */
Andrey Andreev50814092012-03-01 12:36:12 +0200278 protected $_smtp_connect = '';
Andrey Andreev597ea272012-11-01 22:56:26 +0200279
280 /**
281 * Mail encoding
282 *
283 * @var string '8bit' or '7bit'
284 */
Andrey Andreev50814092012-03-01 12:36:12 +0200285 protected $_encoding = '8bit';
Andrey Andreev597ea272012-11-01 22:56:26 +0200286
287 /**
288 * Whether to perform SMTP authentication
289 *
290 * @var bool
291 */
Andrey Andreev50814092012-03-01 12:36:12 +0200292 protected $_smtp_auth = FALSE;
Andrey Andreev597ea272012-11-01 22:56:26 +0200293
294 /**
295 * Whether to send a Reply-To header
296 *
297 * @var bool
298 */
Andrey Andreev50814092012-03-01 12:36:12 +0200299 protected $_replyto_flag = FALSE;
Andrey Andreev597ea272012-11-01 22:56:26 +0200300
301 /**
302 * Debug messages
303 *
304 * @see CI_Email::print_debugger()
305 * @var string
306 */
Andrey Andreev50814092012-03-01 12:36:12 +0200307 protected $_debug_msg = array();
Andrey Andreev597ea272012-11-01 22:56:26 +0200308
309 /**
310 * Recipients
311 *
312 * @var string[]
313 */
Andrey Andreev50814092012-03-01 12:36:12 +0200314 protected $_recipients = array();
Andrey Andreev597ea272012-11-01 22:56:26 +0200315
316 /**
317 * CC Recipients
318 *
319 * @var string[]
320 */
Andrey Andreev50814092012-03-01 12:36:12 +0200321 protected $_cc_array = array();
Andrey Andreev597ea272012-11-01 22:56:26 +0200322
323 /**
324 * BCC Recipients
325 *
326 * @var string[]
327 */
Andrey Andreev50814092012-03-01 12:36:12 +0200328 protected $_bcc_array = array();
Andrey Andreev597ea272012-11-01 22:56:26 +0200329
330 /**
331 * Message headers
332 *
333 * @var string[]
334 */
Andrey Andreev50814092012-03-01 12:36:12 +0200335 protected $_headers = array();
Andrey Andreev597ea272012-11-01 22:56:26 +0200336
337 /**
338 * Attachment data
339 *
340 * @var array
341 */
Andrey Andreevb8f9a152012-10-27 01:36:51 +0300342 protected $_attachments = array();
Andrey Andreev597ea272012-11-01 22:56:26 +0200343
344 /**
345 * Valid $protocol values
346 *
347 * @see CI_Email::$protocol
348 * @var string[]
349 */
Andrey Andreev50814092012-03-01 12:36:12 +0200350 protected $_protocols = array('mail', 'sendmail', 'smtp');
Andrey Andreev597ea272012-11-01 22:56:26 +0200351
352 /**
353 * Base charsets
354 *
355 * Character sets valid for 7-bit encoding,
356 * excluding language suffix.
357 *
358 * @var string[]
359 */
360 protected $_base_charsets = array('us-ascii', 'iso-2022-');
361
362 /**
363 * Bit depths
364 *
365 * Valid mail encodings
366 *
367 * @see CI_Email::$_encoding
368 * @var string[]
369 */
Andrey Andreev50814092012-03-01 12:36:12 +0200370 protected $_bit_depths = array('7bit', '8bit');
Andrey Andreev597ea272012-11-01 22:56:26 +0200371
372 /**
373 * $priority translations
374 *
375 * Actual values to send with the X-Priority header
376 *
377 * @var string[]
378 */
Andrey Andreev50814092012-03-01 12:36:12 +0200379 protected $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
Derek Allard2067d1a2008-11-13 22:59:24 +0000380
Andrey Andreev597ea272012-11-01 22:56:26 +0200381 // --------------------------------------------------------------------
382
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 /**
384 * Constructor - Sets Email Preferences
385 *
386 * The constructor can be passed an array of config values
Andrey Andreev56454792012-05-17 14:32:19 +0300387 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300388 * @param array $config = array()
Andrey Andreev56454792012-05-17 14:32:19 +0300389 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000390 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000391 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 {
Andrey Andreev925dd902012-10-19 11:06:31 +0300393 $this->charset = config_item('charset');
Andrey Andreev9f44c212012-10-10 16:07:17 +0300394
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 if (count($config) > 0)
396 {
397 $this->initialize($config);
398 }
399 else
400 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100401 $this->_smtp_auth = ! ($this->smtp_user === '' && $this->smtp_pass === '');
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 }
403
Andrey Andreev5932a732013-09-13 14:45:53 +0300404 $this->_safe_mode = ( ! is_php('5.4') && (bool) @ini_get('safe_mode'));
Andrey Andreev925dd902012-10-19 11:06:31 +0300405 $this->charset = strtoupper($this->charset);
406
Andrey Andreev59c5b532012-03-01 14:09:51 +0200407 log_message('debug', 'Email Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 }
nisheeth-barthwal59209de2013-02-18 17:02:13 +0530409
nisheeth-barthwalcf225572013-02-18 01:08:04 +0530410 // --------------------------------------------------------------------
vlakofff3994252013-02-19 01:45:23 +0100411
nisheeth-barthwalcf225572013-02-18 01:08:04 +0530412 /**
nisheeth-barthwal59209de2013-02-18 17:02:13 +0530413 * Destructor - Releases Resources
414 *
415 * @return void
416 */
417 public function __destruct()
418 {
nisheeth-barthwal758f40c2013-02-18 17:18:51 +0530419 if (is_resource($this->_smtp_connect))
420 {
nisheeth-barthwal59209de2013-02-18 17:02:13 +0530421 $this->_send_command('quit');
nisheeth-barthwal758f40c2013-02-18 17:18:51 +0530422 }
nisheeth-barthwal59209de2013-02-18 17:02:13 +0530423 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000424
425 // --------------------------------------------------------------------
426
427 /**
428 * Initialize preferences
429 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 * @param array
Andrew Podner4296a652012-12-17 07:51:15 -0500431 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000433 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000434 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 foreach ($config as $key => $val)
436 {
437 if (isset($this->$key))
438 {
439 $method = 'set_'.$key;
440
441 if (method_exists($this, $method))
442 {
443 $this->$method($val);
444 }
445 else
446 {
447 $this->$key = $val;
448 }
449 }
450 }
Eric Barnes6113f542010-12-29 13:36:12 -0500451 $this->clear();
Derek Allard2067d1a2008-11-13 22:59:24 +0000452
Alex Bilbied261b1e2012-06-02 11:12:16 +0100453 $this->_smtp_auth = ! ($this->smtp_user === '' && $this->smtp_pass === '');
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000454
455 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 }
Barry Mienydd671972010-10-04 16:33:58 +0200457
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 // --------------------------------------------------------------------
459
460 /**
461 * Initialize the Email Data
462 *
Bo-Yi Wu83320eb2011-09-15 13:28:02 +0800463 * @param bool
Andrew Podner4296a652012-12-17 07:51:15 -0500464 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000466 public function clear($clear_attachments = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200468 $this->_subject = '';
469 $this->_body = '';
470 $this->_finalbody = '';
471 $this->_header_str = '';
472 $this->_replyto_flag = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 $this->_recipients = array();
Derek Jonesd1606352010-09-01 11:16:07 -0500474 $this->_cc_array = array();
475 $this->_bcc_array = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 $this->_headers = array();
477 $this->_debug_msg = array();
478
Mickey Wubfc1cad2012-05-31 22:28:40 -0700479 $this->set_header('User-Agent', $this->useragent);
480 $this->set_header('Date', $this->_set_date());
Derek Allard2067d1a2008-11-13 22:59:24 +0000481
482 if ($clear_attachments !== FALSE)
483 {
Andrey Andreevb8f9a152012-10-27 01:36:51 +0300484 $this->_attachments = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 }
Eric Barnes6113f542010-12-29 13:36:12 -0500486
Greg Akera769deb2010-11-10 15:47:29 -0600487 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 }
Barry Mienydd671972010-10-04 16:33:58 +0200489
Derek Allard2067d1a2008-11-13 22:59:24 +0000490 // --------------------------------------------------------------------
491
492 /**
493 * Set FROM
494 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300495 * @param string $from
496 * @param string $name
497 * @param string $return_path = NULL Return-Path
Andrew Podner4296a652012-12-17 07:51:15 -0500498 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 */
Andrey Andreev925dd902012-10-19 11:06:31 +0300500 public function from($from, $name = '', $return_path = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000501 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200502 if (preg_match('/\<(.*)\>/', $from, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200504 $from = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000505 }
506
507 if ($this->validate)
508 {
509 $this->validate_email($this->_str_to_array($from));
Andrey Andreevccd01c72012-10-05 17:12:55 +0300510 if ($return_path)
Melounek58dfc082012-06-29 08:43:47 +0200511 {
512 $this->validate_email($this->_str_to_array($return_path));
513 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 }
515
516 // prepare the display name
Alex Bilbied261b1e2012-06-02 11:12:16 +0100517 if ($name !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000518 {
519 // only use Q encoding if there are characters that would require it
520 if ( ! preg_match('/[\200-\377]/', $name))
521 {
522 // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
Derek Jonesc630bcf2008-11-17 21:09:45 +0000523 $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"';
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 }
525 else
526 {
Andrey Andreev925dd902012-10-19 11:06:31 +0300527 $name = $this->_prep_q_encoding($name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000528 }
529 }
530
Mickey Wubfc1cad2012-05-31 22:28:40 -0700531 $this->set_header('From', $name.' <'.$from.'>');
Melounek58dfc082012-06-29 08:43:47 +0200532
Andrey Andreev925dd902012-10-19 11:06:31 +0300533 isset($return_path) OR $return_path = $from;
Melounek58dfc082012-06-29 08:43:47 +0200534 $this->set_header('Return-Path', '<'.$return_path.'>');
Eric Barnes6113f542010-12-29 13:36:12 -0500535
Greg Akera769deb2010-11-10 15:47:29 -0600536 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 }
Barry Mienydd671972010-10-04 16:33:58 +0200538
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 // --------------------------------------------------------------------
540
541 /**
542 * Set Reply-to
543 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000544 * @param string
545 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500546 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000547 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000548 public function reply_to($replyto, $name = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200550 if (preg_match('/\<(.*)\>/', $replyto, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200552 $replyto = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 }
554
555 if ($this->validate)
556 {
557 $this->validate_email($this->_str_to_array($replyto));
558 }
559
Alex Bilbied261b1e2012-06-02 11:12:16 +0100560 if ($name === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 {
562 $name = $replyto;
563 }
564
Andrey Andreev3dad2e72012-06-14 15:10:56 +0300565 if (strpos($name, '"') !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000566 {
567 $name = '"'.$name.'"';
568 }
569
Mickey Wubfc1cad2012-05-31 22:28:40 -0700570 $this->set_header('Reply-To', $name.' <'.$replyto.'>');
Derek Allard2067d1a2008-11-13 22:59:24 +0000571 $this->_replyto_flag = TRUE;
Greg Akera769deb2010-11-10 15:47:29 -0600572
573 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000574 }
Barry Mienydd671972010-10-04 16:33:58 +0200575
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 // --------------------------------------------------------------------
577
578 /**
579 * Set Recipients
580 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500582 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000583 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000584 public function to($to)
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 {
586 $to = $this->_str_to_array($to);
587 $to = $this->clean_email($to);
588
589 if ($this->validate)
590 {
591 $this->validate_email($to);
592 }
593
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200594 if ($this->_get_protocol() !== 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 {
Mickey Wubfc1cad2012-05-31 22:28:40 -0700596 $this->set_header('To', implode(', ', $to));
Derek Allard2067d1a2008-11-13 22:59:24 +0000597 }
598
Andrey Andreev8a7078b2012-10-17 10:52:49 +0300599 $this->_recipients = $to;
Eric Barnes6113f542010-12-29 13:36:12 -0500600
Greg Akera769deb2010-11-10 15:47:29 -0600601 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 }
Barry Mienydd671972010-10-04 16:33:58 +0200603
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 // --------------------------------------------------------------------
605
606 /**
607 * Set CC
608 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000609 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500610 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000611 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000612 public function cc($cc)
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 {
Andrey Andreev56454792012-05-17 14:32:19 +0300614 $cc = $this->clean_email($this->_str_to_array($cc));
Derek Allard2067d1a2008-11-13 22:59:24 +0000615
616 if ($this->validate)
617 {
618 $this->validate_email($cc);
619 }
620
Mickey Wubfc1cad2012-05-31 22:28:40 -0700621 $this->set_header('Cc', implode(', ', $cc));
Derek Allard2067d1a2008-11-13 22:59:24 +0000622
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200623 if ($this->_get_protocol() === 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +0000624 {
625 $this->_cc_array = $cc;
626 }
Eric Barnes6113f542010-12-29 13:36:12 -0500627
Greg Akera769deb2010-11-10 15:47:29 -0600628 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000629 }
Barry Mienydd671972010-10-04 16:33:58 +0200630
Derek Allard2067d1a2008-11-13 22:59:24 +0000631 // --------------------------------------------------------------------
632
633 /**
634 * Set BCC
635 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000636 * @param string
637 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500638 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000639 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000640 public function bcc($bcc, $limit = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000641 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100642 if ($limit !== '' && is_numeric($limit))
Derek Allard2067d1a2008-11-13 22:59:24 +0000643 {
644 $this->bcc_batch_mode = TRUE;
645 $this->bcc_batch_size = $limit;
646 }
647
Andrey Andreev56454792012-05-17 14:32:19 +0300648 $bcc = $this->clean_email($this->_str_to_array($bcc));
Derek Allard2067d1a2008-11-13 22:59:24 +0000649
650 if ($this->validate)
651 {
652 $this->validate_email($bcc);
653 }
654
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200655 if ($this->_get_protocol() === 'smtp' OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size))
Derek Allard2067d1a2008-11-13 22:59:24 +0000656 {
657 $this->_bcc_array = $bcc;
658 }
659 else
660 {
Mickey Wubfc1cad2012-05-31 22:28:40 -0700661 $this->set_header('Bcc', implode(', ', $bcc));
Derek Allard2067d1a2008-11-13 22:59:24 +0000662 }
Eric Barnes6113f542010-12-29 13:36:12 -0500663
Greg Akera769deb2010-11-10 15:47:29 -0600664 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000665 }
Barry Mienydd671972010-10-04 16:33:58 +0200666
Derek Allard2067d1a2008-11-13 22:59:24 +0000667 // --------------------------------------------------------------------
668
669 /**
670 * Set Email Subject
671 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000672 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500673 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000674 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000675 public function subject($subject)
Derek Allard2067d1a2008-11-13 22:59:24 +0000676 {
677 $subject = $this->_prep_q_encoding($subject);
Mickey Wubfc1cad2012-05-31 22:28:40 -0700678 $this->set_header('Subject', $subject);
Greg Akera769deb2010-11-10 15:47:29 -0600679 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000680 }
Barry Mienydd671972010-10-04 16:33:58 +0200681
Derek Allard2067d1a2008-11-13 22:59:24 +0000682 // --------------------------------------------------------------------
683
684 /**
685 * Set Body
686 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000687 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500688 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000689 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000690 public function message($body)
Derek Allard2067d1a2008-11-13 22:59:24 +0000691 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200692 $this->_body = rtrim(str_replace("\r", '', $body));
diegorivera33c32802011-10-19 02:56:15 -0200693
Andrey Andreevaf728622011-10-20 10:11:59 +0300694 /* strip slashes only if magic quotes is ON
695 if we do it with magic quotes OFF, it strips real, user-inputted chars.
696
697 NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
698 it will probably not exist in future versions at all.
699 */
700 if ( ! is_php('5.4') && get_magic_quotes_gpc())
diegorivera9fca6152011-10-19 11:18:45 -0200701 {
diegorivera33c32802011-10-19 02:56:15 -0200702 $this->_body = stripslashes($this->_body);
diegorivera9fca6152011-10-19 11:18:45 -0200703 }
diegorivera33c32802011-10-19 02:56:15 -0200704
Greg Akera769deb2010-11-10 15:47:29 -0600705 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000706 }
Barry Mienydd671972010-10-04 16:33:58 +0200707
Derek Allard2067d1a2008-11-13 22:59:24 +0000708 // --------------------------------------------------------------------
709
710 /**
711 * Assign file attachments
712 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300713 * @param string $filename
714 * @param string $disposition = 'attachment'
715 * @param string $newname = NULL
716 * @param string $mime = ''
Andrew Podner4296a652012-12-17 07:51:15 -0500717 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000718 */
Matteo Matteic3b36f42012-03-26 10:27:17 +0200719 public function attach($filename, $disposition = '', $newname = NULL, $mime = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000720 {
Petr Heralecky300e3f02014-01-10 11:49:11 +0100721 if ($mime === '')
722 {
723 if ( ! file_exists($filename))
724 {
725 $this->_set_error_message('lang:email_attachment_missing', $filename);
726 return FALSE;
727 }
728
729 if ( ! $fp = fopen($filename, FOPEN_READ))
730 {
731 $this->_set_error_message('lang:email_attachment_unreadable', $filename);
732 return FALSE;
733 }
734 $file_content = stream_get_contents($fp);
735 $mime = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
736 }
737 else
738 {
739 $file_content =& $filename; // buffered file
740 }
741
Andrey Andreevb8f9a152012-10-27 01:36:51 +0300742 $this->_attachments[] = array(
743 'name' => array($filename, $newname),
744 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters
Petr Heralecky300e3f02014-01-10 11:49:11 +0100745 'type' => $mime,
746 'content' => chunk_split(base64_encode($file_content))
Andrey Andreevb8f9a152012-10-27 01:36:51 +0300747 );
Petr Heralecky300e3f02014-01-10 11:49:11 +0100748
749 fclose($fp);
750
Greg Akera769deb2010-11-10 15:47:29 -0600751 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000752 }
Petr Heralecky300e3f02014-01-10 11:49:11 +0100753
754 // --------------------------------------------------------------------
755
756 /**
757 * Sets and return id of attachment (useful for attached inline pictures)
758 *
759 * @param string
760 * @return string
761 */
762 public function attach_cid($filename)
763 {
764 if($this->multipart != 'related')
765 {
766 $this->multipart = 'related'; // Thunderbird need this for inline images
767 }
768 foreach($this->_attachments as $ind => $attach)
769 {
770 if($attach['name'][0] == $filename)
771 {
772 $this->_attachments[$ind]['cid'] = uniqid(basename($this->_attachments[$ind]['name'][0]) . "@");
773 return $this->_attachments[$ind]['cid'];
774 }
775 }
776 return FALSE;
777 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000778
779 // --------------------------------------------------------------------
780
781 /**
782 * Add a Header Item
783 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000784 * @param string
785 * @param string
786 * @return void
787 */
Mickey Wubfc1cad2012-05-31 22:28:40 -0700788 public function set_header($header, $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000789 {
florisluitenf55d5142013-06-07 17:20:06 +0300790 $this->_headers[$header] = str_replace(array("\n", "\r"), '', $value);
Derek Allard2067d1a2008-11-13 22:59:24 +0000791 }
Barry Mienydd671972010-10-04 16:33:58 +0200792
Derek Allard2067d1a2008-11-13 22:59:24 +0000793 // --------------------------------------------------------------------
794
795 /**
796 * Convert a String to an Array
797 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000798 * @param string
799 * @return array
800 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600801 protected function _str_to_array($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000802 {
803 if ( ! is_array($email))
804 {
Andrey Andreev56454792012-05-17 14:32:19 +0300805 return (strpos($email, ',') !== FALSE)
806 ? preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY)
807 : (array) trim($email);
Derek Allard2067d1a2008-11-13 22:59:24 +0000808 }
Andrey Andreev56454792012-05-17 14:32:19 +0300809
Derek Allard2067d1a2008-11-13 22:59:24 +0000810 return $email;
811 }
Barry Mienydd671972010-10-04 16:33:58 +0200812
Derek Allard2067d1a2008-11-13 22:59:24 +0000813 // --------------------------------------------------------------------
814
815 /**
816 * Set Multipart Value
817 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000818 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500819 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000820 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000821 public function set_alt_message($str = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000822 {
Dan Horrigand0ddeaf2011-08-21 09:07:27 -0400823 $this->alt_message = (string) $str;
Greg Akera769deb2010-11-10 15:47:29 -0600824 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000825 }
Barry Mienydd671972010-10-04 16:33:58 +0200826
Derek Allard2067d1a2008-11-13 22:59:24 +0000827 // --------------------------------------------------------------------
828
829 /**
830 * Set Mailtype
831 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000832 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500833 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000834 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000835 public function set_mailtype($type = 'text')
Derek Allard2067d1a2008-11-13 22:59:24 +0000836 {
Andrey Andreev56454792012-05-17 14:32:19 +0300837 $this->mailtype = ($type === 'html') ? 'html' : 'text';
Greg Akera769deb2010-11-10 15:47:29 -0600838 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000839 }
Barry Mienydd671972010-10-04 16:33:58 +0200840
Derek Allard2067d1a2008-11-13 22:59:24 +0000841 // --------------------------------------------------------------------
nisheeth-barthwalcf225572013-02-18 01:08:04 +0530842
Derek Allard2067d1a2008-11-13 22:59:24 +0000843 /**
844 * Set Wordwrap
845 *
Dan Horrigan628e6602011-08-21 09:08:31 -0400846 * @param bool
Andrew Podner4296a652012-12-17 07:51:15 -0500847 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000848 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000849 public function set_wordwrap($wordwrap = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000850 {
Dan Horrigan628e6602011-08-21 09:08:31 -0400851 $this->wordwrap = (bool) $wordwrap;
Greg Akera769deb2010-11-10 15:47:29 -0600852 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000853 }
Barry Mienydd671972010-10-04 16:33:58 +0200854
Derek Allard2067d1a2008-11-13 22:59:24 +0000855 // --------------------------------------------------------------------
856
857 /**
858 * Set Protocol
859 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000860 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500861 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000862 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000863 public function set_protocol($protocol = 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000864 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200865 $this->protocol = in_array($protocol, $this->_protocols, TRUE) ? strtolower($protocol) : 'mail';
Greg Akera769deb2010-11-10 15:47:29 -0600866 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000867 }
Barry Mienydd671972010-10-04 16:33:58 +0200868
Derek Allard2067d1a2008-11-13 22:59:24 +0000869 // --------------------------------------------------------------------
870
871 /**
872 * Set Priority
873 *
Andrey Andreev081c9462012-03-01 12:58:11 +0200874 * @param int
Andrew Podner4296a652012-12-17 07:51:15 -0500875 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000876 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000877 public function set_priority($n = 3)
Derek Allard2067d1a2008-11-13 22:59:24 +0000878 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200879 $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3;
Greg Akera769deb2010-11-10 15:47:29 -0600880 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000881 }
Barry Mienydd671972010-10-04 16:33:58 +0200882
Derek Allard2067d1a2008-11-13 22:59:24 +0000883 // --------------------------------------------------------------------
884
885 /**
886 * Set Newline Character
887 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000888 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500889 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000890 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000891 public function set_newline($newline = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000892 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200893 $this->newline = in_array($newline, array("\n", "\r\n", "\r")) ? $newline : "\n";
Greg Akera769deb2010-11-10 15:47:29 -0600894 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000895 }
Barry Mienydd671972010-10-04 16:33:58 +0200896
Derek Allard2067d1a2008-11-13 22:59:24 +0000897 // --------------------------------------------------------------------
898
899 /**
900 * Set CRLF
901 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000902 * @param string
Andrew Podner4296a652012-12-17 07:51:15 -0500903 * @return CI_Email
Derek Allard2067d1a2008-11-13 22:59:24 +0000904 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000905 public function set_crlf($crlf = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000906 {
Andrey Andreev76f15c92012-03-01 13:05:07 +0200907 $this->crlf = ($crlf !== "\n" && $crlf !== "\r\n" && $crlf !== "\r") ? "\n" : $crlf;
Greg Akera769deb2010-11-10 15:47:29 -0600908 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000909 }
Barry Mienydd671972010-10-04 16:33:58 +0200910
Derek Allard2067d1a2008-11-13 22:59:24 +0000911 // --------------------------------------------------------------------
912
913 /**
914 * Set Message Boundary
915 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000916 * @return void
917 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600918 protected function _set_boundaries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000919 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200920 $this->_alt_boundary = 'B_ALT_'.uniqid(''); // multipart/alternative
921 $this->_atc_boundary = 'B_ATC_'.uniqid(''); // attachment boundary
Derek Allard2067d1a2008-11-13 22:59:24 +0000922 }
Barry Mienydd671972010-10-04 16:33:58 +0200923
Derek Allard2067d1a2008-11-13 22:59:24 +0000924 // --------------------------------------------------------------------
925
926 /**
927 * Get the Message ID
928 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000929 * @return string
930 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600931 protected function _get_message_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000932 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200933 $from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']);
Andrey Andreev56454792012-05-17 14:32:19 +0300934 return '<'.uniqid('').strstr($from, '@').'>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000935 }
Barry Mienydd671972010-10-04 16:33:58 +0200936
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 // --------------------------------------------------------------------
938
939 /**
940 * Get Mail Protocol
941 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000942 * @param bool
Andrey Andreev59c5b532012-03-01 14:09:51 +0200943 * @return mixed
Derek Allard2067d1a2008-11-13 22:59:24 +0000944 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600945 protected function _get_protocol($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000946 {
947 $this->protocol = strtolower($this->protocol);
Andrey Andreev59c5b532012-03-01 14:09:51 +0200948 in_array($this->protocol, $this->_protocols, TRUE) OR $this->protocol = 'mail';
Derek Allard2067d1a2008-11-13 22:59:24 +0000949
Alex Bilbied261b1e2012-06-02 11:12:16 +0100950 if ($return === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000951 {
952 return $this->protocol;
953 }
954 }
Barry Mienydd671972010-10-04 16:33:58 +0200955
Derek Allard2067d1a2008-11-13 22:59:24 +0000956 // --------------------------------------------------------------------
957
958 /**
959 * Get Mail Encoding
960 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000961 * @param bool
962 * @return string
963 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600964 protected function _get_encoding($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000965 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200966 in_array($this->_encoding, $this->_bit_depths) OR $this->_encoding = '8bit';
Derek Allard2067d1a2008-11-13 22:59:24 +0000967
968 foreach ($this->_base_charsets as $charset)
969 {
Andrey Andreev3dad2e72012-06-14 15:10:56 +0300970 if (strpos($charset, $this->charset) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000971 {
972 $this->_encoding = '7bit';
973 }
974 }
975
Alex Bilbied261b1e2012-06-02 11:12:16 +0100976 if ($return === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000977 {
978 return $this->_encoding;
979 }
980 }
981
982 // --------------------------------------------------------------------
983
984 /**
985 * Get content type (text/html/attachment)
986 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000987 * @return string
988 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600989 protected function _get_content_type()
Derek Allard2067d1a2008-11-13 22:59:24 +0000990 {
Andrey Andreev56454792012-05-17 14:32:19 +0300991 if ($this->mailtype === 'html')
Derek Allard2067d1a2008-11-13 22:59:24 +0000992 {
Andrey Andreevb8f9a152012-10-27 01:36:51 +0300993 return (count($this->_attachments) === 0) ? 'html' : 'html-attach';
Derek Allard2067d1a2008-11-13 22:59:24 +0000994 }
Andrey Andreevb8f9a152012-10-27 01:36:51 +0300995 elseif ($this->mailtype === 'text' && count($this->_attachments) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000996 {
997 return 'plain-attach';
998 }
999 else
1000 {
1001 return 'plain';
1002 }
1003 }
Barry Mienydd671972010-10-04 16:33:58 +02001004
Derek Allard2067d1a2008-11-13 22:59:24 +00001005 // --------------------------------------------------------------------
1006
1007 /**
1008 * Set RFC 822 Date
1009 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001010 * @return string
1011 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001012 protected function _set_date()
Derek Allard2067d1a2008-11-13 22:59:24 +00001013 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001014 $timezone = date('Z');
Andrey Andreev3dad2e72012-06-14 15:10:56 +03001015 $operator = ($timezone[0] === '-') ? '-' : '+';
Derek Allard2067d1a2008-11-13 22:59:24 +00001016 $timezone = abs($timezone);
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001017 $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
Derek Allard2067d1a2008-11-13 22:59:24 +00001018
Andrey Andreev59c5b532012-03-01 14:09:51 +02001019 return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Derek Allard2067d1a2008-11-13 22:59:24 +00001020 }
Barry Mienydd671972010-10-04 16:33:58 +02001021
Derek Allard2067d1a2008-11-13 22:59:24 +00001022 // --------------------------------------------------------------------
1023
1024 /**
1025 * Mime message
1026 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001027 * @return string
1028 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001029 protected function _get_mime_message()
Derek Allard2067d1a2008-11-13 22:59:24 +00001030 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001031 return 'This is a multi-part message in MIME format.'.$this->newline.'Your email application may not support this format.';
Derek Allard2067d1a2008-11-13 22:59:24 +00001032 }
Barry Mienydd671972010-10-04 16:33:58 +02001033
Derek Allard2067d1a2008-11-13 22:59:24 +00001034 // --------------------------------------------------------------------
1035
1036 /**
1037 * Validate Email Address
1038 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001039 * @param string
1040 * @return bool
1041 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001042 public function validate_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +00001043 {
1044 if ( ! is_array($email))
1045 {
patworkb0707982011-04-08 15:10:05 +02001046 $this->_set_error_message('lang:email_must_be_array');
Derek Allard2067d1a2008-11-13 22:59:24 +00001047 return FALSE;
1048 }
1049
1050 foreach ($email as $val)
1051 {
1052 if ( ! $this->valid_email($val))
1053 {
patworkb0707982011-04-08 15:10:05 +02001054 $this->_set_error_message('lang:email_invalid_address', $val);
Derek Allard2067d1a2008-11-13 22:59:24 +00001055 return FALSE;
1056 }
1057 }
1058
1059 return TRUE;
1060 }
Barry Mienydd671972010-10-04 16:33:58 +02001061
Derek Allard2067d1a2008-11-13 22:59:24 +00001062 // --------------------------------------------------------------------
1063
1064 /**
1065 * Email Validation
1066 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001067 * @param string
1068 * @return bool
1069 */
Timothy Warrend37f0e92012-06-27 08:21:59 -04001070 public function valid_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +00001071 {
Andrey Andreev580388b2012-06-27 15:43:46 +03001072 return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
Derek Allard2067d1a2008-11-13 22:59:24 +00001073 }
Barry Mienydd671972010-10-04 16:33:58 +02001074
Derek Allard2067d1a2008-11-13 22:59:24 +00001075 // --------------------------------------------------------------------
1076
1077 /**
1078 * Clean Extended Email Address: Joe Smith <joe@smith.com>
1079 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001080 * @param string
1081 * @return string
1082 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001083 public function clean_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +00001084 {
1085 if ( ! is_array($email))
1086 {
Andrey Andreev56454792012-05-17 14:32:19 +03001087 return preg_match('/\<(.*)\>/', $email, $match) ? $match[1] : $email;
Derek Allard2067d1a2008-11-13 22:59:24 +00001088 }
1089
1090 $clean_email = array();
1091
1092 foreach ($email as $addy)
1093 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001094 $clean_email[] = preg_match('/\<(.*)\>/', $addy, $match) ? $match[1] : $addy;
Derek Allard2067d1a2008-11-13 22:59:24 +00001095 }
1096
1097 return $clean_email;
1098 }
Barry Mienydd671972010-10-04 16:33:58 +02001099
Derek Allard2067d1a2008-11-13 22:59:24 +00001100 // --------------------------------------------------------------------
1101
1102 /**
1103 * Build alternative plain text message
1104 *
Andrey Andreev8df1ae22012-10-19 11:20:54 +03001105 * Provides the raw message for use in plain-text headers of
1106 * HTML-formatted emails.
Derek Allard2067d1a2008-11-13 22:59:24 +00001107 * If the user hasn't specified his own alternative message
1108 * it creates one by stripping the HTML
1109 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001110 * @return string
1111 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001112 protected function _get_alt_message()
Derek Allard2067d1a2008-11-13 22:59:24 +00001113 {
Andrey Andreev8df1ae22012-10-19 11:20:54 +03001114 if ( ! empty($this->alt_message))
Derek Allard2067d1a2008-11-13 22:59:24 +00001115 {
Andrey Andreev8df1ae22012-10-19 11:20:54 +03001116 return ($this->wordwrap)
1117 ? $this->word_wrap($this->alt_message, 76)
1118 : $this->alt_message;
Derek Allard2067d1a2008-11-13 22:59:24 +00001119 }
1120
Andrey Andreev56454792012-05-17 14:32:19 +03001121 $body = preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match) ? $match[1] : $this->_body;
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001122 $body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
Derek Allard2067d1a2008-11-13 22:59:24 +00001123
1124 for ($i = 20; $i >= 3; $i--)
1125 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001126 $body = str_replace(str_repeat("\n", $i), "\n\n", $body);
Derek Allard2067d1a2008-11-13 22:59:24 +00001127 }
1128
GDmac9bea4be2012-10-30 06:14:19 +01001129 // Reduce multiple spaces
Andrey Andreev8a203f62012-11-02 20:40:43 +02001130 $body = preg_replace('| +|', ' ', $body);
GDmac9bea4be2012-10-30 06:14:19 +01001131
Andrey Andreev8df1ae22012-10-19 11:20:54 +03001132 return ($this->wordwrap)
1133 ? $this->word_wrap($body, 76)
1134 : $body;
Derek Allard2067d1a2008-11-13 22:59:24 +00001135 }
Barry Mienydd671972010-10-04 16:33:58 +02001136
Derek Allard2067d1a2008-11-13 22:59:24 +00001137 // --------------------------------------------------------------------
1138
1139 /**
1140 * Word Wrap
1141 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001142 * @param string
Andrey Andreev8df1ae22012-10-19 11:20:54 +03001143 * @param int line-length limit
Derek Allard2067d1a2008-11-13 22:59:24 +00001144 * @return string
1145 */
Andrey Andreev00ea2a92012-10-18 14:59:29 +03001146 public function word_wrap($str, $charlim = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +00001147 {
Andrey Andreev00ea2a92012-10-18 14:59:29 +03001148 // Set the character limit, if not already present
1149 if (empty($charlim))
Derek Allard2067d1a2008-11-13 22:59:24 +00001150 {
Andrey Andreev00ea2a92012-10-18 14:59:29 +03001151 $charlim = empty($this->wrapchars) ? 76 : $this->wrapchars;
Derek Allard2067d1a2008-11-13 22:59:24 +00001152 }
1153
Derek Allard2067d1a2008-11-13 22:59:24 +00001154 // Standardize newlines
1155 if (strpos($str, "\r") !== FALSE)
1156 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +02001157 $str = str_replace(array("\r\n", "\r"), "\n", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001158 }
1159
GDmac9bea4be2012-10-30 06:14:19 +01001160 // Reduce multiple spaces at end of line
1161 $str = preg_replace('| +\n|', "\n", $str);
1162
Derek Allard2067d1a2008-11-13 22:59:24 +00001163 // If the current word is surrounded by {unwrap} tags we'll
1164 // strip the entire chunk and replace it with a marker.
1165 $unwrap = array();
Andrey Andreev56454792012-05-17 14:32:19 +03001166 if (preg_match_all('|(\{unwrap\}.+?\{/unwrap\})|s', $str, $matches))
Derek Allard2067d1a2008-11-13 22:59:24 +00001167 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001168 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001169 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001170 $unwrap[] = $matches[1][$i];
Andrey Andreev56454792012-05-17 14:32:19 +03001171 $str = str_replace($matches[1][$i], '{{unwrapped'.$i.'}}', $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001172 }
1173 }
1174
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001175 // Use PHP's native public function to do the initial wordwrap.
Derek Allard2067d1a2008-11-13 22:59:24 +00001176 // We set the cut flag to FALSE so that any individual words that are
Andrey Andreev56454792012-05-17 14:32:19 +03001177 // too long get left alone. In the next step we'll deal with them.
Derek Allard2067d1a2008-11-13 22:59:24 +00001178 $str = wordwrap($str, $charlim, "\n", FALSE);
1179
1180 // Split the string into individual lines of text and cycle through them
Andrey Andreev56454792012-05-17 14:32:19 +03001181 $output = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001182 foreach (explode("\n", $str) as $line)
1183 {
1184 // Is the line within the allowed character count?
1185 // If so we'll join it to the output and continue
1186 if (strlen($line) <= $charlim)
1187 {
1188 $output .= $line.$this->newline;
1189 continue;
1190 }
1191
1192 $temp = '';
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001193 do
Derek Allard2067d1a2008-11-13 22:59:24 +00001194 {
1195 // If the over-length word is a URL we won't wrap it
Andrey Andreev56454792012-05-17 14:32:19 +03001196 if (preg_match('!\[url.+\]|://|wwww.!', $line))
Derek Allard2067d1a2008-11-13 22:59:24 +00001197 {
1198 break;
1199 }
1200
1201 // Trim the word down
1202 $temp .= substr($line, 0, $charlim-1);
1203 $line = substr($line, $charlim-1);
1204 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001205 while (strlen($line) > $charlim);
Derek Allard2067d1a2008-11-13 22:59:24 +00001206
1207 // If $temp contains data it means we had to split up an over-length
1208 // word into smaller chunks so we'll add it back to our current line
Alex Bilbied261b1e2012-06-02 11:12:16 +01001209 if ($temp !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001210 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001211 $output .= $temp.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001212 }
1213
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001214 $output .= $line.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001215 }
1216
1217 // Put our markers back
1218 if (count($unwrap) > 0)
1219 {
1220 foreach ($unwrap as $key => $val)
1221 {
Andrey Andreev56454792012-05-17 14:32:19 +03001222 $output = str_replace('{{unwrapped'.$key.'}}', $val, $output);
Derek Allard2067d1a2008-11-13 22:59:24 +00001223 }
1224 }
1225
1226 return $output;
1227 }
Barry Mienydd671972010-10-04 16:33:58 +02001228
Derek Allard2067d1a2008-11-13 22:59:24 +00001229 // --------------------------------------------------------------------
1230
1231 /**
1232 * Build final headers
1233 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001234 * @return string
1235 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001236 protected function _build_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +00001237 {
Mickey Wubfc1cad2012-05-31 22:28:40 -07001238 $this->set_header('X-Sender', $this->clean_email($this->_headers['From']));
1239 $this->set_header('X-Mailer', $this->useragent);
1240 $this->set_header('X-Priority', $this->_priorities[$this->priority - 1]);
1241 $this->set_header('Message-ID', $this->_get_message_id());
1242 $this->set_header('Mime-Version', '1.0');
Derek Allard2067d1a2008-11-13 22:59:24 +00001243 }
Barry Mienydd671972010-10-04 16:33:58 +02001244
Derek Allard2067d1a2008-11-13 22:59:24 +00001245 // --------------------------------------------------------------------
1246
1247 /**
1248 * Write Headers as a string
1249 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001250 * @return void
1251 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001252 protected function _write_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +00001253 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001254 if ($this->protocol === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001255 {
nisheeth-barthwal6bb98902013-02-19 18:11:14 +05301256 if (isset($this->_headers['Subject']))
1257 {
1258 $this->_subject = $this->_headers['Subject'];
1259 unset($this->_headers['Subject']);
1260 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001261 }
1262
1263 reset($this->_headers);
Andrey Andreev56454792012-05-17 14:32:19 +03001264 $this->_header_str = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001265
Pascal Kriete14287f32011-02-14 13:39:34 -05001266 foreach ($this->_headers as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001267 {
1268 $val = trim($val);
1269
Alex Bilbied261b1e2012-06-02 11:12:16 +01001270 if ($val !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001271 {
Andrey Andreev56454792012-05-17 14:32:19 +03001272 $this->_header_str .= $key.': '.$val.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001273 }
1274 }
1275
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001276 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001277 {
Derek Jones1d890882009-02-10 20:32:14 +00001278 $this->_header_str = rtrim($this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001279 }
1280 }
Barry Mienydd671972010-10-04 16:33:58 +02001281
Derek Allard2067d1a2008-11-13 22:59:24 +00001282 // --------------------------------------------------------------------
1283
1284 /**
1285 * Build Final Body and attachments
1286 *
buhayc6da1ef2013-04-18 09:06:49 -07001287 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001288 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001289 protected function _build_message()
Derek Allard2067d1a2008-11-13 22:59:24 +00001290 {
Andrey Andreev76f15c92012-03-01 13:05:07 +02001291 if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
Derek Allard2067d1a2008-11-13 22:59:24 +00001292 {
1293 $this->_body = $this->word_wrap($this->_body);
1294 }
1295
1296 $this->_set_boundaries();
1297 $this->_write_headers();
1298
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001299 $hdr = ($this->_get_protocol() === 'mail') ? $this->newline : '';
Brandon Jones485d7412010-11-09 16:38:17 -05001300 $body = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001301
1302 switch ($this->_get_content_type())
1303 {
1304 case 'plain' :
1305
Andrey Andreev56454792012-05-17 14:32:19 +03001306 $hdr .= 'Content-Type: text/plain; charset='.$this->charset.$this->newline
1307 .'Content-Transfer-Encoding: '.$this->_get_encoding();
Derek Allard2067d1a2008-11-13 22:59:24 +00001308
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001309 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001310 {
1311 $this->_header_str .= $hdr;
1312 $this->_finalbody = $this->_body;
Derek Allard2067d1a2008-11-13 22:59:24 +00001313 }
Brandon Jones485d7412010-11-09 16:38:17 -05001314 else
1315 {
Andrey Andreev2b956af2013-08-07 14:32:56 +03001316 $this->_finalbody = $hdr.$this->newline.$this->newline.$this->_body;
Brandon Jones485d7412010-11-09 16:38:17 -05001317 }
Eric Barnes6113f542010-12-29 13:36:12 -05001318
Derek Allard2067d1a2008-11-13 22:59:24 +00001319 return;
1320
Derek Allard2067d1a2008-11-13 22:59:24 +00001321 case 'html' :
1322
1323 if ($this->send_multipart === FALSE)
1324 {
Andrey Andreev56454792012-05-17 14:32:19 +03001325 $hdr .= 'Content-Type: text/html; charset='.$this->charset.$this->newline
Andrey Andreev2b956af2013-08-07 14:32:56 +03001326 .'Content-Transfer-Encoding: quoted-printable';
Derek Allard2067d1a2008-11-13 22:59:24 +00001327 }
1328 else
1329 {
Andrey Andreev2b956af2013-08-07 14:32:56 +03001330 $hdr .= 'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"';
Derek Allard2067d1a2008-11-13 22:59:24 +00001331
Andrey Andreev56454792012-05-17 14:32:19 +03001332 $body .= $this->_get_mime_message().$this->newline.$this->newline
1333 .'--'.$this->_alt_boundary.$this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001334
Andrey Andreev56454792012-05-17 14:32:19 +03001335 .'Content-Type: text/plain; charset='.$this->charset.$this->newline
1336 .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
1337 .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001338
Andrey Andreev56454792012-05-17 14:32:19 +03001339 .'Content-Type: text/html; charset='.$this->charset.$this->newline
1340 .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001341 }
Eric Barnes6113f542010-12-29 13:36:12 -05001342
Andrey Andreev56454792012-05-17 14:32:19 +03001343 $this->_finalbody = $body.$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -05001344
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001345 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001346 {
1347 $this->_header_str .= $hdr;
Brandon Jones485d7412010-11-09 16:38:17 -05001348 }
1349 else
1350 {
Andrey Andreev2b956af2013-08-07 14:32:56 +03001351 $this->_finalbody = $hdr.$this->newline.$this->newline.$this->_finalbody;
Derek Allard2067d1a2008-11-13 22:59:24 +00001352 }
1353
Derek Allard2067d1a2008-11-13 22:59:24 +00001354 if ($this->send_multipart !== FALSE)
1355 {
Andrey Andreev56454792012-05-17 14:32:19 +03001356 $this->_finalbody .= '--'.$this->_alt_boundary.'--';
Derek Allard2067d1a2008-11-13 22:59:24 +00001357 }
1358
Derek Allard2067d1a2008-11-13 22:59:24 +00001359 return;
1360
Derek Allard2067d1a2008-11-13 22:59:24 +00001361 case 'plain-attach' :
1362
Andrey Andreev2b956af2013-08-07 14:32:56 +03001363 $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"';
Derek Allard2067d1a2008-11-13 22:59:24 +00001364
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001365 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001366 {
1367 $this->_header_str .= $hdr;
Eric Barnes6113f542010-12-29 13:36:12 -05001368 }
1369
Andrey Andreev2b956af2013-08-07 14:32:56 +03001370 $body .= $this->_get_mime_message().$this->newline
1371 .$this->newline
Andrey Andreev56454792012-05-17 14:32:19 +03001372 .'--'.$this->_atc_boundary.$this->newline
Andrey Andreev56454792012-05-17 14:32:19 +03001373 .'Content-Type: text/plain; charset='.$this->charset.$this->newline
Andrey Andreev2b956af2013-08-07 14:32:56 +03001374 .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline
1375 .$this->newline
Andrey Andreev56454792012-05-17 14:32:19 +03001376 .$this->_body.$this->newline.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001377
1378 break;
1379 case 'html-attach' :
1380
Andrey Andreev2b956af2013-08-07 14:32:56 +03001381 $hdr .= 'Content-Type: multipart/'.$this->multipart.'; boundary="'.$this->_atc_boundary.'"';
Eric Barnes6113f542010-12-29 13:36:12 -05001382
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001383 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001384 {
1385 $this->_header_str .= $hdr;
Derek Allard2067d1a2008-11-13 22:59:24 +00001386 }
1387
Andrey Andreev56454792012-05-17 14:32:19 +03001388 $body .= $this->_get_mime_message().$this->newline.$this->newline
1389 .'--'.$this->_atc_boundary.$this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001390
Andrey Andreev56454792012-05-17 14:32:19 +03001391 .'Content-Type: multipart/alternative; boundary="'.$this->_alt_boundary.'"'.$this->newline.$this->newline
1392 .'--'.$this->_alt_boundary.$this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001393
Andrey Andreev56454792012-05-17 14:32:19 +03001394 .'Content-Type: text/plain; charset='.$this->charset.$this->newline
1395 .'Content-Transfer-Encoding: '.$this->_get_encoding().$this->newline.$this->newline
1396 .$this->_get_alt_message().$this->newline.$this->newline.'--'.$this->_alt_boundary.$this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001397
Andrey Andreev56454792012-05-17 14:32:19 +03001398 .'Content-Type: text/html; charset='.$this->charset.$this->newline
1399 .'Content-Transfer-Encoding: quoted-printable'.$this->newline.$this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001400
Andrey Andreev56454792012-05-17 14:32:19 +03001401 .$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline
1402 .'--'.$this->_alt_boundary.'--'.$this->newline.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001403
1404 break;
1405 }
1406
1407 $attachment = array();
Andrey Andreevb8f9a152012-10-27 01:36:51 +03001408 for ($i = 0, $c = count($this->_attachments), $z = 0; $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001409 {
Andrey Andreevb8f9a152012-10-27 01:36:51 +03001410 $filename = $this->_attachments[$i]['name'][0];
vlakoff912f1bc2013-01-15 03:34:12 +01001411 $basename = ($this->_attachments[$i]['name'][1] === NULL)
Andrey Andreevb8f9a152012-10-27 01:36:51 +03001412 ? basename($filename) : $this->_attachments[$i]['name'][1];
Andrey Andreev56454792012-05-17 14:32:19 +03001413
1414 $attachment[$z++] = '--'.$this->_atc_boundary.$this->newline
Petr Heralecky300e3f02014-01-10 11:49:11 +01001415 .'Content-type: '.$this->_attachments[$i]['type'].'; '
Andrey Andreev56454792012-05-17 14:32:19 +03001416 .'name="'.$basename.'"'.$this->newline
Andrey Andreevb8f9a152012-10-27 01:36:51 +03001417 .'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline
Petr Heralecky300e3f02014-01-10 11:49:11 +01001418 .'Content-Transfer-Encoding: base64'.$this->newline
1419 .(!empty($this->_attachments[$i]['cid']) ? "Content-ID: <".$this->_attachments[$i]['cid'].">".$this->newline : '');
Derek Allard2067d1a2008-11-13 22:59:24 +00001420
Petr Heralecky300e3f02014-01-10 11:49:11 +01001421 $attachment[$z++] = $this->_attachments[$i]['content'];
Derek Allard2067d1a2008-11-13 22:59:24 +00001422 }
1423
Andrey Andreev56454792012-05-17 14:32:19 +03001424 $body .= implode($this->newline, $attachment).$this->newline.'--'.$this->_atc_boundary.'--';
Andrey Andreev2b956af2013-08-07 14:32:56 +03001425 $this->_finalbody = ($this->_get_protocol() === 'mail')
1426 ? $body
1427 : $hdr.$this->newline.$this->newline.$body;
buhay466e8082013-04-17 14:25:34 -07001428 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001429 }
Barry Mienydd671972010-10-04 16:33:58 +02001430
Derek Allard2067d1a2008-11-13 22:59:24 +00001431 // --------------------------------------------------------------------
1432
1433 /**
1434 * Prep Quoted Printable
1435 *
1436 * Prepares string for Quoted-Printable Content-Transfer-Encoding
1437 * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
1438 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001439 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +00001440 * @return string
1441 */
Andrey Andreev683b34d2012-10-09 15:00:00 +03001442 protected function _prep_quoted_printable($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001443 {
Andrey Andreev00ea2a92012-10-18 14:59:29 +03001444 // We are intentionally wrapping so mail servers will encode characters
1445 // properly and MUAs will behave, so {unwrap} must go!
1446 $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);
1447
Andrey Andreev683b34d2012-10-09 15:00:00 +03001448 // RFC 2045 specifies CRLF as "\r\n".
1449 // However, many developers choose to override that and violate
1450 // the RFC rules due to (apparently) a bug in MS Exchange,
1451 // which only works with "\n".
Andrey Andreev26f0cf92012-10-11 13:52:39 +03001452 if ($this->crlf === "\r\n")
Andrey Andreev683b34d2012-10-09 15:00:00 +03001453 {
Andrey Andreev26f0cf92012-10-11 13:52:39 +03001454 if (is_php('5.3'))
1455 {
1456 return quoted_printable_encode($str);
1457 }
1458 elseif (function_exists('imap_8bit'))
1459 {
1460 return imap_8bit($str);
1461 }
Andrey Andreev683b34d2012-10-09 15:00:00 +03001462 }
1463
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001464 // Reduce multiple spaces & remove nulls
Andrey Andreev56454792012-05-17 14:32:19 +03001465 $str = preg_replace(array('| +|', '/\x00+/'), array(' ', ''), $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001466
1467 // Standardize newlines
1468 if (strpos($str, "\r") !== FALSE)
1469 {
1470 $str = str_replace(array("\r\n", "\r"), "\n", $str);
1471 }
1472
Derek Allard2067d1a2008-11-13 22:59:24 +00001473 $escape = '=';
1474 $output = '';
1475
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001476 foreach (explode("\n", $str) as $line)
Derek Allard2067d1a2008-11-13 22:59:24 +00001477 {
1478 $length = strlen($line);
1479 $temp = '';
1480
1481 // Loop through each character in the line to add soft-wrap
1482 // characters at the end of a line " =\r\n" and add the newly
1483 // processed line(s) to the output (see comment on $crlf class property)
1484 for ($i = 0; $i < $length; $i++)
1485 {
1486 // Grab the next character
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001487 $char = $line[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001488 $ascii = ord($char);
1489
1490 // Convert spaces and tabs but only if it's the end of the line
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001491 if ($i === ($length - 1) && ($ascii === 32 OR $ascii === 9))
Derek Allard2067d1a2008-11-13 22:59:24 +00001492 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001493 $char = $escape.sprintf('%02s', dechex($ascii));
Derek Allard2067d1a2008-11-13 22:59:24 +00001494 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001495 elseif ($ascii === 61) // encode = signs
Derek Allard2067d1a2008-11-13 22:59:24 +00001496 {
Derek Jones37f4b9c2011-07-01 17:56:50 -05001497 $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D
Derek Allard2067d1a2008-11-13 22:59:24 +00001498 }
1499
1500 // If we're at the character limit, add the line to the output,
1501 // reset our temp variable, and keep on chuggin'
Andrey Andreeve8bc5f42012-10-10 11:13:59 +03001502 if ((strlen($temp) + strlen($char)) >= 76)
Derek Allard2067d1a2008-11-13 22:59:24 +00001503 {
1504 $output .= $temp.$escape.$this->crlf;
1505 $temp = '';
1506 }
1507
1508 // Add the character to our temporary line
1509 $temp .= $char;
1510 }
1511
1512 // Add our completed line to the output
1513 $output .= $temp.$this->crlf;
1514 }
1515
1516 // get rid of extra CRLF tacked onto the end
Andrey Andreev59c5b532012-03-01 14:09:51 +02001517 return substr($output, 0, strlen($this->crlf) * -1);
Derek Allard2067d1a2008-11-13 22:59:24 +00001518 }
1519
1520 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001521
Derek Allard2067d1a2008-11-13 22:59:24 +00001522 /**
1523 * Prep Q Encoding
1524 *
Andrey Andreev925dd902012-10-19 11:06:31 +03001525 * Performs "Q Encoding" on a string for use in email headers.
1526 * It's related but not identical to quoted-printable, so it has its
1527 * own method.
Derek Allard2067d1a2008-11-13 22:59:24 +00001528 *
Andrey Andreev081c9462012-03-01 12:58:11 +02001529 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +02001530 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +00001531 */
Andrey Andreev925dd902012-10-19 11:06:31 +03001532 protected function _prep_q_encoding($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001533 {
Andrey Andreev925dd902012-10-19 11:06:31 +03001534 $str = str_replace(array("\r", "\n"), '', $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001535
Andrey Andreev925dd902012-10-19 11:06:31 +03001536 if ($this->charset === 'UTF-8')
Derek Allard2067d1a2008-11-13 22:59:24 +00001537 {
Andrey Andreev925dd902012-10-19 11:06:31 +03001538 if (MB_ENABLED === TRUE)
1539 {
1540 return mb_encode_mimeheader($str, $this->charset, 'Q', $this->crlf);
1541 }
1542 elseif (extension_loaded('iconv'))
1543 {
1544 $output = @iconv_mime_encode('', $str,
1545 array(
1546 'scheme' => 'Q',
1547 'line-length' => 76,
1548 'input-charset' => $this->charset,
1549 'output-charset' => $this->charset,
1550 'line-break-chars' => $this->crlf
1551 )
1552 );
1553
1554 // There are reports that iconv_mime_encode() might fail and return FALSE
1555 if ($output !== FALSE)
1556 {
1557 // iconv_mime_encode() will always put a header field name.
1558 // We've passed it an empty one, but it still prepends our
1559 // encoded string with ': ', so we need to strip it.
1560 return substr($output, 2);
1561 }
1562
1563 $chars = iconv_strlen($str, 'UTF-8');
1564 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001565 }
1566
Andrey Andreev925dd902012-10-19 11:06:31 +03001567 // We might already have this set for UTF-8
1568 isset($chars) OR $chars = strlen($str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001569
Andrey Andreev925dd902012-10-19 11:06:31 +03001570 $output = '=?'.$this->charset.'?Q?';
1571 for ($i = 0, $length = strlen($output), $iconv = extension_loaded('iconv'); $i < $chars; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001572 {
Andrey Andreev925dd902012-10-19 11:06:31 +03001573 $chr = ($this->charset === 'UTF-8' && $iconv === TRUE)
1574 ? '='.implode('=', str_split(strtoupper(bin2hex(iconv_substr($str, $i, 1, $this->charset))), 2))
1575 : '='.strtoupper(bin2hex($str[$i]));
Derek Allard2067d1a2008-11-13 22:59:24 +00001576
Andrey Andreev925dd902012-10-19 11:06:31 +03001577 // RFC 2045 sets a limit of 76 characters per line.
1578 // We'll append ?= to the end of each line though.
1579 if ($length + ($l = strlen($chr)) > 74)
Derek Allard2067d1a2008-11-13 22:59:24 +00001580 {
Andrey Andreev925dd902012-10-19 11:06:31 +03001581 $output .= '?='.$this->crlf // EOL
1582 .' =?'.$this->charset.'?Q?'.$chr; // New line
1583 $length = 6 + strlen($this->charset) + $l; // Reset the length for the new line
Derek Allard2067d1a2008-11-13 22:59:24 +00001584 }
Andrey Andreev925dd902012-10-19 11:06:31 +03001585 else
Derek Allard2067d1a2008-11-13 22:59:24 +00001586 {
Andrey Andreev925dd902012-10-19 11:06:31 +03001587 $output .= $chr;
1588 $length += $l;
Derek Allard2067d1a2008-11-13 22:59:24 +00001589 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001590 }
1591
Andrey Andreev925dd902012-10-19 11:06:31 +03001592 // End the header
1593 return $output.'?=';
Derek Allard2067d1a2008-11-13 22:59:24 +00001594 }
1595
1596 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001597
Derek Allard2067d1a2008-11-13 22:59:24 +00001598 /**
1599 * Send Email
1600 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03001601 * @param bool $auto_clear = TRUE
Derek Allard2067d1a2008-11-13 22:59:24 +00001602 * @return bool
1603 */
Alex Bilbied7bc8d02012-07-30 09:46:20 +01001604 public function send($auto_clear = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001605 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001606 if ($this->_replyto_flag === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001607 {
1608 $this->reply_to($this->_headers['From']);
1609 }
1610
Andrey Andreev76f15c92012-03-01 13:05:07 +02001611 if ( ! isset($this->_recipients) && ! isset($this->_headers['To'])
1612 && ! isset($this->_bcc_array) && ! isset($this->_headers['Bcc'])
1613 && ! isset($this->_headers['Cc']))
Derek Allard2067d1a2008-11-13 22:59:24 +00001614 {
patworkb0707982011-04-08 15:10:05 +02001615 $this->_set_error_message('lang:email_no_recipients');
Derek Allard2067d1a2008-11-13 22:59:24 +00001616 return FALSE;
1617 }
1618
1619 $this->_build_headers();
1620
Andrey Andreev76f15c92012-03-01 13:05:07 +02001621 if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size)
Derek Allard2067d1a2008-11-13 22:59:24 +00001622 {
Alex Bilbieb901e732012-07-30 09:44:57 +01001623 $result = $this->batch_bcc_send();
Alex Bilbied7bc8d02012-07-30 09:46:20 +01001624
Alex Bilbiea87aab32012-07-30 09:50:37 +01001625 if ($result && $auto_clear)
Alex Bilbied7bc8d02012-07-30 09:46:20 +01001626 {
1627 $this->clear();
1628 }
1629
Alex Bilbieb901e732012-07-30 09:44:57 +01001630 return $result;
Derek Allard2067d1a2008-11-13 22:59:24 +00001631 }
1632
buhay466e8082013-04-17 14:25:34 -07001633 if ($this->_build_message() === FALSE)
1634 {
1635 return FALSE;
1636 }
buhayc6da1ef2013-04-18 09:06:49 -07001637
Alex Bilbieb901e732012-07-30 09:44:57 +01001638 $result = $this->_spool_email();
Andrey Andreevbdb99992012-07-30 17:38:05 +03001639
Alex Bilbiea87aab32012-07-30 09:50:37 +01001640 if ($result && $auto_clear)
Alex Bilbied7bc8d02012-07-30 09:46:20 +01001641 {
1642 $this->clear();
1643 }
Alex Bilbiea87aab32012-07-30 09:50:37 +01001644
Alex Bilbieb901e732012-07-30 09:44:57 +01001645 return $result;
Derek Allard2067d1a2008-11-13 22:59:24 +00001646 }
Barry Mienydd671972010-10-04 16:33:58 +02001647
Derek Allard2067d1a2008-11-13 22:59:24 +00001648 // --------------------------------------------------------------------
1649
1650 /**
Andrey Andreev081c9462012-03-01 12:58:11 +02001651 * Batch Bcc Send. Sends groups of BCCs in batches
Derek Allard2067d1a2008-11-13 22:59:24 +00001652 *
Andrey Andreev081c9462012-03-01 12:58:11 +02001653 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00001654 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001655 public function batch_bcc_send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001656 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001657 $float = $this->bcc_batch_size - 1;
1658 $set = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001659 $chunk = array();
1660
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001661 for ($i = 0, $c = count($this->_bcc_array); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001662 {
1663 if (isset($this->_bcc_array[$i]))
1664 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001665 $set .= ', '.$this->_bcc_array[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001666 }
1667
Alex Bilbied261b1e2012-06-02 11:12:16 +01001668 if ($i === $float)
Derek Allard2067d1a2008-11-13 22:59:24 +00001669 {
1670 $chunk[] = substr($set, 1);
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001671 $float += $this->bcc_batch_size;
Andrey Andreev59c5b532012-03-01 14:09:51 +02001672 $set = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001673 }
1674
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001675 if ($i === $c-1)
Derek Allard2067d1a2008-11-13 22:59:24 +00001676 {
1677 $chunk[] = substr($set, 1);
1678 }
1679 }
1680
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001681 for ($i = 0, $c = count($chunk); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001682 {
1683 unset($this->_headers['Bcc']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001684
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001685 $bcc = $this->clean_email($this->_str_to_array($chunk[$i]));
Derek Allard2067d1a2008-11-13 22:59:24 +00001686
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001687 if ($this->protocol !== 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +00001688 {
Mickey Wubfc1cad2012-05-31 22:28:40 -07001689 $this->set_header('Bcc', implode(', ', $bcc));
Derek Allard2067d1a2008-11-13 22:59:24 +00001690 }
1691 else
1692 {
1693 $this->_bcc_array = $bcc;
1694 }
1695
buhay466e8082013-04-17 14:25:34 -07001696 if ($this->_build_message() === FALSE)
1697 {
1698 return FALSE;
1699 }
buhayc6da1ef2013-04-18 09:06:49 -07001700
Derek Allard2067d1a2008-11-13 22:59:24 +00001701 $this->_spool_email();
1702 }
1703 }
Barry Mienydd671972010-10-04 16:33:58 +02001704
Derek Allard2067d1a2008-11-13 22:59:24 +00001705 // --------------------------------------------------------------------
1706
1707 /**
1708 * Unwrap special elements
1709 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001710 * @return void
1711 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001712 protected function _unwrap_specials()
Derek Allard2067d1a2008-11-13 22:59:24 +00001713 {
Andrey Andreev56454792012-05-17 14:32:19 +03001714 $this->_finalbody = preg_replace_callback('/\{unwrap\}(.*?)\{\/unwrap\}/si', array($this, '_remove_nl_callback'), $this->_finalbody);
Derek Allard2067d1a2008-11-13 22:59:24 +00001715 }
Barry Mienydd671972010-10-04 16:33:58 +02001716
Derek Allard2067d1a2008-11-13 22:59:24 +00001717 // --------------------------------------------------------------------
1718
1719 /**
1720 * Strip line-breaks via callback
1721 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03001722 * @param string $matches
Derek Allard2067d1a2008-11-13 22:59:24 +00001723 * @return string
1724 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001725 protected function _remove_nl_callback($matches)
Derek Allard2067d1a2008-11-13 22:59:24 +00001726 {
1727 if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
1728 {
1729 $matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]);
1730 }
1731
1732 return $matches[1];
1733 }
Barry Mienydd671972010-10-04 16:33:58 +02001734
Derek Allard2067d1a2008-11-13 22:59:24 +00001735 // --------------------------------------------------------------------
1736
1737 /**
1738 * Spool mail to the mail server
1739 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001740 * @return bool
1741 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001742 protected function _spool_email()
Derek Allard2067d1a2008-11-13 22:59:24 +00001743 {
1744 $this->_unwrap_specials();
1745
Andrey Andreev56454792012-05-17 14:32:19 +03001746 $method = '_send_with_'.$this->_get_protocol();
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001747 if ( ! $this->$method())
Derek Allard2067d1a2008-11-13 22:59:24 +00001748 {
Andrey Andreev56454792012-05-17 14:32:19 +03001749 $this->_set_error_message('lang:email_send_failure_'.($this->_get_protocol() === 'mail' ? 'phpmail' : $this->_get_protocol()));
Diogo Osório7fcc7bd2012-03-02 16:54:52 +00001750 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001751 }
1752
patworkb0707982011-04-08 15:10:05 +02001753 $this->_set_error_message('lang:email_sent', $this->_get_protocol());
Derek Allard2067d1a2008-11-13 22:59:24 +00001754 return TRUE;
1755 }
Barry Mienydd671972010-10-04 16:33:58 +02001756
Derek Allard2067d1a2008-11-13 22:59:24 +00001757 // --------------------------------------------------------------------
1758
1759 /**
1760 * Send using mail()
1761 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001762 * @return bool
1763 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001764 protected function _send_with_mail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001765 {
Andrey Andreev8a7078b2012-10-17 10:52:49 +03001766 if (is_array($this->_recipients))
1767 {
1768 $this->_recipients = implode(', ', $this->_recipients);
1769 }
1770
Alex Bilbied261b1e2012-06-02 11:12:16 +01001771 if ($this->_safe_mode === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001772 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001773 return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001774 }
1775 else
1776 {
1777 // most documentation of sendmail using the "-f" flag lacks a space after it, however
1778 // we've encountered servers that seem to require it to be in place.
Melounek58dfc082012-06-29 08:43:47 +02001779 return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['Return-Path']));
Derek Allard2067d1a2008-11-13 22:59:24 +00001780 }
1781 }
Barry Mienydd671972010-10-04 16:33:58 +02001782
Derek Allard2067d1a2008-11-13 22:59:24 +00001783 // --------------------------------------------------------------------
1784
1785 /**
1786 * Send using Sendmail
1787 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001788 * @return bool
1789 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001790 protected function _send_with_sendmail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001791 {
Andrey Andreeve9d2dc82012-11-07 14:23:29 +02001792 // is popen() enabled?
1793 if ( ! function_usable('popen')
1794 OR FALSE === ($fp = @popen(
1795 $this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From'])
1796 .' -t -r '.$this->clean_email($this->_headers['Return-Path'])
1797 , 'w'))
1798 ) // server probably has popen disabled, so nothing we can do to get a verbose error.
Derek Jones4cefaa42009-04-29 19:13:56 +00001799 {
Derek Jones4cefaa42009-04-29 19:13:56 +00001800 return FALSE;
1801 }
Derek Jones71141ce2010-03-02 16:41:20 -06001802
Derek Jonesc630bcf2008-11-17 21:09:45 +00001803 fputs($fp, $this->_header_str);
1804 fputs($fp, $this->_finalbody);
1805
Barry Mienydd671972010-10-04 16:33:58 +02001806 $status = pclose($fp);
Eric Barnes6113f542010-12-29 13:36:12 -05001807
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001808 if ($status !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001809 {
patworkb0707982011-04-08 15:10:05 +02001810 $this->_set_error_message('lang:email_exit_status', $status);
1811 $this->_set_error_message('lang:email_no_socket');
Derek Allard2067d1a2008-11-13 22:59:24 +00001812 return FALSE;
1813 }
1814
Derek Allard2067d1a2008-11-13 22:59:24 +00001815 return TRUE;
1816 }
Barry Mienydd671972010-10-04 16:33:58 +02001817
Derek Allard2067d1a2008-11-13 22:59:24 +00001818 // --------------------------------------------------------------------
1819
1820 /**
1821 * Send using SMTP
1822 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001823 * @return bool
1824 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001825 protected function _send_with_smtp()
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301826 {
1827 if ($this->smtp_host === '')
1828 {
1829 $this->_set_error_message('lang:email_no_hostname');
1830 return FALSE;
1831 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001832
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301833 if ( ! $this->_smtp_connect() OR ! $this->_smtp_authenticate())
1834 {
1835 return FALSE;
1836 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001837
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301838 $this->_send_command('from', $this->clean_email($this->_headers['From']));
Derek Allard2067d1a2008-11-13 22:59:24 +00001839
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301840 foreach ($this->_recipients as $val)
1841 {
1842 $this->_send_command('to', $val);
1843 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001844
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301845 if (count($this->_cc_array) > 0)
1846 {
1847 foreach ($this->_cc_array as $val)
1848 {
1849 if ($val !== '')
1850 {
1851 $this->_send_command('to', $val);
1852 }
1853 }
1854 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001855
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301856 if (count($this->_bcc_array) > 0)
1857 {
1858 foreach ($this->_bcc_array as $val)
1859 {
1860 if ($val !== '')
1861 {
1862 $this->_send_command('to', $val);
1863 }
1864 }
1865 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001866
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301867 $this->_send_command('data');
Derek Allard2067d1a2008-11-13 22:59:24 +00001868
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301869 // perform dot transformation on any lines that begin with a dot
1870 $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody));
Derek Allard2067d1a2008-11-13 22:59:24 +00001871
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301872 $this->_send_data('.');
Derek Allard2067d1a2008-11-13 22:59:24 +00001873
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301874 $reply = $this->_get_smtp_data();
Derek Allard2067d1a2008-11-13 22:59:24 +00001875
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301876 $this->_set_error_message($reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001877
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301878 if (strpos($reply, '250') !== 0)
1879 {
1880 $this->_set_error_message('lang:email_smtp_error', $reply);
1881 return FALSE;
1882 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001883
nisheeth-barthwal758f40c2013-02-18 17:18:51 +05301884 if ($this->smtp_keepalive)
1885 {
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301886 $this->_send_command('reset');
nisheeth-barthwal758f40c2013-02-18 17:18:51 +05301887 }
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301888 else
nisheeth-barthwal758f40c2013-02-18 17:18:51 +05301889 {
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301890 $this->_send_command('quit');
nisheeth-barthwal758f40c2013-02-18 17:18:51 +05301891 }
Barry Mienydd671972010-10-04 16:33:58 +02001892
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301893 return TRUE;
1894 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001895
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301896 // --------------------------------------------------------------------
Radu Potop4c589ae2011-09-29 10:19:55 +03001897
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301898 /**
1899 * SMTP Connect
1900 *
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301901 * @return string
1902 */
nisheeth-barthwala44e6912013-02-18 18:07:03 +05301903 protected function _smtp_connect()
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301904 {
nisheeth-barthwala44e6912013-02-18 18:07:03 +05301905 if (is_resource($this->_smtp_connect))
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301906 {
nisheeth-barthwala44e6912013-02-18 18:07:03 +05301907 return TRUE;
1908 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001909
Andrey Andreev89b67b42013-03-12 19:34:23 +02001910 $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001911
nisheeth-barthwala44e6912013-02-18 18:07:03 +05301912 $this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
1913 $this->smtp_port,
1914 $errno,
1915 $errstr,
1916 $this->smtp_timeout);
1917
1918 if ( ! is_resource($this->_smtp_connect))
1919 {
1920 $this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr);
1921 return FALSE;
1922 }
1923
1924 stream_set_timeout($this->_smtp_connect, $this->smtp_timeout);
1925 $this->_set_error_message($this->_get_smtp_data());
1926
1927 if ($this->smtp_crypto === 'tls')
1928 {
1929 $this->_send_command('hello');
1930 $this->_send_command('starttls');
1931
1932 $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
1933
1934 if ($crypto !== TRUE)
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301935 {
nisheeth-barthwala44e6912013-02-18 18:07:03 +05301936 $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data());
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301937 return FALSE;
1938 }
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301939 }
nisheeth-barthwala44e6912013-02-18 18:07:03 +05301940
1941 return $this->_send_command('hello');
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301942 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001943
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301944 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +00001945
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301946 /**
1947 * Send SMTP command
1948 *
1949 * @param string
1950 * @param string
1951 * @return string
1952 */
1953 protected function _send_command($cmd, $data = '')
1954 {
1955 switch ($cmd)
1956 {
1957 case 'hello' :
Derek Allard2067d1a2008-11-13 22:59:24 +00001958
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301959 if ($this->_smtp_auth OR $this->_get_encoding() === '8bit')
1960 {
1961 $this->_send_data('EHLO '.$this->_get_hostname());
1962 }
1963 else
1964 {
1965 $this->_send_data('HELO '.$this->_get_hostname());
1966 }
Radu Potopbbf04b02011-09-28 13:57:51 +03001967
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301968 $resp = 250;
1969 break;
1970 case 'starttls' :
Derek Allard2067d1a2008-11-13 22:59:24 +00001971
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301972 $this->_send_data('STARTTLS');
1973 $resp = 220;
1974 break;
1975 case 'from' :
Andrey Andreev56454792012-05-17 14:32:19 +03001976
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301977 $this->_send_data('MAIL FROM:<'.$data.'>');
1978 $resp = 250;
1979 break;
1980 case 'to' :
Andrey Andreev56454792012-05-17 14:32:19 +03001981
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301982 if ($this->dsn)
1983 {
1984 $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data);
1985 }
1986 else
1987 {
1988 $this->_send_data('RCPT TO:<'.$data.'>');
1989 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001990
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301991 $resp = 250;
1992 break;
1993 case 'data' :
Derek Allard2067d1a2008-11-13 22:59:24 +00001994
nisheeth-barthwal59209de2013-02-18 17:02:13 +05301995 $this->_send_data('DATA');
1996 $resp = 354;
1997 break;
1998 case 'reset':
Derek Allard2067d1a2008-11-13 22:59:24 +00001999
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302000 $this->_send_data('RSET');
2001 $resp = 250;
2002 break;
2003 case 'quit' :
Derek Allard2067d1a2008-11-13 22:59:24 +00002004
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302005 $this->_send_data('QUIT');
2006 $resp = 221;
2007 break;
2008 }
Derek Allard2067d1a2008-11-13 22:59:24 +00002009
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302010 $reply = $this->_get_smtp_data();
Derek Allard2067d1a2008-11-13 22:59:24 +00002011
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302012 $this->_debug_msg[] = '<pre>'.$cmd.': '.$reply.'</pre>';
Derek Allard2067d1a2008-11-13 22:59:24 +00002013
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302014 if ((int) substr($reply, 0, 3) !== $resp)
2015 {
2016 $this->_set_error_message('lang:email_smtp_error', $reply);
2017 return FALSE;
2018 }
Barry Mienydd671972010-10-04 16:33:58 +02002019
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302020 if ($cmd === 'quit')
2021 {
2022 fclose($this->_smtp_connect);
2023 }
Derek Allard2067d1a2008-11-13 22:59:24 +00002024
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302025 return TRUE;
2026 }
Derek Allard2067d1a2008-11-13 22:59:24 +00002027
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302028 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +00002029
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302030 /**
2031 * SMTP Authenticate
2032 *
2033 * @return bool
2034 */
2035 protected function _smtp_authenticate()
2036 {
2037 if ( ! $this->_smtp_auth)
2038 {
2039 return TRUE;
2040 }
Derek Allard2067d1a2008-11-13 22:59:24 +00002041
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302042 if ($this->smtp_user === '' && $this->smtp_pass === '')
2043 {
2044 $this->_set_error_message('lang:email_no_smtp_unpw');
2045 return FALSE;
2046 }
Derek Allard2067d1a2008-11-13 22:59:24 +00002047
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302048 $this->_send_data('AUTH LOGIN');
Derek Allard2067d1a2008-11-13 22:59:24 +00002049
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302050 $reply = $this->_get_smtp_data();
Derek Allard2067d1a2008-11-13 22:59:24 +00002051
Andrey Andreevfa01ae42013-03-04 14:40:18 +02002052 if (strpos($reply, '503') === 0) // Already authenticated
nisheeth-barthwal758f40c2013-02-18 17:18:51 +05302053 {
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302054 return TRUE;
nisheeth-barthwal758f40c2013-02-18 17:18:51 +05302055 }
Andrey Andreevfa01ae42013-03-04 14:40:18 +02002056 elseif (strpos($reply, '334') !== 0)
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302057 {
2058 $this->_set_error_message('lang:email_failed_smtp_login', $reply);
2059 return FALSE;
2060 }
Derek Allard2067d1a2008-11-13 22:59:24 +00002061
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302062 $this->_send_data(base64_encode($this->smtp_user));
Derek Allard2067d1a2008-11-13 22:59:24 +00002063
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302064 $reply = $this->_get_smtp_data();
Derek Allard2067d1a2008-11-13 22:59:24 +00002065
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302066 if (strpos($reply, '334') !== 0)
2067 {
2068 $this->_set_error_message('lang:email_smtp_auth_un', $reply);
2069 return FALSE;
2070 }
Derek Allard2067d1a2008-11-13 22:59:24 +00002071
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302072 $this->_send_data(base64_encode($this->smtp_pass));
Derek Allard2067d1a2008-11-13 22:59:24 +00002073
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302074 $reply = $this->_get_smtp_data();
nisheeth-barthwalcf225572013-02-18 01:08:04 +05302075
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302076 if (strpos($reply, '235') !== 0)
2077 {
2078 $this->_set_error_message('lang:email_smtp_auth_pw', $reply);
2079 return FALSE;
2080 }
nisheeth-barthwalcf225572013-02-18 01:08:04 +05302081
nisheeth-barthwal59209de2013-02-18 17:02:13 +05302082 return TRUE;
2083 }
Barry Mienydd671972010-10-04 16:33:58 +02002084
Derek Allard2067d1a2008-11-13 22:59:24 +00002085 // --------------------------------------------------------------------
2086
2087 /**
2088 * Send SMTP data
2089 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03002090 * @param string $data
Derek Allard2067d1a2008-11-13 22:59:24 +00002091 * @return bool
2092 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06002093 protected function _send_data($data)
Derek Allard2067d1a2008-11-13 22:59:24 +00002094 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03002095 if ( ! fwrite($this->_smtp_connect, $data.$this->newline))
Derek Allard2067d1a2008-11-13 22:59:24 +00002096 {
patworkb0707982011-04-08 15:10:05 +02002097 $this->_set_error_message('lang:email_smtp_data_failure', $data);
Derek Allard2067d1a2008-11-13 22:59:24 +00002098 return FALSE;
2099 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02002100
2101 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00002102 }
Barry Mienydd671972010-10-04 16:33:58 +02002103
Derek Allard2067d1a2008-11-13 22:59:24 +00002104 // --------------------------------------------------------------------
2105
2106 /**
2107 * Get SMTP data
2108 *
Derek Allard2067d1a2008-11-13 22:59:24 +00002109 * @return string
2110 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06002111 protected function _get_smtp_data()
Derek Allard2067d1a2008-11-13 22:59:24 +00002112 {
Andrey Andreev56454792012-05-17 14:32:19 +03002113 $data = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00002114
2115 while ($str = fgets($this->_smtp_connect, 512))
2116 {
2117 $data .= $str;
2118
Alex Bilbied261b1e2012-06-02 11:12:16 +01002119 if ($str[3] === ' ')
Derek Allard2067d1a2008-11-13 22:59:24 +00002120 {
2121 break;
2122 }
2123 }
2124
2125 return $data;
2126 }
Barry Mienydd671972010-10-04 16:33:58 +02002127
Derek Allard2067d1a2008-11-13 22:59:24 +00002128 // --------------------------------------------------------------------
2129
2130 /**
2131 * Get Hostname
2132 *
Derek Allard2067d1a2008-11-13 22:59:24 +00002133 * @return string
2134 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06002135 protected function _get_hostname()
Derek Allard2067d1a2008-11-13 22:59:24 +00002136 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02002137 return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
Derek Allard2067d1a2008-11-13 22:59:24 +00002138 }
Barry Mienydd671972010-10-04 16:33:58 +02002139
Derek Allard2067d1a2008-11-13 22:59:24 +00002140 // --------------------------------------------------------------------
2141
2142 /**
Derek Allard2067d1a2008-11-13 22:59:24 +00002143 * Get Debug Message
2144 *
Andrey Andreev61797f62012-11-26 16:15:12 +02002145 * @param array $include List of raw data chunks to include in the output
2146 * Valid options are: 'headers', 'subject', 'body'
Derek Allard2067d1a2008-11-13 22:59:24 +00002147 * @return string
2148 */
Andrey Andreev61797f62012-11-26 16:15:12 +02002149 public function print_debugger($include = array('headers', 'subject', 'body'))
Derek Allard2067d1a2008-11-13 22:59:24 +00002150 {
2151 $msg = '';
2152
2153 if (count($this->_debug_msg) > 0)
2154 {
2155 foreach ($this->_debug_msg as $val)
2156 {
2157 $msg .= $val;
2158 }
2159 }
2160
Andrey Andreev61797f62012-11-26 16:15:12 +02002161 // Determine which parts of our raw data needs to be printed
2162 $raw_data = '';
2163 is_array($include) OR $include = array($include);
2164
2165 if (in_array('headers', $include, TRUE))
2166 {
Andrey Andreev58f677f2013-07-16 11:01:37 +03002167 $raw_data = htmlspecialchars($this->_header_str)."\n";
Andrey Andreev61797f62012-11-26 16:15:12 +02002168 }
2169
2170 if (in_array('subject', $include, TRUE))
2171 {
2172 $raw_data .= htmlspecialchars($this->_subject)."\n";
2173 }
2174
2175 if (in_array('body', $include, TRUE))
2176 {
2177 $raw_data .= htmlspecialchars($this->_finalbody);
2178 }
2179
2180 return $msg.($raw_data === '' ? '' : '<pre>'.$raw_data.'</pre>');
Derek Allard2067d1a2008-11-13 22:59:24 +00002181 }
Barry Mienydd671972010-10-04 16:33:58 +02002182
Derek Allard2067d1a2008-11-13 22:59:24 +00002183 // --------------------------------------------------------------------
2184
2185 /**
2186 * Set Message
2187 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03002188 * @param string $msg
2189 * @param string $val = ''
Andrey Andreev081c9462012-03-01 12:58:11 +02002190 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00002191 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06002192 protected function _set_error_message($msg, $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00002193 {
2194 $CI =& get_instance();
2195 $CI->lang->load('email');
2196
Andrey Andreev7a7ad782012-11-12 17:21:01 +02002197 if (sscanf($msg, 'lang:%s', $line) !== 1 OR FALSE === ($line = $CI->lang->line($line)))
Derek Allard2067d1a2008-11-13 22:59:24 +00002198 {
Andrey Andreev56454792012-05-17 14:32:19 +03002199 $this->_debug_msg[] = str_replace('%s', $val, $msg).'<br />';
Derek Allard2067d1a2008-11-13 22:59:24 +00002200 }
2201 else
2202 {
Andrey Andreev56454792012-05-17 14:32:19 +03002203 $this->_debug_msg[] = str_replace('%s', $val, $line).'<br />';
Derek Allard2067d1a2008-11-13 22:59:24 +00002204 }
2205 }
Barry Mienydd671972010-10-04 16:33:58 +02002206
Derek Allard2067d1a2008-11-13 22:59:24 +00002207 // --------------------------------------------------------------------
2208
2209 /**
2210 * Mime Types
2211 *
Derek Allard2067d1a2008-11-13 22:59:24 +00002212 * @param string
2213 * @return string
2214 */
Andrey Andreev59c5b532012-03-01 14:09:51 +02002215 protected function _mime_types($ext = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00002216 {
Andrey Andreev6ef498b2012-06-05 22:01:58 +03002217 static $mimes;
Derek Allard2067d1a2008-11-13 22:59:24 +00002218
Andrey Andreev6ef498b2012-06-05 22:01:58 +03002219 $ext = strtolower($ext);
2220
2221 if ( ! is_array($mimes))
2222 {
2223 $mimes =& get_mimes();
2224 }
2225
2226 if (isset($mimes[$ext]))
2227 {
2228 return is_array($mimes[$ext])
2229 ? current($mimes[$ext])
2230 : $mimes[$ext];
2231 }
2232
2233 return 'application/x-unknown-content-type';
Derek Allard2067d1a2008-11-13 22:59:24 +00002234 }
2235
2236}
Derek Allard2067d1a2008-11-13 22:59:24 +00002237
2238/* End of file Email.php */
Andrey Andreev50988592012-10-08 20:46:04 +03002239/* Location: ./system/libraries/Email.php */