blob: 7429035f8f4a74cac6483b36eb9ecf7dcf7c1ee3 [file] [log] [blame]
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
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
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, 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 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * CodeIgniter Email Class
30 *
31 * Permits email to be sent using Mail, Sendmail, or SMTP.
32 *
33 * @package CodeIgniter
34 * @subpackage Libraries
35 * @category Libraries
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/libraries/email.html
38 */
trita15dd4f2011-11-23 07:40:05 -050039class CI_Email {
Derek Allard2067d1a2008-11-13 22:59:24 +000040
Andrey Andreev59c5b532012-03-01 14:09:51 +020041 public $useragent = 'CodeIgniter';
42 public $mailpath = '/usr/sbin/sendmail'; // Sendmail path
43 public $protocol = 'mail'; // mail/sendmail/smtp
44 public $smtp_host = ''; // SMTP Server. Example: mail.earthlink.net
45 public $smtp_user = ''; // SMTP Username
46 public $smtp_pass = ''; // SMTP Password
47 public $smtp_port = 25; // SMTP Port
48 public $smtp_timeout = 5; // SMTP Timeout in seconds
49 public $smtp_crypto = ''; // SMTP Encryption. Can be null, tls or ssl.
50 public $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off
51 public $wrapchars = 76; // Number of characters to wrap at.
52 public $mailtype = 'text'; // text/html Defines email formatting
53 public $charset = 'utf-8'; // Default char set: iso-8859-1 or us-ascii
54 public $multipart = 'mixed'; // "mixed" (in the body) or "related" (separate)
55 public $alt_message = ''; // Alternative message for HTML emails
56 public $validate = FALSE; // TRUE/FALSE. Enables email validation
57 public $priority = 3; // Default priority (1 - 5)
58 public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
59 public $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
Derek Allard2067d1a2008-11-13 22:59:24 +000060 // even on the receiving end think they need to muck with CRLFs, so using "\n", while
61 // distasteful, is the only thing that seems to work for all environments.
Andrey Andreev1bd3d882011-12-22 15:38:20 +020062 public $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo.
Andrey Andreev59c5b532012-03-01 14:09:51 +020063 public $bcc_batch_mode = FALSE; // TRUE/FALSE - Turns on/off Bcc batch feature
Andrey Andreev1bd3d882011-12-22 15:38:20 +020064 public $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch
Andrey Andreev50814092012-03-01 12:36:12 +020065
66 protected $_safe_mode = FALSE;
67 protected $_subject = '';
68 protected $_body = '';
69 protected $_finalbody = '';
70 protected $_alt_boundary = '';
71 protected $_atc_boundary = '';
72 protected $_header_str = '';
73 protected $_smtp_connect = '';
74 protected $_encoding = '8bit';
75 protected $_IP = FALSE;
76 protected $_smtp_auth = FALSE;
77 protected $_replyto_flag = FALSE;
78 protected $_debug_msg = array();
79 protected $_recipients = array();
80 protected $_cc_array = array();
81 protected $_bcc_array = array();
82 protected $_headers = array();
83 protected $_attach_name = array();
84 protected $_attach_type = array();
85 protected $_attach_disp = array();
86 protected $_protocols = array('mail', 'sendmail', 'smtp');
87 protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
88 protected $_bit_depths = array('7bit', '8bit');
89 protected $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
Derek Allard2067d1a2008-11-13 22:59:24 +000090
Derek Allard2067d1a2008-11-13 22:59:24 +000091 /**
92 * Constructor - Sets Email Preferences
93 *
94 * The constructor can be passed an array of config values
95 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +000096 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000097 {
98 if (count($config) > 0)
99 {
100 $this->initialize($config);
101 }
102 else
103 {
Andrey Andreev76f15c92012-03-01 13:05:07 +0200104 $this->_smtp_auth = ! ($this->smtp_user == '' && $this->smtp_pass == '');
Andrey Andreev59c5b532012-03-01 14:09:51 +0200105 $this->_safe_mode = (bool) @ini_get('safe_mode');
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 }
107
Andrey Andreev59c5b532012-03-01 14:09:51 +0200108 log_message('debug', 'Email Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 }
110
111 // --------------------------------------------------------------------
112
113 /**
114 * Initialize preferences
115 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 * @param array
117 * @return void
118 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000119 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 foreach ($config as $key => $val)
122 {
123 if (isset($this->$key))
124 {
125 $method = 'set_'.$key;
126
127 if (method_exists($this, $method))
128 {
129 $this->$method($val);
130 }
131 else
132 {
133 $this->$key = $val;
134 }
135 }
136 }
Eric Barnes6113f542010-12-29 13:36:12 -0500137 $this->clear();
Derek Allard2067d1a2008-11-13 22:59:24 +0000138
Andrey Andreev76f15c92012-03-01 13:05:07 +0200139 $this->_smtp_auth = ! ($this->smtp_user == '' && $this->smtp_pass == '');
Andrey Andreev59c5b532012-03-01 14:09:51 +0200140 $this->_safe_mode = (bool) @ini_get('safe_mode');
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000141
142 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 }
Barry Mienydd671972010-10-04 16:33:58 +0200144
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 // --------------------------------------------------------------------
146
147 /**
148 * Initialize the Email Data
149 *
Bo-Yi Wu83320eb2011-09-15 13:28:02 +0800150 * @param bool
Andrey Andreev081c9462012-03-01 12:58:11 +0200151 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000153 public function clear($clear_attachments = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200155 $this->_subject = '';
156 $this->_body = '';
157 $this->_finalbody = '';
158 $this->_header_str = '';
159 $this->_replyto_flag = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 $this->_recipients = array();
Derek Jonesd1606352010-09-01 11:16:07 -0500161 $this->_cc_array = array();
162 $this->_bcc_array = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 $this->_headers = array();
164 $this->_debug_msg = array();
165
166 $this->_set_header('User-Agent', $this->useragent);
167 $this->_set_header('Date', $this->_set_date());
168
169 if ($clear_attachments !== FALSE)
170 {
171 $this->_attach_name = array();
172 $this->_attach_type = array();
173 $this->_attach_disp = array();
174 }
Eric Barnes6113f542010-12-29 13:36:12 -0500175
Greg Akera769deb2010-11-10 15:47:29 -0600176 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 }
Barry Mienydd671972010-10-04 16:33:58 +0200178
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 // --------------------------------------------------------------------
180
181 /**
182 * Set FROM
183 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 * @param string
185 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200186 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000187 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000188 public function from($from, $name = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200190 if (preg_match('/\<(.*)\>/', $from, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200192 $from = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 }
194
195 if ($this->validate)
196 {
197 $this->validate_email($this->_str_to_array($from));
198 }
199
200 // prepare the display name
201 if ($name != '')
202 {
203 // only use Q encoding if there are characters that would require it
204 if ( ! preg_match('/[\200-\377]/', $name))
205 {
206 // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
Derek Jonesc630bcf2008-11-17 21:09:45 +0000207 $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"';
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 }
209 else
210 {
211 $name = $this->_prep_q_encoding($name, TRUE);
212 }
213 }
214
215 $this->_set_header('From', $name.' <'.$from.'>');
216 $this->_set_header('Return-Path', '<'.$from.'>');
Eric Barnes6113f542010-12-29 13:36:12 -0500217
Greg Akera769deb2010-11-10 15:47:29 -0600218 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 }
Barry Mienydd671972010-10-04 16:33:58 +0200220
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 // --------------------------------------------------------------------
222
223 /**
224 * Set Reply-to
225 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 * @param string
227 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200228 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000230 public function reply_to($replyto, $name = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000231 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200232 if (preg_match('/\<(.*)\>/', $replyto, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000233 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200234 $replyto = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 }
236
237 if ($this->validate)
238 {
239 $this->validate_email($this->_str_to_array($replyto));
240 }
241
242 if ($name == '')
243 {
244 $name = $replyto;
245 }
246
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200247 if (strncmp($name, '"', 1) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 {
249 $name = '"'.$name.'"';
250 }
251
252 $this->_set_header('Reply-To', $name.' <'.$replyto.'>');
253 $this->_replyto_flag = TRUE;
Greg Akera769deb2010-11-10 15:47:29 -0600254
255 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 }
Barry Mienydd671972010-10-04 16:33:58 +0200257
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 // --------------------------------------------------------------------
259
260 /**
261 * Set Recipients
262 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200264 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000266 public function to($to)
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 {
268 $to = $this->_str_to_array($to);
269 $to = $this->clean_email($to);
270
271 if ($this->validate)
272 {
273 $this->validate_email($to);
274 }
275
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200276 if ($this->_get_protocol() !== 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200278 $this->_set_header('To', implode(', ', $to));
Derek Allard2067d1a2008-11-13 22:59:24 +0000279 }
280
281 switch ($this->_get_protocol())
282 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200283 case 'smtp':
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000284 $this->_recipients = $to;
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 break;
Andrey Andreev59c5b532012-03-01 14:09:51 +0200286 case 'sendmail':
287 case 'mail':
288 $this->_recipients = implode(', ', $to);
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 break;
290 }
Eric Barnes6113f542010-12-29 13:36:12 -0500291
Greg Akera769deb2010-11-10 15:47:29 -0600292 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 }
Barry Mienydd671972010-10-04 16:33:58 +0200294
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 // --------------------------------------------------------------------
296
297 /**
298 * Set CC
299 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200301 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000303 public function cc($cc)
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 {
305 $cc = $this->_str_to_array($cc);
306 $cc = $this->clean_email($cc);
307
308 if ($this->validate)
309 {
310 $this->validate_email($cc);
311 }
312
Andrey Andreev59c5b532012-03-01 14:09:51 +0200313 $this->_set_header('Cc', implode(', ', $cc));
Derek Allard2067d1a2008-11-13 22:59:24 +0000314
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200315 if ($this->_get_protocol() === 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 {
317 $this->_cc_array = $cc;
318 }
Eric Barnes6113f542010-12-29 13:36:12 -0500319
Greg Akera769deb2010-11-10 15:47:29 -0600320 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 }
Barry Mienydd671972010-10-04 16:33:58 +0200322
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 // --------------------------------------------------------------------
324
325 /**
326 * Set BCC
327 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 * @param string
329 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200330 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000332 public function bcc($bcc, $limit = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 {
334 if ($limit != '' && is_numeric($limit))
335 {
336 $this->bcc_batch_mode = TRUE;
337 $this->bcc_batch_size = $limit;
338 }
339
340 $bcc = $this->_str_to_array($bcc);
341 $bcc = $this->clean_email($bcc);
342
343 if ($this->validate)
344 {
345 $this->validate_email($bcc);
346 }
347
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200348 if ($this->_get_protocol() === 'smtp' OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size))
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 {
350 $this->_bcc_array = $bcc;
351 }
352 else
353 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200354 $this->_set_header('Bcc', implode(', ', $bcc));
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 }
Eric Barnes6113f542010-12-29 13:36:12 -0500356
Greg Akera769deb2010-11-10 15:47:29 -0600357 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 }
Barry Mienydd671972010-10-04 16:33:58 +0200359
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 // --------------------------------------------------------------------
361
362 /**
363 * Set Email Subject
364 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200366 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000368 public function subject($subject)
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 {
370 $subject = $this->_prep_q_encoding($subject);
371 $this->_set_header('Subject', $subject);
Greg Akera769deb2010-11-10 15:47:29 -0600372 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 }
Barry Mienydd671972010-10-04 16:33:58 +0200374
Derek Allard2067d1a2008-11-13 22:59:24 +0000375 // --------------------------------------------------------------------
376
377 /**
378 * Set Body
379 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200381 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000383 public function message($body)
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200385 $this->_body = rtrim(str_replace("\r", '', $body));
diegorivera33c32802011-10-19 02:56:15 -0200386
Andrey Andreevaf728622011-10-20 10:11:59 +0300387 /* strip slashes only if magic quotes is ON
388 if we do it with magic quotes OFF, it strips real, user-inputted chars.
389
390 NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
391 it will probably not exist in future versions at all.
392 */
393 if ( ! is_php('5.4') && get_magic_quotes_gpc())
diegorivera9fca6152011-10-19 11:18:45 -0200394 {
diegorivera33c32802011-10-19 02:56:15 -0200395 $this->_body = stripslashes($this->_body);
diegorivera9fca6152011-10-19 11:18:45 -0200396 }
diegorivera33c32802011-10-19 02:56:15 -0200397
Greg Akera769deb2010-11-10 15:47:29 -0600398 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 }
Barry Mienydd671972010-10-04 16:33:58 +0200400
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 // --------------------------------------------------------------------
402
403 /**
404 * Assign file attachments
405 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200407 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 */
Matteo Matteic3b36f42012-03-26 10:27:17 +0200409 public function attach($filename, $disposition = '', $newname = NULL, $mime = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 {
trit151fc682011-11-23 07:30:06 -0500411 $this->_attach_name[] = array($filename, $newname);
tritd5269982011-11-23 17:22:44 -0500412 $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters
Matteo Matteic3b36f42012-03-26 10:27:17 +0200413 $this->_attach_type[] = $mime;
Greg Akera769deb2010-11-10 15:47:29 -0600414 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 }
416
417 // --------------------------------------------------------------------
418
419 /**
420 * Add a Header Item
421 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 * @param string
423 * @param string
424 * @return void
425 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600426 protected function _set_header($header, $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 {
428 $this->_headers[$header] = $value;
429 }
Barry Mienydd671972010-10-04 16:33:58 +0200430
Derek Allard2067d1a2008-11-13 22:59:24 +0000431 // --------------------------------------------------------------------
432
433 /**
434 * Convert a String to an Array
435 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 * @param string
437 * @return array
438 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600439 protected function _str_to_array($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
441 if ( ! is_array($email))
442 {
443 if (strpos($email, ',') !== FALSE)
444 {
445 $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY);
446 }
447 else
448 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200449 $email = (array) trim($email);
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 }
451 }
452 return $email;
453 }
Barry Mienydd671972010-10-04 16:33:58 +0200454
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 // --------------------------------------------------------------------
456
457 /**
458 * Set Multipart Value
459 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200461 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000463 public function set_alt_message($str = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 {
Dan Horrigand0ddeaf2011-08-21 09:07:27 -0400465 $this->alt_message = (string) $str;
Greg Akera769deb2010-11-10 15:47:29 -0600466 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 }
Barry Mienydd671972010-10-04 16:33:58 +0200468
Derek Allard2067d1a2008-11-13 22:59:24 +0000469 // --------------------------------------------------------------------
470
471 /**
472 * Set Mailtype
473 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200475 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000477 public function set_mailtype($type = 'text')
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 {
479 $this->mailtype = ($type == 'html') ? 'html' : 'text';
Greg Akera769deb2010-11-10 15:47:29 -0600480 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 }
Barry Mienydd671972010-10-04 16:33:58 +0200482
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 // --------------------------------------------------------------------
484
485 /**
486 * Set Wordwrap
487 *
Dan Horrigan628e6602011-08-21 09:08:31 -0400488 * @param bool
Andrey Andreev081c9462012-03-01 12:58:11 +0200489 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000490 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000491 public function set_wordwrap($wordwrap = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 {
Dan Horrigan628e6602011-08-21 09:08:31 -0400493 $this->wordwrap = (bool) $wordwrap;
Greg Akera769deb2010-11-10 15:47:29 -0600494 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000495 }
Barry Mienydd671972010-10-04 16:33:58 +0200496
Derek Allard2067d1a2008-11-13 22:59:24 +0000497 // --------------------------------------------------------------------
498
499 /**
500 * Set Protocol
501 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200503 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000505 public function set_protocol($protocol = 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000506 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200507 $this->protocol = in_array($protocol, $this->_protocols, TRUE) ? strtolower($protocol) : 'mail';
Greg Akera769deb2010-11-10 15:47:29 -0600508 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000509 }
Barry Mienydd671972010-10-04 16:33:58 +0200510
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 // --------------------------------------------------------------------
512
513 /**
514 * Set Priority
515 *
Andrey Andreev081c9462012-03-01 12:58:11 +0200516 * @param int
517 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000518 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000519 public function set_priority($n = 3)
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200521 $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3;
Greg Akera769deb2010-11-10 15:47:29 -0600522 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 }
Barry Mienydd671972010-10-04 16:33:58 +0200524
Derek Allard2067d1a2008-11-13 22:59:24 +0000525 // --------------------------------------------------------------------
526
527 /**
528 * Set Newline Character
529 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200531 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000533 public function set_newline($newline = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200535 $this->newline = in_array($newline, array("\n", "\r\n", "\r")) ? $newline : "\n";
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 CRLF
543 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000544 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200545 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000547 public function set_crlf($crlf = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000548 {
Andrey Andreev76f15c92012-03-01 13:05:07 +0200549 $this->crlf = ($crlf !== "\n" && $crlf !== "\r\n" && $crlf !== "\r") ? "\n" : $crlf;
Greg Akera769deb2010-11-10 15:47:29 -0600550 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 }
Barry Mienydd671972010-10-04 16:33:58 +0200552
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 // --------------------------------------------------------------------
554
555 /**
556 * Set Message Boundary
557 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 * @return void
559 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600560 protected function _set_boundaries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200562 $this->_alt_boundary = 'B_ALT_'.uniqid(''); // multipart/alternative
563 $this->_atc_boundary = 'B_ATC_'.uniqid(''); // attachment boundary
Derek Allard2067d1a2008-11-13 22:59:24 +0000564 }
Barry Mienydd671972010-10-04 16:33:58 +0200565
Derek Allard2067d1a2008-11-13 22:59:24 +0000566 // --------------------------------------------------------------------
567
568 /**
569 * Get the Message ID
570 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000571 * @return string
572 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600573 protected function _get_message_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000574 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200575 $from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']);
Andrey Andreev59c5b532012-03-01 14:09:51 +0200576 return '<'.uniqid('').strstr($from, '@').'>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 }
Barry Mienydd671972010-10-04 16:33:58 +0200578
Derek Allard2067d1a2008-11-13 22:59:24 +0000579 // --------------------------------------------------------------------
580
581 /**
582 * Get Mail Protocol
583 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 * @param bool
Andrey Andreev59c5b532012-03-01 14:09:51 +0200585 * @return mixed
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600587 protected function _get_protocol($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 {
589 $this->protocol = strtolower($this->protocol);
Andrey Andreev59c5b532012-03-01 14:09:51 +0200590 in_array($this->protocol, $this->_protocols, TRUE) OR $this->protocol = 'mail';
Derek Allard2067d1a2008-11-13 22:59:24 +0000591
592 if ($return == TRUE)
593 {
594 return $this->protocol;
595 }
596 }
Barry Mienydd671972010-10-04 16:33:58 +0200597
Derek Allard2067d1a2008-11-13 22:59:24 +0000598 // --------------------------------------------------------------------
599
600 /**
601 * Get Mail Encoding
602 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000603 * @param bool
604 * @return string
605 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600606 protected function _get_encoding($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000607 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200608 in_array($this->_encoding, $this->_bit_depths) OR $this->_encoding = '8bit';
Derek Allard2067d1a2008-11-13 22:59:24 +0000609
610 foreach ($this->_base_charsets as $charset)
611 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200612 if (strncmp($charset, $this->charset, strlen($charset)) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 {
614 $this->_encoding = '7bit';
615 }
616 }
617
618 if ($return == TRUE)
619 {
620 return $this->_encoding;
621 }
622 }
623
624 // --------------------------------------------------------------------
625
626 /**
627 * Get content type (text/html/attachment)
628 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000629 * @return string
630 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600631 protected function _get_content_type()
Derek Allard2067d1a2008-11-13 22:59:24 +0000632 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200633 if ($this->mailtype === 'html' && count($this->_attach_name) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000634 {
635 return 'html';
636 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200637 elseif ($this->mailtype === 'html' && count($this->_attach_name) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000638 {
639 return 'html-attach';
640 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200641 elseif ($this->mailtype === 'text' && count($this->_attach_name) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 {
643 return 'plain-attach';
644 }
645 else
646 {
647 return 'plain';
648 }
649 }
Barry Mienydd671972010-10-04 16:33:58 +0200650
Derek Allard2067d1a2008-11-13 22:59:24 +0000651 // --------------------------------------------------------------------
652
653 /**
654 * Set RFC 822 Date
655 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000656 * @return string
657 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600658 protected function _set_date()
Derek Allard2067d1a2008-11-13 22:59:24 +0000659 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200660 $timezone = date('Z');
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200661 $operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+';
Derek Allard2067d1a2008-11-13 22:59:24 +0000662 $timezone = abs($timezone);
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200663 $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
Derek Allard2067d1a2008-11-13 22:59:24 +0000664
Andrey Andreev59c5b532012-03-01 14:09:51 +0200665 return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
Derek Allard2067d1a2008-11-13 22:59:24 +0000666 }
Barry Mienydd671972010-10-04 16:33:58 +0200667
Derek Allard2067d1a2008-11-13 22:59:24 +0000668 // --------------------------------------------------------------------
669
670 /**
671 * Mime message
672 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000673 * @return string
674 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600675 protected function _get_mime_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000676 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200677 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 +0000678 }
Barry Mienydd671972010-10-04 16:33:58 +0200679
Derek Allard2067d1a2008-11-13 22:59:24 +0000680 // --------------------------------------------------------------------
681
682 /**
683 * Validate Email Address
684 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000685 * @param string
686 * @return bool
687 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000688 public function validate_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000689 {
690 if ( ! is_array($email))
691 {
patworkb0707982011-04-08 15:10:05 +0200692 $this->_set_error_message('lang:email_must_be_array');
Derek Allard2067d1a2008-11-13 22:59:24 +0000693 return FALSE;
694 }
695
696 foreach ($email as $val)
697 {
698 if ( ! $this->valid_email($val))
699 {
patworkb0707982011-04-08 15:10:05 +0200700 $this->_set_error_message('lang:email_invalid_address', $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000701 return FALSE;
702 }
703 }
704
705 return TRUE;
706 }
Barry Mienydd671972010-10-04 16:33:58 +0200707
Derek Allard2067d1a2008-11-13 22:59:24 +0000708 // --------------------------------------------------------------------
709
710 /**
711 * Email Validation
712 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000713 * @param string
714 * @return bool
715 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000716 public function valid_email($address)
Derek Allard2067d1a2008-11-13 22:59:24 +0000717 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200718 return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $address);
Derek Allard2067d1a2008-11-13 22:59:24 +0000719 }
Barry Mienydd671972010-10-04 16:33:58 +0200720
Derek Allard2067d1a2008-11-13 22:59:24 +0000721 // --------------------------------------------------------------------
722
723 /**
724 * Clean Extended Email Address: Joe Smith <joe@smith.com>
725 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000726 * @param string
727 * @return string
728 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000729 public function clean_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000730 {
731 if ( ! is_array($email))
732 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200733 return (preg_match('/\<(.*)\>/', $email, $match)) ? $match[1] : $email;
Derek Allard2067d1a2008-11-13 22:59:24 +0000734 }
735
736 $clean_email = array();
737
738 foreach ($email as $addy)
739 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200740 $clean_email[] = preg_match('/\<(.*)\>/', $addy, $match) ? $match[1] : $addy;
Derek Allard2067d1a2008-11-13 22:59:24 +0000741 }
742
743 return $clean_email;
744 }
Barry Mienydd671972010-10-04 16:33:58 +0200745
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 // --------------------------------------------------------------------
747
748 /**
749 * Build alternative plain text message
750 *
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000751 * This public function provides the raw message for use
Derek Allard2067d1a2008-11-13 22:59:24 +0000752 * in plain-text headers of HTML-formatted emails.
753 * If the user hasn't specified his own alternative message
754 * it creates one by stripping the HTML
755 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000756 * @return string
757 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600758 protected function _get_alt_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000759 {
Andrey Andreev59c5b532012-03-01 14:09:51 +0200760 if ($this->alt_message != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000761 {
762 return $this->word_wrap($this->alt_message, '76');
763 }
764
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200765 $body = (preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match)) ? $match[1] : $this->_body;
766 $body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000767
768 for ($i = 20; $i >= 3; $i--)
769 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200770 $body = str_replace(str_repeat("\n", $i), "\n\n", $body);
Derek Allard2067d1a2008-11-13 22:59:24 +0000771 }
772
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200773 return $this->word_wrap($body, 76);
Derek Allard2067d1a2008-11-13 22:59:24 +0000774 }
Barry Mienydd671972010-10-04 16:33:58 +0200775
Derek Allard2067d1a2008-11-13 22:59:24 +0000776 // --------------------------------------------------------------------
777
778 /**
779 * Word Wrap
780 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000781 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200782 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000783 * @return string
784 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000785 public function word_wrap($str, $charlim = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000786 {
787 // Se the character limit
788 if ($charlim == '')
789 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200790 $charlim = ($this->wrapchars == "") ? 76 : $this->wrapchars;
Derek Allard2067d1a2008-11-13 22:59:24 +0000791 }
792
793 // Reduce multiple spaces
794 $str = preg_replace("| +|", " ", $str);
795
796 // Standardize newlines
797 if (strpos($str, "\r") !== FALSE)
798 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200799 $str = str_replace(array("\r\n", "\r"), "\n", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000800 }
801
802 // If the current word is surrounded by {unwrap} tags we'll
803 // strip the entire chunk and replace it with a marker.
804 $unwrap = array();
805 if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
806 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200807 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000808 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200809 $unwrap[] = $matches[1][$i];
810 $str = str_replace($matches[1][$i], "{{unwrapped".$i."}}", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000811 }
812 }
813
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000814 // Use PHP's native public function to do the initial wordwrap.
Derek Allard2067d1a2008-11-13 22:59:24 +0000815 // We set the cut flag to FALSE so that any individual words that are
Derek Jones37f4b9c2011-07-01 17:56:50 -0500816 // too long get left alone. In the next step we'll deal with them.
Derek Allard2067d1a2008-11-13 22:59:24 +0000817 $str = wordwrap($str, $charlim, "\n", FALSE);
818
819 // Split the string into individual lines of text and cycle through them
820 $output = "";
821 foreach (explode("\n", $str) as $line)
822 {
823 // Is the line within the allowed character count?
824 // If so we'll join it to the output and continue
825 if (strlen($line) <= $charlim)
826 {
827 $output .= $line.$this->newline;
828 continue;
829 }
830
831 $temp = '';
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200832 do
Derek Allard2067d1a2008-11-13 22:59:24 +0000833 {
834 // If the over-length word is a URL we won't wrap it
835 if (preg_match("!\[url.+\]|://|wwww.!", $line))
836 {
837 break;
838 }
839
840 // Trim the word down
841 $temp .= substr($line, 0, $charlim-1);
842 $line = substr($line, $charlim-1);
843 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200844 while (strlen($line) > $charlim);
Derek Allard2067d1a2008-11-13 22:59:24 +0000845
846 // If $temp contains data it means we had to split up an over-length
847 // word into smaller chunks so we'll add it back to our current line
848 if ($temp != '')
849 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200850 $output .= $temp.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000851 }
852
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200853 $output .= $line.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000854 }
855
856 // Put our markers back
857 if (count($unwrap) > 0)
858 {
859 foreach ($unwrap as $key => $val)
860 {
861 $output = str_replace("{{unwrapped".$key."}}", $val, $output);
862 }
863 }
864
865 return $output;
866 }
Barry Mienydd671972010-10-04 16:33:58 +0200867
Derek Allard2067d1a2008-11-13 22:59:24 +0000868 // --------------------------------------------------------------------
869
870 /**
871 * Build final headers
872 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000873 * @return string
874 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600875 protected function _build_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +0000876 {
877 $this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
878 $this->_set_header('X-Mailer', $this->useragent);
879 $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]);
880 $this->_set_header('Message-ID', $this->_get_message_id());
881 $this->_set_header('Mime-Version', '1.0');
882 }
Barry Mienydd671972010-10-04 16:33:58 +0200883
Derek Allard2067d1a2008-11-13 22:59:24 +0000884 // --------------------------------------------------------------------
885
886 /**
887 * Write Headers as a string
888 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000889 * @return void
890 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600891 protected function _write_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +0000892 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200893 if ($this->protocol === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000894 {
895 $this->_subject = $this->_headers['Subject'];
896 unset($this->_headers['Subject']);
897 }
898
899 reset($this->_headers);
900 $this->_header_str = "";
901
Pascal Kriete14287f32011-02-14 13:39:34 -0500902 foreach ($this->_headers as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000903 {
904 $val = trim($val);
905
906 if ($val != "")
907 {
908 $this->_header_str .= $key.": ".$val.$this->newline;
909 }
910 }
911
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200912 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000913 {
Derek Jones1d890882009-02-10 20:32:14 +0000914 $this->_header_str = rtrim($this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000915 }
916 }
Barry Mienydd671972010-10-04 16:33:58 +0200917
Derek Allard2067d1a2008-11-13 22:59:24 +0000918 // --------------------------------------------------------------------
919
920 /**
921 * Build Final Body and attachments
922 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000923 * @return void
924 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600925 protected function _build_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000926 {
Andrey Andreev76f15c92012-03-01 13:05:07 +0200927 if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
Derek Allard2067d1a2008-11-13 22:59:24 +0000928 {
929 $this->_body = $this->word_wrap($this->_body);
930 }
931
932 $this->_set_boundaries();
933 $this->_write_headers();
934
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200935 $hdr = ($this->_get_protocol() === 'mail') ? $this->newline : '';
Brandon Jones485d7412010-11-09 16:38:17 -0500936 $body = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000937
938 switch ($this->_get_content_type())
939 {
940 case 'plain' :
941
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200942 $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline
943 . "Content-Transfer-Encoding: " . $this->_get_encoding();
Derek Allard2067d1a2008-11-13 22:59:24 +0000944
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200945 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000946 {
947 $this->_header_str .= $hdr;
948 $this->_finalbody = $this->_body;
Derek Allard2067d1a2008-11-13 22:59:24 +0000949 }
Brandon Jones485d7412010-11-09 16:38:17 -0500950 else
951 {
952 $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body;
953 }
Eric Barnes6113f542010-12-29 13:36:12 -0500954
Derek Allard2067d1a2008-11-13 22:59:24 +0000955 return;
956
Derek Allard2067d1a2008-11-13 22:59:24 +0000957 case 'html' :
958
959 if ($this->send_multipart === FALSE)
960 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200961 $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline
962 . "Content-Transfer-Encoding: quoted-printable";
Derek Allard2067d1a2008-11-13 22:59:24 +0000963 }
964 else
965 {
Derek Jonesa45e7612009-02-10 18:33:01 +0000966 $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000967
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200968 $body .= $this->_get_mime_message() . $this->newline . $this->newline
969 . "--" . $this->_alt_boundary . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +0000970
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200971 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
972 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
973 . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -0500974
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200975 . "Content-Type: text/html; charset=" . $this->charset . $this->newline
976 . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000977 }
Eric Barnes6113f542010-12-29 13:36:12 -0500978
Brandon Jones485d7412010-11-09 16:38:17 -0500979 $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -0500980
981
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200982 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000983 {
984 $this->_header_str .= $hdr;
Brandon Jones485d7412010-11-09 16:38:17 -0500985 }
986 else
987 {
988 $this->_finalbody = $hdr . $this->_finalbody;
Derek Allard2067d1a2008-11-13 22:59:24 +0000989 }
990
Derek Allard2067d1a2008-11-13 22:59:24 +0000991
992 if ($this->send_multipart !== FALSE)
993 {
Brandon Jones485d7412010-11-09 16:38:17 -0500994 $this->_finalbody .= "--" . $this->_alt_boundary . "--";
Derek Allard2067d1a2008-11-13 22:59:24 +0000995 }
996
Derek Allard2067d1a2008-11-13 22:59:24 +0000997 return;
998
Derek Allard2067d1a2008-11-13 22:59:24 +0000999 case 'plain-attach' :
1000
Derek Jonesa45e7612009-02-10 18:33:01 +00001001 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001002
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001003 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001004 {
1005 $this->_header_str .= $hdr;
Eric Barnes6113f542010-12-29 13:36:12 -05001006 }
1007
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001008 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1009 . "--" . $this->_atc_boundary . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001010
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001011 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1012 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001013
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001014 . $this->_body . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001015
1016 break;
1017 case 'html-attach' :
1018
Derek Jonesa45e7612009-02-10 18:33:01 +00001019 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -05001020
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001021 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001022 {
1023 $this->_header_str .= $hdr;
Derek Allard2067d1a2008-11-13 22:59:24 +00001024 }
1025
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001026 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1027 . "--" . $this->_atc_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001028
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001029 . "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline
1030 . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001031
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001032 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1033 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
1034 . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001035
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001036 . "Content-Type: text/html; charset=" . $this->charset . $this->newline
1037 . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001038
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001039 . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline
1040 . "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001041
1042 break;
1043 }
1044
1045 $attachment = array();
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001046 for ($i = 0, $c = count($this->_attach_name), $z = 0; $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001047 {
tritbc4ac992011-11-23 07:19:41 -05001048 $filename = $this->_attach_name[$i][0];
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001049 $basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1];
Derek Allard2067d1a2008-11-13 22:59:24 +00001050 $ctype = $this->_attach_type[$i];
Matteo Mattei5688d582012-03-13 19:29:29 +01001051 $file_content = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001052
Matteo Matteic3b36f42012-03-26 10:27:17 +02001053 if ($this->_attach_type[$i] == '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001054 {
Matteo Mattei5688d582012-03-13 19:29:29 +01001055 if ( ! file_exists($filename))
1056 {
1057 $this->_set_error_message('lang:email_attachment_missing', $filename);
1058 return FALSE;
1059 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001060
Matteo Mattei5688d582012-03-13 19:29:29 +01001061 $file = filesize($filename) +1;
1062
1063 if ( ! $fp = fopen($filename, FOPEN_READ))
1064 {
1065 $this->_set_error_message('lang:email_attachment_unreadable', $filename);
1066 return FALSE;
1067 }
1068
Matteo Matteic3b36f42012-03-26 10:27:17 +02001069 $ctype = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
Matteo Mattei5688d582012-03-13 19:29:29 +01001070 $file_content = fread($fp, $file);
1071 fclose($fp);
1072 }
1073 else
1074 {
1075 $file_content =& $this->_attach_content[$i];
1076 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001077 $attachment[$z++] = "--".$this->_atc_boundary.$this->newline
1078 . "Content-type: ".$ctype."; "
1079 . "name=\"".$basename."\"".$this->newline
1080 . "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline
1081 . "Content-Transfer-Encoding: base64".$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001082
Matteo Mattei5688d582012-03-13 19:29:29 +01001083 $attachment[$z++] = chunk_split(base64_encode($file_content));
Derek Allard2067d1a2008-11-13 22:59:24 +00001084 }
1085
Brandon Jones485d7412010-11-09 16:38:17 -05001086 $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001087 $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr . $body;
Derek Allard2067d1a2008-11-13 22:59:24 +00001088 return;
1089 }
Barry Mienydd671972010-10-04 16:33:58 +02001090
Derek Allard2067d1a2008-11-13 22:59:24 +00001091 // --------------------------------------------------------------------
1092
1093 /**
1094 * Prep Quoted Printable
1095 *
1096 * Prepares string for Quoted-Printable Content-Transfer-Encoding
1097 * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
1098 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001099 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +02001100 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +00001101 * @return string
1102 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001103 protected function _prep_quoted_printable($str, $charlim = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001104 {
1105 // Set the character limit
1106 // Don't allow over 76, as that will make servers and MUAs barf
1107 // all over quoted-printable data
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001108 if ($charlim == '' OR $charlim > 76)
Derek Allard2067d1a2008-11-13 22:59:24 +00001109 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001110 $charlim = 76;
Derek Allard2067d1a2008-11-13 22:59:24 +00001111 }
1112
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001113 // Reduce multiple spaces & remove nulls
1114 $str = preg_replace(array("| +|", '/\x00+/'), array(' ', ''), $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001115
1116 // Standardize newlines
1117 if (strpos($str, "\r") !== FALSE)
1118 {
1119 $str = str_replace(array("\r\n", "\r"), "\n", $str);
1120 }
1121
1122 // We are intentionally wrapping so mail servers will encode characters
1123 // properly and MUAs will behave, so {unwrap} must go!
1124 $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);
1125
Derek Allard2067d1a2008-11-13 22:59:24 +00001126 $escape = '=';
1127 $output = '';
1128
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001129 foreach (explode("\n", $str) as $line)
Derek Allard2067d1a2008-11-13 22:59:24 +00001130 {
1131 $length = strlen($line);
1132 $temp = '';
1133
1134 // Loop through each character in the line to add soft-wrap
1135 // characters at the end of a line " =\r\n" and add the newly
1136 // processed line(s) to the output (see comment on $crlf class property)
1137 for ($i = 0; $i < $length; $i++)
1138 {
1139 // Grab the next character
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001140 $char = $line[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001141 $ascii = ord($char);
1142
1143 // Convert spaces and tabs but only if it's the end of the line
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001144 if ($i === ($length - 1) && ($ascii === 32 OR $ascii === 9))
Derek Allard2067d1a2008-11-13 22:59:24 +00001145 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001146 $char = $escape.sprintf('%02s', dechex($ascii));
Derek Allard2067d1a2008-11-13 22:59:24 +00001147 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001148 elseif ($ascii === 61) // encode = signs
Derek Allard2067d1a2008-11-13 22:59:24 +00001149 {
Derek Jones37f4b9c2011-07-01 17:56:50 -05001150 $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D
Derek Allard2067d1a2008-11-13 22:59:24 +00001151 }
1152
1153 // If we're at the character limit, add the line to the output,
1154 // reset our temp variable, and keep on chuggin'
1155 if ((strlen($temp) + strlen($char)) >= $charlim)
1156 {
1157 $output .= $temp.$escape.$this->crlf;
1158 $temp = '';
1159 }
1160
1161 // Add the character to our temporary line
1162 $temp .= $char;
1163 }
1164
1165 // Add our completed line to the output
1166 $output .= $temp.$this->crlf;
1167 }
1168
1169 // get rid of extra CRLF tacked onto the end
Andrey Andreev59c5b532012-03-01 14:09:51 +02001170 return substr($output, 0, strlen($this->crlf) * -1);
Derek Allard2067d1a2008-11-13 22:59:24 +00001171 }
1172
1173 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001174
Derek Allard2067d1a2008-11-13 22:59:24 +00001175 /**
1176 * Prep Q Encoding
1177 *
Derek Jones37f4b9c2011-07-01 17:56:50 -05001178 * Performs "Q Encoding" on a string for use in email headers. It's related
Derek Allard2067d1a2008-11-13 22:59:24 +00001179 * but not identical to quoted-printable, so it has its own method
1180 *
Andrey Andreev081c9462012-03-01 12:58:11 +02001181 * @param string
1182 * @param bool set to TRUE for processing From: headers
1183 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +00001184 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001185 protected function _prep_q_encoding($str, $from = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001186 {
1187 $str = str_replace(array("\r", "\n"), array('', ''), $str);
1188
1189 // Line length must not exceed 76 characters, so we adjust for
1190 // a space, 7 extra characters =??Q??=, and the charset that we will add to each line
1191 $limit = 75 - 7 - strlen($this->charset);
1192
1193 // these special characters must be converted too
1194 $convert = array('_', '=', '?');
1195
1196 if ($from === TRUE)
1197 {
1198 $convert[] = ',';
1199 $convert[] = ';';
1200 }
1201
1202 $output = '';
1203 $temp = '';
1204
1205 for ($i = 0, $length = strlen($str); $i < $length; $i++)
1206 {
1207 // Grab the next character
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001208 $char = $str[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001209 $ascii = ord($char);
1210
1211 // convert ALL non-printable ASCII characters and our specials
1212 if ($ascii < 32 OR $ascii > 126 OR in_array($char, $convert))
1213 {
1214 $char = '='.dechex($ascii);
1215 }
1216
1217 // handle regular spaces a bit more compactly than =20
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001218 if ($ascii === 32)
Derek Allard2067d1a2008-11-13 22:59:24 +00001219 {
1220 $char = '_';
1221 }
1222
1223 // If we're at the character limit, add the line to the output,
1224 // reset our temp variable, and keep on chuggin'
1225 if ((strlen($temp) + strlen($char)) >= $limit)
1226 {
1227 $output .= $temp.$this->crlf;
1228 $temp = '';
1229 }
1230
1231 // Add the character to our temporary line
1232 $temp .= $char;
1233 }
1234
1235 $str = $output.$temp;
1236
1237 // wrap each line with the shebang, charset, and transfer encoding
1238 // the preceding space on successive lines is required for header "folding"
Andrey Andreev59c5b532012-03-01 14:09:51 +02001239 return trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
Derek Allard2067d1a2008-11-13 22:59:24 +00001240 }
1241
1242 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001243
Derek Allard2067d1a2008-11-13 22:59:24 +00001244 /**
1245 * Send Email
1246 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001247 * @return bool
1248 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001249 public function send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001250 {
1251 if ($this->_replyto_flag == FALSE)
1252 {
1253 $this->reply_to($this->_headers['From']);
1254 }
1255
Andrey Andreev76f15c92012-03-01 13:05:07 +02001256 if ( ! isset($this->_recipients) && ! isset($this->_headers['To'])
1257 && ! isset($this->_bcc_array) && ! isset($this->_headers['Bcc'])
1258 && ! isset($this->_headers['Cc']))
Derek Allard2067d1a2008-11-13 22:59:24 +00001259 {
patworkb0707982011-04-08 15:10:05 +02001260 $this->_set_error_message('lang:email_no_recipients');
Derek Allard2067d1a2008-11-13 22:59:24 +00001261 return FALSE;
1262 }
1263
1264 $this->_build_headers();
1265
Andrey Andreev76f15c92012-03-01 13:05:07 +02001266 if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size)
Derek Allard2067d1a2008-11-13 22:59:24 +00001267 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001268 return $this->batch_bcc_send();
Derek Allard2067d1a2008-11-13 22:59:24 +00001269 }
1270
1271 $this->_build_message();
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001272 return $this->_spool_email();
Derek Allard2067d1a2008-11-13 22:59:24 +00001273 }
Barry Mienydd671972010-10-04 16:33:58 +02001274
Derek Allard2067d1a2008-11-13 22:59:24 +00001275 // --------------------------------------------------------------------
1276
1277 /**
Andrey Andreev081c9462012-03-01 12:58:11 +02001278 * Batch Bcc Send. Sends groups of BCCs in batches
Derek Allard2067d1a2008-11-13 22:59:24 +00001279 *
Andrey Andreev081c9462012-03-01 12:58:11 +02001280 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00001281 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001282 public function batch_bcc_send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001283 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001284 $float = $this->bcc_batch_size - 1;
1285 $set = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001286 $chunk = array();
1287
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001288 for ($i = 0, $c = count($this->_bcc_array); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001289 {
1290 if (isset($this->_bcc_array[$i]))
1291 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001292 $set .= ', '.$this->_bcc_array[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001293 }
1294
1295 if ($i == $float)
1296 {
1297 $chunk[] = substr($set, 1);
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001298 $float += $this->bcc_batch_size;
Andrey Andreev59c5b532012-03-01 14:09:51 +02001299 $set = '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001300 }
1301
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001302 if ($i === $c-1)
Derek Allard2067d1a2008-11-13 22:59:24 +00001303 {
1304 $chunk[] = substr($set, 1);
1305 }
1306 }
1307
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001308 for ($i = 0, $c = count($chunk); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001309 {
1310 unset($this->_headers['Bcc']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001311
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001312 $bcc = $this->clean_email($this->_str_to_array($chunk[$i]));
Derek Allard2067d1a2008-11-13 22:59:24 +00001313
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001314 if ($this->protocol !== 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +00001315 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001316 $this->_set_header('Bcc', implode(', ', $bcc));
Derek Allard2067d1a2008-11-13 22:59:24 +00001317 }
1318 else
1319 {
1320 $this->_bcc_array = $bcc;
1321 }
1322
1323 $this->_build_message();
1324 $this->_spool_email();
1325 }
1326 }
Barry Mienydd671972010-10-04 16:33:58 +02001327
Derek Allard2067d1a2008-11-13 22:59:24 +00001328 // --------------------------------------------------------------------
1329
1330 /**
1331 * Unwrap special elements
1332 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001333 * @return void
1334 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001335 protected function _unwrap_specials()
Derek Allard2067d1a2008-11-13 22:59:24 +00001336 {
1337 $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
1338 }
Barry Mienydd671972010-10-04 16:33:58 +02001339
Derek Allard2067d1a2008-11-13 22:59:24 +00001340 // --------------------------------------------------------------------
1341
1342 /**
1343 * Strip line-breaks via callback
1344 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001345 * @return string
1346 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001347 protected function _remove_nl_callback($matches)
Derek Allard2067d1a2008-11-13 22:59:24 +00001348 {
1349 if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
1350 {
1351 $matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]);
1352 }
1353
1354 return $matches[1];
1355 }
Barry Mienydd671972010-10-04 16:33:58 +02001356
Derek Allard2067d1a2008-11-13 22:59:24 +00001357 // --------------------------------------------------------------------
1358
1359 /**
1360 * Spool mail to the mail server
1361 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001362 * @return bool
1363 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001364 protected function _spool_email()
Derek Allard2067d1a2008-11-13 22:59:24 +00001365 {
1366 $this->_unwrap_specials();
1367
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001368 $method = '_send_with_' . $this->_get_protocol();
1369 if ( ! $this->$method())
Derek Allard2067d1a2008-11-13 22:59:24 +00001370 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001371 $this->_set_error_message('lang:email_send_failure_' . ($this->_get_protocol() === 'mail' ? 'phpmail' : $this->_get_protocol()));
Diogo Osório7fcc7bd2012-03-02 16:54:52 +00001372 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001373 }
1374
patworkb0707982011-04-08 15:10:05 +02001375 $this->_set_error_message('lang:email_sent', $this->_get_protocol());
Derek Allard2067d1a2008-11-13 22:59:24 +00001376 return TRUE;
1377 }
Barry Mienydd671972010-10-04 16:33:58 +02001378
Derek Allard2067d1a2008-11-13 22:59:24 +00001379 // --------------------------------------------------------------------
1380
1381 /**
1382 * Send using mail()
1383 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001384 * @return bool
1385 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001386 protected function _send_with_mail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001387 {
1388 if ($this->_safe_mode == TRUE)
1389 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001390 return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001391 }
1392 else
1393 {
1394 // most documentation of sendmail using the "-f" flag lacks a space after it, however
1395 // we've encountered servers that seem to require it to be in place.
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001396 return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']));
Derek Allard2067d1a2008-11-13 22:59:24 +00001397 }
1398 }
Barry Mienydd671972010-10-04 16:33:58 +02001399
Derek Allard2067d1a2008-11-13 22:59:24 +00001400 // --------------------------------------------------------------------
1401
1402 /**
1403 * Send using Sendmail
1404 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001405 * @return bool
1406 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001407 protected function _send_with_sendmail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001408 {
1409 $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
1410
Derek Jones4cefaa42009-04-29 19:13:56 +00001411 if ($fp === FALSE OR $fp === NULL)
1412 {
1413 // server probably has popen disabled, so nothing we can do to get a verbose error.
1414 return FALSE;
1415 }
Derek Jones71141ce2010-03-02 16:41:20 -06001416
Derek Jonesc630bcf2008-11-17 21:09:45 +00001417 fputs($fp, $this->_header_str);
1418 fputs($fp, $this->_finalbody);
1419
Barry Mienydd671972010-10-04 16:33:58 +02001420 $status = pclose($fp);
Eric Barnes6113f542010-12-29 13:36:12 -05001421
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001422 if ($status !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001423 {
patworkb0707982011-04-08 15:10:05 +02001424 $this->_set_error_message('lang:email_exit_status', $status);
1425 $this->_set_error_message('lang:email_no_socket');
Derek Allard2067d1a2008-11-13 22:59:24 +00001426 return FALSE;
1427 }
1428
Derek Allard2067d1a2008-11-13 22:59:24 +00001429 return TRUE;
1430 }
Barry Mienydd671972010-10-04 16:33:58 +02001431
Derek Allard2067d1a2008-11-13 22:59:24 +00001432 // --------------------------------------------------------------------
1433
1434 /**
1435 * Send using SMTP
1436 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001437 * @return bool
1438 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001439 protected function _send_with_smtp()
Derek Allard2067d1a2008-11-13 22:59:24 +00001440 {
1441 if ($this->smtp_host == '')
1442 {
patworkb0707982011-04-08 15:10:05 +02001443 $this->_set_error_message('lang:email_no_hostname');
Derek Allard2067d1a2008-11-13 22:59:24 +00001444 return FALSE;
1445 }
1446
Diogo Osório593f7982012-03-02 18:04:17 +00001447 if ( ! $this->_smtp_connect() OR ! $this->_smtp_authenticate())
Diogo Osório7fcc7bd2012-03-02 16:54:52 +00001448 {
1449 return FALSE;
1450 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001451
1452 $this->_send_command('from', $this->clean_email($this->_headers['From']));
1453
Pascal Kriete14287f32011-02-14 13:39:34 -05001454 foreach ($this->_recipients as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001455 {
1456 $this->_send_command('to', $val);
1457 }
1458
1459 if (count($this->_cc_array) > 0)
1460 {
Pascal Kriete14287f32011-02-14 13:39:34 -05001461 foreach ($this->_cc_array as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001462 {
1463 if ($val != "")
1464 {
1465 $this->_send_command('to', $val);
1466 }
1467 }
1468 }
1469
1470 if (count($this->_bcc_array) > 0)
1471 {
Pascal Kriete14287f32011-02-14 13:39:34 -05001472 foreach ($this->_bcc_array as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001473 {
1474 if ($val != "")
1475 {
1476 $this->_send_command('to', $val);
1477 }
1478 }
1479 }
1480
1481 $this->_send_command('data');
1482
1483 // perform dot transformation on any lines that begin with a dot
1484 $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody));
1485
1486 $this->_send_data('.');
1487
1488 $reply = $this->_get_smtp_data();
1489
1490 $this->_set_error_message($reply);
1491
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001492 if (strncmp($reply, '250', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001493 {
patworkb0707982011-04-08 15:10:05 +02001494 $this->_set_error_message('lang:email_smtp_error', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001495 return FALSE;
1496 }
1497
1498 $this->_send_command('quit');
1499 return TRUE;
1500 }
Barry Mienydd671972010-10-04 16:33:58 +02001501
Derek Allard2067d1a2008-11-13 22:59:24 +00001502 // --------------------------------------------------------------------
1503
1504 /**
1505 * SMTP Connect
1506 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001507 * @param string
1508 * @return string
1509 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001510 protected function _smtp_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +00001511 {
Phil Sturgeonc00a5a02011-11-22 15:25:32 +00001512 $ssl = ($this->smtp_crypto == 'ssl') ? 'ssl://' : NULL;
Radu Potop4c589ae2011-09-29 10:19:55 +03001513
Radu Potopbbf04b02011-09-28 13:57:51 +03001514 $this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
Derek Allard2067d1a2008-11-13 22:59:24 +00001515 $this->smtp_port,
1516 $errno,
1517 $errstr,
1518 $this->smtp_timeout);
1519
Pascal Kriete14287f32011-02-14 13:39:34 -05001520 if ( ! is_resource($this->_smtp_connect))
Derek Allard2067d1a2008-11-13 22:59:24 +00001521 {
patworkb0707982011-04-08 15:10:05 +02001522 $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr);
Derek Allard2067d1a2008-11-13 22:59:24 +00001523 return FALSE;
1524 }
1525
1526 $this->_set_error_message($this->_get_smtp_data());
Radu Potopbbf04b02011-09-28 13:57:51 +03001527
1528 if ($this->smtp_crypto == 'tls')
1529 {
1530 $this->_send_command('hello');
1531 $this->_send_command('starttls');
Phil Sturgeonc00a5a02011-11-22 15:25:32 +00001532
Radu Potop4c589ae2011-09-29 10:19:55 +03001533 $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
Radu Potop4c589ae2011-09-29 10:19:55 +03001534
Sean Fishere862ddd2011-10-26 22:45:00 -03001535 if ($crypto !== TRUE)
1536 {
1537 $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data());
1538 return FALSE;
1539 }
Radu Potopbbf04b02011-09-28 13:57:51 +03001540 }
1541
Derek Allard2067d1a2008-11-13 22:59:24 +00001542 return $this->_send_command('hello');
1543 }
Barry Mienydd671972010-10-04 16:33:58 +02001544
Derek Allard2067d1a2008-11-13 22:59:24 +00001545 // --------------------------------------------------------------------
1546
1547 /**
1548 * Send SMTP command
1549 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001550 * @param string
1551 * @param string
1552 * @return string
1553 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001554 protected function _send_command($cmd, $data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001555 {
1556 switch ($cmd)
1557 {
1558 case 'hello' :
1559
1560 if ($this->_smtp_auth OR $this->_get_encoding() == '8bit')
1561 $this->_send_data('EHLO '.$this->_get_hostname());
1562 else
1563 $this->_send_data('HELO '.$this->_get_hostname());
1564
1565 $resp = 250;
1566 break;
Radu Potopbbf04b02011-09-28 13:57:51 +03001567 case 'starttls' :
1568
1569 $this->_send_data('STARTTLS');
1570
1571 $resp = 220;
1572 break;
Derek Allard2067d1a2008-11-13 22:59:24 +00001573 case 'from' :
1574
1575 $this->_send_data('MAIL FROM:<'.$data.'>');
1576
1577 $resp = 250;
1578 break;
1579 case 'to' :
1580
1581 $this->_send_data('RCPT TO:<'.$data.'>');
1582
1583 $resp = 250;
1584 break;
1585 case 'data' :
1586
1587 $this->_send_data('DATA');
1588
1589 $resp = 354;
1590 break;
1591 case 'quit' :
1592
1593 $this->_send_data('QUIT');
1594
1595 $resp = 221;
1596 break;
1597 }
1598
1599 $reply = $this->_get_smtp_data();
1600
1601 $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>";
1602
1603 if (substr($reply, 0, 3) != $resp)
1604 {
patworkb0707982011-04-08 15:10:05 +02001605 $this->_set_error_message('lang:email_smtp_error', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001606 return FALSE;
1607 }
1608
1609 if ($cmd == 'quit')
1610 {
1611 fclose($this->_smtp_connect);
1612 }
1613
1614 return TRUE;
1615 }
Barry Mienydd671972010-10-04 16:33:58 +02001616
Derek Allard2067d1a2008-11-13 22:59:24 +00001617 // --------------------------------------------------------------------
1618
1619 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -05001620 * SMTP Authenticate
Derek Allard2067d1a2008-11-13 22:59:24 +00001621 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001622 * @return bool
1623 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001624 protected function _smtp_authenticate()
Derek Allard2067d1a2008-11-13 22:59:24 +00001625 {
1626 if ( ! $this->_smtp_auth)
1627 {
1628 return TRUE;
1629 }
1630
Andrey Andreev76f15c92012-03-01 13:05:07 +02001631 if ($this->smtp_user == '' && $this->smtp_pass == '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001632 {
patworkb0707982011-04-08 15:10:05 +02001633 $this->_set_error_message('lang:email_no_smtp_unpw');
Derek Allard2067d1a2008-11-13 22:59:24 +00001634 return FALSE;
1635 }
1636
1637 $this->_send_data('AUTH LOGIN');
1638
1639 $reply = $this->_get_smtp_data();
1640
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001641 if (strncmp($reply, '334', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001642 {
patworkb0707982011-04-08 15:10:05 +02001643 $this->_set_error_message('lang:email_failed_smtp_login', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001644 return FALSE;
1645 }
1646
1647 $this->_send_data(base64_encode($this->smtp_user));
1648
1649 $reply = $this->_get_smtp_data();
1650
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001651 if (strncmp($reply, '334', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001652 {
patworkb0707982011-04-08 15:10:05 +02001653 $this->_set_error_message('lang:email_smtp_auth_un', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001654 return FALSE;
1655 }
1656
1657 $this->_send_data(base64_encode($this->smtp_pass));
1658
1659 $reply = $this->_get_smtp_data();
1660
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001661 if (strncmp($reply, '235', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001662 {
patworkb0707982011-04-08 15:10:05 +02001663 $this->_set_error_message('lang:email_smtp_auth_pw', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001664 return FALSE;
1665 }
1666
1667 return TRUE;
1668 }
Barry Mienydd671972010-10-04 16:33:58 +02001669
Derek Allard2067d1a2008-11-13 22:59:24 +00001670 // --------------------------------------------------------------------
1671
1672 /**
1673 * Send SMTP data
1674 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001675 * @return bool
1676 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001677 protected function _send_data($data)
Derek Allard2067d1a2008-11-13 22:59:24 +00001678 {
1679 if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
1680 {
patworkb0707982011-04-08 15:10:05 +02001681 $this->_set_error_message('lang:email_smtp_data_failure', $data);
Derek Allard2067d1a2008-11-13 22:59:24 +00001682 return FALSE;
1683 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001684
1685 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001686 }
Barry Mienydd671972010-10-04 16:33:58 +02001687
Derek Allard2067d1a2008-11-13 22:59:24 +00001688 // --------------------------------------------------------------------
1689
1690 /**
1691 * Get SMTP data
1692 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001693 * @return string
1694 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001695 protected function _get_smtp_data()
Derek Allard2067d1a2008-11-13 22:59:24 +00001696 {
1697 $data = "";
1698
1699 while ($str = fgets($this->_smtp_connect, 512))
1700 {
1701 $data .= $str;
1702
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001703 if ($str[3] == " ")
Derek Allard2067d1a2008-11-13 22:59:24 +00001704 {
1705 break;
1706 }
1707 }
1708
1709 return $data;
1710 }
Barry Mienydd671972010-10-04 16:33:58 +02001711
Derek Allard2067d1a2008-11-13 22:59:24 +00001712 // --------------------------------------------------------------------
1713
1714 /**
1715 * Get Hostname
1716 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001717 * @return string
1718 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001719 protected function _get_hostname()
Derek Allard2067d1a2008-11-13 22:59:24 +00001720 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001721 return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
Derek Allard2067d1a2008-11-13 22:59:24 +00001722 }
Barry Mienydd671972010-10-04 16:33:58 +02001723
Derek Allard2067d1a2008-11-13 22:59:24 +00001724 // --------------------------------------------------------------------
1725
1726 /**
1727 * Get IP
1728 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001729 * @return string
1730 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001731 protected function _get_ip()
Derek Allard2067d1a2008-11-13 22:59:24 +00001732 {
1733 if ($this->_IP !== FALSE)
1734 {
1735 return $this->_IP;
1736 }
1737
Andrey Andreev76f15c92012-03-01 13:05:07 +02001738 $cip = ( ! empty($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
1739 $rip = ( ! empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : FALSE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001740 if ($cip) $this->_IP = $cip;
1741 elseif ($rip) $this->_IP = $rip;
1742 else
1743 {
Andrey Andreev76f15c92012-03-01 13:05:07 +02001744 $fip = ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001745 if ($fip)
1746 {
1747 $this->_IP = $fip;
1748 }
1749 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001750
Robin Sowell76b369e2010-03-19 11:15:28 -04001751 if (strpos($this->_IP, ',') !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001752 {
1753 $x = explode(',', $this->_IP);
1754 $this->_IP = end($x);
1755 }
1756
Andrey Andreev59c5b532012-03-01 14:09:51 +02001757 if ( ! preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $this->_IP))
Derek Allard2067d1a2008-11-13 22:59:24 +00001758 {
1759 $this->_IP = '0.0.0.0';
1760 }
1761
Derek Allard2067d1a2008-11-13 22:59:24 +00001762 return $this->_IP;
1763 }
Barry Mienydd671972010-10-04 16:33:58 +02001764
Derek Allard2067d1a2008-11-13 22:59:24 +00001765 // --------------------------------------------------------------------
1766
1767 /**
1768 * Get Debug Message
1769 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001770 * @return string
1771 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001772 public function print_debugger()
Derek Allard2067d1a2008-11-13 22:59:24 +00001773 {
1774 $msg = '';
1775
1776 if (count($this->_debug_msg) > 0)
1777 {
1778 foreach ($this->_debug_msg as $val)
1779 {
1780 $msg .= $val;
1781 }
1782 }
1783
Andrey Andreev59c5b532012-03-01 14:09:51 +02001784 return $msg.'<pre>'.$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
Derek Allard2067d1a2008-11-13 22:59:24 +00001785 }
Barry Mienydd671972010-10-04 16:33:58 +02001786
Derek Allard2067d1a2008-11-13 22:59:24 +00001787 // --------------------------------------------------------------------
1788
1789 /**
1790 * Set Message
1791 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001792 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +02001793 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00001794 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001795 protected function _set_error_message($msg, $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001796 {
1797 $CI =& get_instance();
1798 $CI->lang->load('email');
1799
Andrey Andreev76f15c92012-03-01 13:05:07 +02001800 if (substr($msg, 0, 5) !== 'lang:' OR FALSE === ($line = $CI->lang->line(substr($msg, 5))))
Derek Allard2067d1a2008-11-13 22:59:24 +00001801 {
1802 $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
1803 }
1804 else
1805 {
1806 $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />";
1807 }
1808 }
Barry Mienydd671972010-10-04 16:33:58 +02001809
Derek Allard2067d1a2008-11-13 22:59:24 +00001810 // --------------------------------------------------------------------
1811
1812 /**
1813 * Mime Types
1814 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001815 * @param string
1816 * @return string
1817 */
Andrey Andreev59c5b532012-03-01 14:09:51 +02001818 protected function _mime_types($ext = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001819 {
Andrey Andreev59c5b532012-03-01 14:09:51 +02001820 $mimes = array(
1821 'hqx' => 'application/mac-binhex40',
Derek Allard2067d1a2008-11-13 22:59:24 +00001822 'cpt' => 'application/mac-compactpro',
1823 'doc' => 'application/msword',
1824 'bin' => 'application/macbinary',
1825 'dms' => 'application/octet-stream',
1826 'lha' => 'application/octet-stream',
1827 'lzh' => 'application/octet-stream',
1828 'exe' => 'application/octet-stream',
1829 'class' => 'application/octet-stream',
1830 'psd' => 'application/octet-stream',
1831 'so' => 'application/octet-stream',
1832 'sea' => 'application/octet-stream',
1833 'dll' => 'application/octet-stream',
1834 'oda' => 'application/oda',
1835 'pdf' => 'application/pdf',
1836 'ai' => 'application/postscript',
1837 'eps' => 'application/postscript',
1838 'ps' => 'application/postscript',
1839 'smi' => 'application/smil',
1840 'smil' => 'application/smil',
1841 'mif' => 'application/vnd.mif',
1842 'xls' => 'application/vnd.ms-excel',
1843 'ppt' => 'application/vnd.ms-powerpoint',
1844 'wbxml' => 'application/vnd.wap.wbxml',
1845 'wmlc' => 'application/vnd.wap.wmlc',
1846 'dcr' => 'application/x-director',
1847 'dir' => 'application/x-director',
1848 'dxr' => 'application/x-director',
1849 'dvi' => 'application/x-dvi',
1850 'gtar' => 'application/x-gtar',
1851 'php' => 'application/x-httpd-php',
1852 'php4' => 'application/x-httpd-php',
1853 'php3' => 'application/x-httpd-php',
1854 'phtml' => 'application/x-httpd-php',
1855 'phps' => 'application/x-httpd-php-source',
1856 'js' => 'application/x-javascript',
1857 'swf' => 'application/x-shockwave-flash',
1858 'sit' => 'application/x-stuffit',
1859 'tar' => 'application/x-tar',
1860 'tgz' => 'application/x-tar',
1861 'xhtml' => 'application/xhtml+xml',
1862 'xht' => 'application/xhtml+xml',
1863 'zip' => 'application/zip',
1864 'mid' => 'audio/midi',
1865 'midi' => 'audio/midi',
1866 'mpga' => 'audio/mpeg',
1867 'mp2' => 'audio/mpeg',
1868 'mp3' => 'audio/mpeg',
1869 'aif' => 'audio/x-aiff',
1870 'aiff' => 'audio/x-aiff',
1871 'aifc' => 'audio/x-aiff',
1872 'ram' => 'audio/x-pn-realaudio',
1873 'rm' => 'audio/x-pn-realaudio',
1874 'rpm' => 'audio/x-pn-realaudio-plugin',
1875 'ra' => 'audio/x-realaudio',
1876 'rv' => 'video/vnd.rn-realvideo',
1877 'wav' => 'audio/x-wav',
1878 'bmp' => 'image/bmp',
1879 'gif' => 'image/gif',
1880 'jpeg' => 'image/jpeg',
1881 'jpg' => 'image/jpeg',
1882 'jpe' => 'image/jpeg',
1883 'png' => 'image/png',
1884 'tiff' => 'image/tiff',
1885 'tif' => 'image/tiff',
1886 'css' => 'text/css',
1887 'html' => 'text/html',
1888 'htm' => 'text/html',
1889 'shtml' => 'text/html',
1890 'txt' => 'text/plain',
1891 'text' => 'text/plain',
1892 'log' => 'text/plain',
1893 'rtx' => 'text/richtext',
1894 'rtf' => 'text/rtf',
1895 'xml' => 'text/xml',
1896 'xsl' => 'text/xml',
1897 'mpeg' => 'video/mpeg',
1898 'mpg' => 'video/mpeg',
1899 'mpe' => 'video/mpeg',
1900 'qt' => 'video/quicktime',
1901 'mov' => 'video/quicktime',
1902 'avi' => 'video/x-msvideo',
1903 'movie' => 'video/x-sgi-movie',
1904 'doc' => 'application/msword',
1905 'word' => 'application/msword',
1906 'xl' => 'application/excel',
1907 'eml' => 'message/rfc822'
1908 );
1909
Andrey Andreev59c5b532012-03-01 14:09:51 +02001910 return isset($mimes[strtolower($ext)]) ? $mimes[strtolower($ext)] : 'application/x-unknown-content-type';
Derek Allard2067d1a2008-11-13 22:59:24 +00001911 }
1912
1913}
Derek Allard2067d1a2008-11-13 22:59:24 +00001914
1915/* End of file Email.php */
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001916/* Location: ./system/libraries/Email.php */