blob: f1b18ab4fb9e8bf5c63a8ebb16e89fcedadfd63a [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 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 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 Andreev1bd3d882011-12-22 15:38:20 +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.
63 public $bcc_batch_mode = FALSE; // TRUE/FALSE Turns on/off Bcc batch feature
64 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 Andreev1bd3d882011-12-22 15:38:20 +0200105 $this->_safe_mode = (bool) @ini_get("safe_mode");
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 }
107
108 log_message('debug', "Email Class Initialized");
109 }
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 Andreev1bd3d882011-12-22 15:38:20 +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 {
155 $this->_subject = "";
156 $this->_body = "";
157 $this->_finalbody = "";
158 $this->_header_str = "";
159 $this->_replyto_flag = FALSE;
160 $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 {
190 if (preg_match( '/\<(.*)\>/', $from, $match))
191 {
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 {
232 if (preg_match( '/\<(.*)\>/', $replyto, $match))
233 {
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 {
278 $this->_set_header('To', implode(", ", $to));
279 }
280
281 switch ($this->_get_protocol())
282 {
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000283 case 'smtp' :
284 $this->_recipients = $to;
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 break;
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000286 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
313 $this->_set_header('Cc', implode(", ", $cc));
314
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 {
354 $this->_set_header('Bcc', implode(", ", $bcc));
355 }
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 {
diegorivera33c32802011-10-19 02:56:15 -0200385 $this->_body = rtrim(str_replace("\r", "", $body));
386
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 */
trit10eb14d2011-11-23 15:48:21 -0500409 public function attach($filename, $disposition = '', $newname = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 {
trit151fc682011-11-23 07:30:06 -0500411 $this->_attach_name[] = array($filename, $newname);
Phil Sturgeon0aaf42b2011-08-10 08:06:37 -0600412 $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
tritd5269982011-11-23 17:22:44 -0500413 $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters
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 {
449 $email = trim($email);
450 settype($email, "array");
451 }
452 }
453 return $email;
454 }
Barry Mienydd671972010-10-04 16:33:58 +0200455
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 // --------------------------------------------------------------------
457
458 /**
459 * Set Multipart Value
460 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000461 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200462 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000464 public function set_alt_message($str = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 {
Dan Horrigand0ddeaf2011-08-21 09:07:27 -0400466 $this->alt_message = (string) $str;
Greg Akera769deb2010-11-10 15:47:29 -0600467 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 }
Barry Mienydd671972010-10-04 16:33:58 +0200469
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 // --------------------------------------------------------------------
471
472 /**
473 * Set Mailtype
474 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000475 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200476 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000478 public function set_mailtype($type = 'text')
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 {
480 $this->mailtype = ($type == 'html') ? 'html' : 'text';
Greg Akera769deb2010-11-10 15:47:29 -0600481 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 }
Barry Mienydd671972010-10-04 16:33:58 +0200483
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 // --------------------------------------------------------------------
485
486 /**
487 * Set Wordwrap
488 *
Dan Horrigan628e6602011-08-21 09:08:31 -0400489 * @param bool
Andrey Andreev081c9462012-03-01 12:58:11 +0200490 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000491 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000492 public function set_wordwrap($wordwrap = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 {
Dan Horrigan628e6602011-08-21 09:08:31 -0400494 $this->wordwrap = (bool) $wordwrap;
Greg Akera769deb2010-11-10 15:47:29 -0600495 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 }
Barry Mienydd671972010-10-04 16:33:58 +0200497
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 // --------------------------------------------------------------------
499
500 /**
501 * Set Protocol
502 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200504 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000505 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000506 public function set_protocol($protocol = 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000507 {
508 $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol);
Greg Akera769deb2010-11-10 15:47:29 -0600509 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 }
Barry Mienydd671972010-10-04 16:33:58 +0200511
Derek Allard2067d1a2008-11-13 22:59:24 +0000512 // --------------------------------------------------------------------
513
514 /**
515 * Set Priority
516 *
Andrey Andreev081c9462012-03-01 12:58:11 +0200517 * @param int
518 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000520 public function set_priority($n = 3)
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200522 if ( ! is_numeric($n) OR $n < 1 OR $n > 5)
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 {
524 $this->priority = 3;
525 return;
526 }
527
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200528 $this->priority = (int) $n;
Greg Akera769deb2010-11-10 15:47:29 -0600529 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 }
Barry Mienydd671972010-10-04 16:33:58 +0200531
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 // --------------------------------------------------------------------
533
534 /**
535 * Set Newline Character
536 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200538 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000540 public function set_newline($newline = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000541 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200542 $this->newline = in_array($newline, array("\n", "\r\n", "\r")) ? $newline : "\n";
Greg Akera769deb2010-11-10 15:47:29 -0600543 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000544 }
Barry Mienydd671972010-10-04 16:33:58 +0200545
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 // --------------------------------------------------------------------
547
548 /**
549 * Set CRLF
550 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200552 * @return object
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000554 public function set_crlf($crlf = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000555 {
Andrey Andreev76f15c92012-03-01 13:05:07 +0200556 $this->crlf = ($crlf !== "\n" && $crlf !== "\r\n" && $crlf !== "\r") ? "\n" : $crlf;
Greg Akera769deb2010-11-10 15:47:29 -0600557 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 }
Barry Mienydd671972010-10-04 16:33:58 +0200559
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 // --------------------------------------------------------------------
561
562 /**
563 * Set Message Boundary
564 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000565 * @return void
566 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600567 protected function _set_boundaries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 {
569 $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative
570 $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary
571 }
Barry Mienydd671972010-10-04 16:33:58 +0200572
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 // --------------------------------------------------------------------
574
575 /**
576 * Get the Message ID
577 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000578 * @return string
579 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600580 protected function _get_message_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200582 $from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000583
Derek Jones37f4b9c2011-07-01 17:56:50 -0500584 return "<".uniqid('').strstr($from, '@').">";
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 }
Barry Mienydd671972010-10-04 16:33:58 +0200586
Derek Allard2067d1a2008-11-13 22:59:24 +0000587 // --------------------------------------------------------------------
588
589 /**
590 * Get Mail Protocol
591 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000592 * @param bool
593 * @return string
594 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600595 protected function _get_protocol($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000596 {
597 $this->protocol = strtolower($this->protocol);
598 $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
599
600 if ($return == TRUE)
601 {
602 return $this->protocol;
603 }
604 }
Barry Mienydd671972010-10-04 16:33:58 +0200605
Derek Allard2067d1a2008-11-13 22:59:24 +0000606 // --------------------------------------------------------------------
607
608 /**
609 * Get Mail Encoding
610 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000611 * @param bool
612 * @return string
613 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600614 protected function _get_encoding($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000615 {
616 $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
617
618 foreach ($this->_base_charsets as $charset)
619 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200620 if (strncmp($charset, $this->charset, strlen($charset)) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 {
622 $this->_encoding = '7bit';
623 }
624 }
625
626 if ($return == TRUE)
627 {
628 return $this->_encoding;
629 }
630 }
631
632 // --------------------------------------------------------------------
633
634 /**
635 * Get content type (text/html/attachment)
636 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000637 * @return string
638 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600639 protected function _get_content_type()
Derek Allard2067d1a2008-11-13 22:59:24 +0000640 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200641 if ($this->mailtype === 'html' && count($this->_attach_name) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 {
643 return 'html';
644 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200645 elseif ($this->mailtype === 'html' && count($this->_attach_name) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000646 {
647 return 'html-attach';
648 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200649 elseif ($this->mailtype === 'text' && count($this->_attach_name) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000650 {
651 return 'plain-attach';
652 }
653 else
654 {
655 return 'plain';
656 }
657 }
Barry Mienydd671972010-10-04 16:33:58 +0200658
Derek Allard2067d1a2008-11-13 22:59:24 +0000659 // --------------------------------------------------------------------
660
661 /**
662 * Set RFC 822 Date
663 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000664 * @return string
665 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600666 protected function _set_date()
Derek Allard2067d1a2008-11-13 22:59:24 +0000667 {
668 $timezone = date("Z");
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200669 $operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+';
Derek Allard2067d1a2008-11-13 22:59:24 +0000670 $timezone = abs($timezone);
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200671 $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
Derek Allard2067d1a2008-11-13 22:59:24 +0000672
673 return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone);
674 }
Barry Mienydd671972010-10-04 16:33:58 +0200675
Derek Allard2067d1a2008-11-13 22:59:24 +0000676 // --------------------------------------------------------------------
677
678 /**
679 * Mime message
680 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000681 * @return string
682 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600683 protected function _get_mime_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000684 {
685 return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format.";
686 }
Barry Mienydd671972010-10-04 16:33:58 +0200687
Derek Allard2067d1a2008-11-13 22:59:24 +0000688 // --------------------------------------------------------------------
689
690 /**
691 * Validate Email Address
692 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000693 * @param string
694 * @return bool
695 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000696 public function validate_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000697 {
698 if ( ! is_array($email))
699 {
patworkb0707982011-04-08 15:10:05 +0200700 $this->_set_error_message('lang:email_must_be_array');
Derek Allard2067d1a2008-11-13 22:59:24 +0000701 return FALSE;
702 }
703
704 foreach ($email as $val)
705 {
706 if ( ! $this->valid_email($val))
707 {
patworkb0707982011-04-08 15:10:05 +0200708 $this->_set_error_message('lang:email_invalid_address', $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000709 return FALSE;
710 }
711 }
712
713 return TRUE;
714 }
Barry Mienydd671972010-10-04 16:33:58 +0200715
Derek Allard2067d1a2008-11-13 22:59:24 +0000716 // --------------------------------------------------------------------
717
718 /**
719 * Email Validation
720 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000721 * @param string
722 * @return bool
723 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000724 public function valid_email($address)
Derek Allard2067d1a2008-11-13 22:59:24 +0000725 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200726 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 +0000727 }
Barry Mienydd671972010-10-04 16:33:58 +0200728
Derek Allard2067d1a2008-11-13 22:59:24 +0000729 // --------------------------------------------------------------------
730
731 /**
732 * Clean Extended Email Address: Joe Smith <joe@smith.com>
733 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000734 * @param string
735 * @return string
736 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000737 public function clean_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000738 {
739 if ( ! is_array($email))
740 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200741 return (preg_match('/\<(.*)\>/', $email, $match)) ? $match[1] : $email;
Derek Allard2067d1a2008-11-13 22:59:24 +0000742 }
743
744 $clean_email = array();
745
746 foreach ($email as $addy)
747 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200748 $clean_email[] = (preg_match( '/\<(.*)\>/', $addy, $match)) ? $match[1] : $addy;
Derek Allard2067d1a2008-11-13 22:59:24 +0000749 }
750
751 return $clean_email;
752 }
Barry Mienydd671972010-10-04 16:33:58 +0200753
Derek Allard2067d1a2008-11-13 22:59:24 +0000754 // --------------------------------------------------------------------
755
756 /**
757 * Build alternative plain text message
758 *
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000759 * This public function provides the raw message for use
Derek Allard2067d1a2008-11-13 22:59:24 +0000760 * in plain-text headers of HTML-formatted emails.
761 * If the user hasn't specified his own alternative message
762 * it creates one by stripping the HTML
763 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000764 * @return string
765 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600766 protected function _get_alt_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000767 {
768 if ($this->alt_message != "")
769 {
770 return $this->word_wrap($this->alt_message, '76');
771 }
772
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200773 $body = (preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match)) ? $match[1] : $this->_body;
774 $body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000775
776 for ($i = 20; $i >= 3; $i--)
777 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200778 $body = str_replace(str_repeat("\n", $i), "\n\n", $body);
Derek Allard2067d1a2008-11-13 22:59:24 +0000779 }
780
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200781 return $this->word_wrap($body, 76);
Derek Allard2067d1a2008-11-13 22:59:24 +0000782 }
Barry Mienydd671972010-10-04 16:33:58 +0200783
Derek Allard2067d1a2008-11-13 22:59:24 +0000784 // --------------------------------------------------------------------
785
786 /**
787 * Word Wrap
788 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000789 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +0200790 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +0000791 * @return string
792 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000793 public function word_wrap($str, $charlim = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000794 {
795 // Se the character limit
796 if ($charlim == '')
797 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200798 $charlim = ($this->wrapchars == "") ? 76 : $this->wrapchars;
Derek Allard2067d1a2008-11-13 22:59:24 +0000799 }
800
801 // Reduce multiple spaces
802 $str = preg_replace("| +|", " ", $str);
803
804 // Standardize newlines
805 if (strpos($str, "\r") !== FALSE)
806 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200807 $str = str_replace(array("\r\n", "\r"), "\n", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000808 }
809
810 // If the current word is surrounded by {unwrap} tags we'll
811 // strip the entire chunk and replace it with a marker.
812 $unwrap = array();
813 if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
814 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200815 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000816 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200817 $unwrap[] = $matches[1][$i];
818 $str = str_replace($matches[1][$i], "{{unwrapped".$i."}}", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000819 }
820 }
821
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000822 // Use PHP's native public function to do the initial wordwrap.
Derek Allard2067d1a2008-11-13 22:59:24 +0000823 // We set the cut flag to FALSE so that any individual words that are
Derek Jones37f4b9c2011-07-01 17:56:50 -0500824 // too long get left alone. In the next step we'll deal with them.
Derek Allard2067d1a2008-11-13 22:59:24 +0000825 $str = wordwrap($str, $charlim, "\n", FALSE);
826
827 // Split the string into individual lines of text and cycle through them
828 $output = "";
829 foreach (explode("\n", $str) as $line)
830 {
831 // Is the line within the allowed character count?
832 // If so we'll join it to the output and continue
833 if (strlen($line) <= $charlim)
834 {
835 $output .= $line.$this->newline;
836 continue;
837 }
838
839 $temp = '';
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200840 do
Derek Allard2067d1a2008-11-13 22:59:24 +0000841 {
842 // If the over-length word is a URL we won't wrap it
843 if (preg_match("!\[url.+\]|://|wwww.!", $line))
844 {
845 break;
846 }
847
848 // Trim the word down
849 $temp .= substr($line, 0, $charlim-1);
850 $line = substr($line, $charlim-1);
851 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200852 while (strlen($line) > $charlim);
Derek Allard2067d1a2008-11-13 22:59:24 +0000853
854 // If $temp contains data it means we had to split up an over-length
855 // word into smaller chunks so we'll add it back to our current line
856 if ($temp != '')
857 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200858 $output .= $temp.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000859 }
860
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200861 $output .= $line.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000862 }
863
864 // Put our markers back
865 if (count($unwrap) > 0)
866 {
867 foreach ($unwrap as $key => $val)
868 {
869 $output = str_replace("{{unwrapped".$key."}}", $val, $output);
870 }
871 }
872
873 return $output;
874 }
Barry Mienydd671972010-10-04 16:33:58 +0200875
Derek Allard2067d1a2008-11-13 22:59:24 +0000876 // --------------------------------------------------------------------
877
878 /**
879 * Build final headers
880 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000881 * @return string
882 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600883 protected function _build_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +0000884 {
885 $this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
886 $this->_set_header('X-Mailer', $this->useragent);
887 $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]);
888 $this->_set_header('Message-ID', $this->_get_message_id());
889 $this->_set_header('Mime-Version', '1.0');
890 }
Barry Mienydd671972010-10-04 16:33:58 +0200891
Derek Allard2067d1a2008-11-13 22:59:24 +0000892 // --------------------------------------------------------------------
893
894 /**
895 * Write Headers as a string
896 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000897 * @return void
898 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600899 protected function _write_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +0000900 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200901 if ($this->protocol === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000902 {
903 $this->_subject = $this->_headers['Subject'];
904 unset($this->_headers['Subject']);
905 }
906
907 reset($this->_headers);
908 $this->_header_str = "";
909
Pascal Kriete14287f32011-02-14 13:39:34 -0500910 foreach ($this->_headers as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000911 {
912 $val = trim($val);
913
914 if ($val != "")
915 {
916 $this->_header_str .= $key.": ".$val.$this->newline;
917 }
918 }
919
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200920 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000921 {
Derek Jones1d890882009-02-10 20:32:14 +0000922 $this->_header_str = rtrim($this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000923 }
924 }
Barry Mienydd671972010-10-04 16:33:58 +0200925
Derek Allard2067d1a2008-11-13 22:59:24 +0000926 // --------------------------------------------------------------------
927
928 /**
929 * Build Final Body and attachments
930 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000931 * @return void
932 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600933 protected function _build_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000934 {
Andrey Andreev76f15c92012-03-01 13:05:07 +0200935 if ($this->wordwrap === TRUE && $this->mailtype !== 'html')
Derek Allard2067d1a2008-11-13 22:59:24 +0000936 {
937 $this->_body = $this->word_wrap($this->_body);
938 }
939
940 $this->_set_boundaries();
941 $this->_write_headers();
942
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200943 $hdr = ($this->_get_protocol() === 'mail') ? $this->newline : '';
Brandon Jones485d7412010-11-09 16:38:17 -0500944 $body = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000945
946 switch ($this->_get_content_type())
947 {
948 case 'plain' :
949
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200950 $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline
951 . "Content-Transfer-Encoding: " . $this->_get_encoding();
Derek Allard2067d1a2008-11-13 22:59:24 +0000952
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200953 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000954 {
955 $this->_header_str .= $hdr;
956 $this->_finalbody = $this->_body;
Derek Allard2067d1a2008-11-13 22:59:24 +0000957 }
Brandon Jones485d7412010-11-09 16:38:17 -0500958 else
959 {
960 $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body;
961 }
Eric Barnes6113f542010-12-29 13:36:12 -0500962
Derek Allard2067d1a2008-11-13 22:59:24 +0000963 return;
964
Derek Allard2067d1a2008-11-13 22:59:24 +0000965 case 'html' :
966
967 if ($this->send_multipart === FALSE)
968 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200969 $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline
970 . "Content-Transfer-Encoding: quoted-printable";
Derek Allard2067d1a2008-11-13 22:59:24 +0000971 }
972 else
973 {
Derek Jonesa45e7612009-02-10 18:33:01 +0000974 $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000975
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200976 $body .= $this->_get_mime_message() . $this->newline . $this->newline
977 . "--" . $this->_alt_boundary . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +0000978
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200979 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
980 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
981 . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -0500982
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200983 . "Content-Type: text/html; charset=" . $this->charset . $this->newline
984 . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000985 }
Eric Barnes6113f542010-12-29 13:36:12 -0500986
Brandon Jones485d7412010-11-09 16:38:17 -0500987 $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -0500988
989
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200990 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000991 {
992 $this->_header_str .= $hdr;
Brandon Jones485d7412010-11-09 16:38:17 -0500993 }
994 else
995 {
996 $this->_finalbody = $hdr . $this->_finalbody;
Derek Allard2067d1a2008-11-13 22:59:24 +0000997 }
998
Derek Allard2067d1a2008-11-13 22:59:24 +0000999
1000 if ($this->send_multipart !== FALSE)
1001 {
Brandon Jones485d7412010-11-09 16:38:17 -05001002 $this->_finalbody .= "--" . $this->_alt_boundary . "--";
Derek Allard2067d1a2008-11-13 22:59:24 +00001003 }
1004
Derek Allard2067d1a2008-11-13 22:59:24 +00001005 return;
1006
Derek Allard2067d1a2008-11-13 22:59:24 +00001007 case 'plain-attach' :
1008
Derek Jonesa45e7612009-02-10 18:33:01 +00001009 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001010
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001011 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001012 {
1013 $this->_header_str .= $hdr;
Eric Barnes6113f542010-12-29 13:36:12 -05001014 }
1015
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001016 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1017 . "--" . $this->_atc_boundary . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001018
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001019 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1020 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001021
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001022 . $this->_body . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001023
1024 break;
1025 case 'html-attach' :
1026
Derek Jonesa45e7612009-02-10 18:33:01 +00001027 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -05001028
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001029 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001030 {
1031 $this->_header_str .= $hdr;
Derek Allard2067d1a2008-11-13 22:59:24 +00001032 }
1033
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001034 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1035 . "--" . $this->_atc_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001036
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001037 . "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline
1038 . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001039
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001040 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1041 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
1042 . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001043
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001044 . "Content-Type: text/html; charset=" . $this->charset . $this->newline
1045 . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001046
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001047 . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline
1048 . "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001049
1050 break;
1051 }
1052
1053 $attachment = array();
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001054 for ($i = 0, $c = count($this->_attach_name), $z = 0; $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001055 {
tritbc4ac992011-11-23 07:19:41 -05001056 $filename = $this->_attach_name[$i][0];
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001057 $basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1];
Derek Allard2067d1a2008-11-13 22:59:24 +00001058 $ctype = $this->_attach_type[$i];
1059
tritbc4ac992011-11-23 07:19:41 -05001060 if ( ! file_exists($filename))
Derek Allard2067d1a2008-11-13 22:59:24 +00001061 {
tritbc4ac992011-11-23 07:19:41 -05001062 $this->_set_error_message('lang:email_attachment_missing', $filename);
Derek Allard2067d1a2008-11-13 22:59:24 +00001063 return FALSE;
1064 }
1065
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001066 $attachment[$z++] = "--".$this->_atc_boundary.$this->newline
1067 . "Content-type: ".$ctype."; "
1068 . "name=\"".$basename."\"".$this->newline
1069 . "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline
1070 . "Content-Transfer-Encoding: base64".$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001071
tritbc4ac992011-11-23 07:19:41 -05001072 $file = filesize($filename) +1;
Derek Allard2067d1a2008-11-13 22:59:24 +00001073
tritbc4ac992011-11-23 07:19:41 -05001074 if ( ! $fp = fopen($filename, FOPEN_READ))
Derek Allard2067d1a2008-11-13 22:59:24 +00001075 {
tritbc4ac992011-11-23 07:19:41 -05001076 $this->_set_error_message('lang:email_attachment_unreadable', $filename);
Derek Allard2067d1a2008-11-13 22:59:24 +00001077 return FALSE;
1078 }
1079
1080 $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file)));
1081 fclose($fp);
1082 }
1083
Brandon Jones485d7412010-11-09 16:38:17 -05001084 $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001085 $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr . $body;
Derek Allard2067d1a2008-11-13 22:59:24 +00001086 return;
1087 }
Barry Mienydd671972010-10-04 16:33:58 +02001088
Derek Allard2067d1a2008-11-13 22:59:24 +00001089 // --------------------------------------------------------------------
1090
1091 /**
1092 * Prep Quoted Printable
1093 *
1094 * Prepares string for Quoted-Printable Content-Transfer-Encoding
1095 * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
1096 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001097 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +02001098 * @param int
Derek Allard2067d1a2008-11-13 22:59:24 +00001099 * @return string
1100 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001101 protected function _prep_quoted_printable($str, $charlim = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001102 {
1103 // Set the character limit
1104 // Don't allow over 76, as that will make servers and MUAs barf
1105 // all over quoted-printable data
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001106 if ($charlim == '' OR $charlim > 76)
Derek Allard2067d1a2008-11-13 22:59:24 +00001107 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001108 $charlim = 76;
Derek Allard2067d1a2008-11-13 22:59:24 +00001109 }
1110
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001111 // Reduce multiple spaces & remove nulls
1112 $str = preg_replace(array("| +|", '/\x00+/'), array(' ', ''), $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001113
1114 // Standardize newlines
1115 if (strpos($str, "\r") !== FALSE)
1116 {
1117 $str = str_replace(array("\r\n", "\r"), "\n", $str);
1118 }
1119
1120 // We are intentionally wrapping so mail servers will encode characters
1121 // properly and MUAs will behave, so {unwrap} must go!
1122 $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);
1123
Derek Allard2067d1a2008-11-13 22:59:24 +00001124 $escape = '=';
1125 $output = '';
1126
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001127 foreach (explode("\n", $str) as $line)
Derek Allard2067d1a2008-11-13 22:59:24 +00001128 {
1129 $length = strlen($line);
1130 $temp = '';
1131
1132 // Loop through each character in the line to add soft-wrap
1133 // characters at the end of a line " =\r\n" and add the newly
1134 // processed line(s) to the output (see comment on $crlf class property)
1135 for ($i = 0; $i < $length; $i++)
1136 {
1137 // Grab the next character
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001138 $char = $line[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001139 $ascii = ord($char);
1140
1141 // Convert spaces and tabs but only if it's the end of the line
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001142 if ($i === ($length - 1) && ($ascii === 32 OR $ascii === 9))
Derek Allard2067d1a2008-11-13 22:59:24 +00001143 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001144 $char = $escape.sprintf('%02s', dechex($ascii));
Derek Allard2067d1a2008-11-13 22:59:24 +00001145 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001146 elseif ($ascii === 61) // encode = signs
Derek Allard2067d1a2008-11-13 22:59:24 +00001147 {
Derek Jones37f4b9c2011-07-01 17:56:50 -05001148 $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D
Derek Allard2067d1a2008-11-13 22:59:24 +00001149 }
1150
1151 // If we're at the character limit, add the line to the output,
1152 // reset our temp variable, and keep on chuggin'
1153 if ((strlen($temp) + strlen($char)) >= $charlim)
1154 {
1155 $output .= $temp.$escape.$this->crlf;
1156 $temp = '';
1157 }
1158
1159 // Add the character to our temporary line
1160 $temp .= $char;
1161 }
1162
1163 // Add our completed line to the output
1164 $output .= $temp.$this->crlf;
1165 }
1166
1167 // get rid of extra CRLF tacked onto the end
1168 $output = substr($output, 0, strlen($this->crlf) * -1);
1169
1170 return $output;
1171 }
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"
1239 $str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
1240
1241 return $str;
1242 }
1243
1244 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001245
Derek Allard2067d1a2008-11-13 22:59:24 +00001246 /**
1247 * Send Email
1248 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001249 * @return bool
1250 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001251 public function send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001252 {
1253 if ($this->_replyto_flag == FALSE)
1254 {
1255 $this->reply_to($this->_headers['From']);
1256 }
1257
Andrey Andreev76f15c92012-03-01 13:05:07 +02001258 if ( ! isset($this->_recipients) && ! isset($this->_headers['To'])
1259 && ! isset($this->_bcc_array) && ! isset($this->_headers['Bcc'])
1260 && ! isset($this->_headers['Cc']))
Derek Allard2067d1a2008-11-13 22:59:24 +00001261 {
patworkb0707982011-04-08 15:10:05 +02001262 $this->_set_error_message('lang:email_no_recipients');
Derek Allard2067d1a2008-11-13 22:59:24 +00001263 return FALSE;
1264 }
1265
1266 $this->_build_headers();
1267
Andrey Andreev76f15c92012-03-01 13:05:07 +02001268 if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size)
Derek Allard2067d1a2008-11-13 22:59:24 +00001269 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001270 return $this->batch_bcc_send();
Derek Allard2067d1a2008-11-13 22:59:24 +00001271 }
1272
1273 $this->_build_message();
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001274 return $this->_spool_email();
Derek Allard2067d1a2008-11-13 22:59:24 +00001275 }
Barry Mienydd671972010-10-04 16:33:58 +02001276
Derek Allard2067d1a2008-11-13 22:59:24 +00001277 // --------------------------------------------------------------------
1278
1279 /**
Andrey Andreev081c9462012-03-01 12:58:11 +02001280 * Batch Bcc Send. Sends groups of BCCs in batches
Derek Allard2067d1a2008-11-13 22:59:24 +00001281 *
Andrey Andreev081c9462012-03-01 12:58:11 +02001282 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00001283 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001284 public function batch_bcc_send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001285 {
1286 $float = $this->bcc_batch_size -1;
1287
1288 $set = "";
1289
1290 $chunk = array();
1291
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001292 for ($i = 0, $c = count($this->_bcc_array); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001293 {
1294 if (isset($this->_bcc_array[$i]))
1295 {
1296 $set .= ", ".$this->_bcc_array[$i];
1297 }
1298
1299 if ($i == $float)
1300 {
1301 $chunk[] = substr($set, 1);
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001302 $float += $this->bcc_batch_size;
Derek Allard2067d1a2008-11-13 22:59:24 +00001303 $set = "";
1304 }
1305
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001306 if ($i === $c-1)
Derek Allard2067d1a2008-11-13 22:59:24 +00001307 {
1308 $chunk[] = substr($set, 1);
1309 }
1310 }
1311
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001312 for ($i = 0, $c = count($chunk); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001313 {
1314 unset($this->_headers['Bcc']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001315
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001316 $bcc = $this->clean_email($this->_str_to_array($chunk[$i]));
Derek Allard2067d1a2008-11-13 22:59:24 +00001317
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001318 if ($this->protocol !== 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +00001319 {
1320 $this->_set_header('Bcc', implode(", ", $bcc));
1321 }
1322 else
1323 {
1324 $this->_bcc_array = $bcc;
1325 }
1326
1327 $this->_build_message();
1328 $this->_spool_email();
1329 }
1330 }
Barry Mienydd671972010-10-04 16:33:58 +02001331
Derek Allard2067d1a2008-11-13 22:59:24 +00001332 // --------------------------------------------------------------------
1333
1334 /**
1335 * Unwrap special elements
1336 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001337 * @return void
1338 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001339 protected function _unwrap_specials()
Derek Allard2067d1a2008-11-13 22:59:24 +00001340 {
1341 $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
1342 }
Barry Mienydd671972010-10-04 16:33:58 +02001343
Derek Allard2067d1a2008-11-13 22:59:24 +00001344 // --------------------------------------------------------------------
1345
1346 /**
1347 * Strip line-breaks via callback
1348 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001349 * @return string
1350 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001351 protected function _remove_nl_callback($matches)
Derek Allard2067d1a2008-11-13 22:59:24 +00001352 {
1353 if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
1354 {
1355 $matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]);
1356 }
1357
1358 return $matches[1];
1359 }
Barry Mienydd671972010-10-04 16:33:58 +02001360
Derek Allard2067d1a2008-11-13 22:59:24 +00001361 // --------------------------------------------------------------------
1362
1363 /**
1364 * Spool mail to the mail server
1365 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001366 * @return bool
1367 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001368 protected function _spool_email()
Derek Allard2067d1a2008-11-13 22:59:24 +00001369 {
1370 $this->_unwrap_specials();
1371
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001372 $method = '_send_with_' . $this->_get_protocol();
1373 if ( ! $this->$method())
Derek Allard2067d1a2008-11-13 22:59:24 +00001374 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001375 $this->_set_error_message('lang:email_send_failure_' . ($this->_get_protocol() === 'mail' ? 'phpmail' : $this->_get_protocol()));
Derek Allard2067d1a2008-11-13 22:59:24 +00001376 }
1377
patworkb0707982011-04-08 15:10:05 +02001378 $this->_set_error_message('lang:email_sent', $this->_get_protocol());
Derek Allard2067d1a2008-11-13 22:59:24 +00001379 return TRUE;
1380 }
Barry Mienydd671972010-10-04 16:33:58 +02001381
Derek Allard2067d1a2008-11-13 22:59:24 +00001382 // --------------------------------------------------------------------
1383
1384 /**
1385 * Send using mail()
1386 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001387 * @return bool
1388 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001389 protected function _send_with_mail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001390 {
1391 if ($this->_safe_mode == TRUE)
1392 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001393 return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001394 }
1395 else
1396 {
1397 // most documentation of sendmail using the "-f" flag lacks a space after it, however
1398 // we've encountered servers that seem to require it to be in place.
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001399 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 +00001400 }
1401 }
Barry Mienydd671972010-10-04 16:33:58 +02001402
Derek Allard2067d1a2008-11-13 22:59:24 +00001403 // --------------------------------------------------------------------
1404
1405 /**
1406 * Send using Sendmail
1407 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001408 * @return bool
1409 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001410 protected function _send_with_sendmail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001411 {
1412 $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
1413
Derek Jones4cefaa42009-04-29 19:13:56 +00001414 if ($fp === FALSE OR $fp === NULL)
1415 {
1416 // server probably has popen disabled, so nothing we can do to get a verbose error.
1417 return FALSE;
1418 }
Derek Jones71141ce2010-03-02 16:41:20 -06001419
Derek Jonesc630bcf2008-11-17 21:09:45 +00001420 fputs($fp, $this->_header_str);
1421 fputs($fp, $this->_finalbody);
1422
Barry Mienydd671972010-10-04 16:33:58 +02001423 $status = pclose($fp);
Eric Barnes6113f542010-12-29 13:36:12 -05001424
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001425 if ($status !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001426 {
patworkb0707982011-04-08 15:10:05 +02001427 $this->_set_error_message('lang:email_exit_status', $status);
1428 $this->_set_error_message('lang:email_no_socket');
Derek Allard2067d1a2008-11-13 22:59:24 +00001429 return FALSE;
1430 }
1431
Derek Allard2067d1a2008-11-13 22:59:24 +00001432 return TRUE;
1433 }
Barry Mienydd671972010-10-04 16:33:58 +02001434
Derek Allard2067d1a2008-11-13 22:59:24 +00001435 // --------------------------------------------------------------------
1436
1437 /**
1438 * Send using SMTP
1439 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001440 * @return bool
1441 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001442 protected function _send_with_smtp()
Derek Allard2067d1a2008-11-13 22:59:24 +00001443 {
1444 if ($this->smtp_host == '')
1445 {
patworkb0707982011-04-08 15:10:05 +02001446 $this->_set_error_message('lang:email_no_hostname');
Derek Allard2067d1a2008-11-13 22:59:24 +00001447 return FALSE;
1448 }
1449
1450 $this->_smtp_connect();
1451 $this->_smtp_authenticate();
1452
1453 $this->_send_command('from', $this->clean_email($this->_headers['From']));
1454
Pascal Kriete14287f32011-02-14 13:39:34 -05001455 foreach ($this->_recipients as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001456 {
1457 $this->_send_command('to', $val);
1458 }
1459
1460 if (count($this->_cc_array) > 0)
1461 {
Pascal Kriete14287f32011-02-14 13:39:34 -05001462 foreach ($this->_cc_array as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001463 {
1464 if ($val != "")
1465 {
1466 $this->_send_command('to', $val);
1467 }
1468 }
1469 }
1470
1471 if (count($this->_bcc_array) > 0)
1472 {
Pascal Kriete14287f32011-02-14 13:39:34 -05001473 foreach ($this->_bcc_array as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001474 {
1475 if ($val != "")
1476 {
1477 $this->_send_command('to', $val);
1478 }
1479 }
1480 }
1481
1482 $this->_send_command('data');
1483
1484 // perform dot transformation on any lines that begin with a dot
1485 $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody));
1486
1487 $this->_send_data('.');
1488
1489 $reply = $this->_get_smtp_data();
1490
1491 $this->_set_error_message($reply);
1492
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001493 if (strncmp($reply, '250', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001494 {
patworkb0707982011-04-08 15:10:05 +02001495 $this->_set_error_message('lang:email_smtp_error', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001496 return FALSE;
1497 }
1498
1499 $this->_send_command('quit');
1500 return TRUE;
1501 }
Barry Mienydd671972010-10-04 16:33:58 +02001502
Derek Allard2067d1a2008-11-13 22:59:24 +00001503 // --------------------------------------------------------------------
1504
1505 /**
1506 * SMTP Connect
1507 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001508 * @param string
1509 * @return string
1510 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001511 protected function _smtp_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +00001512 {
Phil Sturgeonc00a5a02011-11-22 15:25:32 +00001513 $ssl = ($this->smtp_crypto == 'ssl') ? 'ssl://' : NULL;
Radu Potop4c589ae2011-09-29 10:19:55 +03001514
Radu Potopbbf04b02011-09-28 13:57:51 +03001515 $this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
Derek Allard2067d1a2008-11-13 22:59:24 +00001516 $this->smtp_port,
1517 $errno,
1518 $errstr,
1519 $this->smtp_timeout);
1520
Pascal Kriete14287f32011-02-14 13:39:34 -05001521 if ( ! is_resource($this->_smtp_connect))
Derek Allard2067d1a2008-11-13 22:59:24 +00001522 {
patworkb0707982011-04-08 15:10:05 +02001523 $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr);
Derek Allard2067d1a2008-11-13 22:59:24 +00001524 return FALSE;
1525 }
1526
1527 $this->_set_error_message($this->_get_smtp_data());
Radu Potopbbf04b02011-09-28 13:57:51 +03001528
1529 if ($this->smtp_crypto == 'tls')
1530 {
1531 $this->_send_command('hello');
1532 $this->_send_command('starttls');
Phil Sturgeonc00a5a02011-11-22 15:25:32 +00001533
Radu Potop4c589ae2011-09-29 10:19:55 +03001534 $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
Radu Potop4c589ae2011-09-29 10:19:55 +03001535
Sean Fishere862ddd2011-10-26 22:45:00 -03001536 if ($crypto !== TRUE)
1537 {
1538 $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data());
1539 return FALSE;
1540 }
Radu Potopbbf04b02011-09-28 13:57:51 +03001541 }
1542
Derek Allard2067d1a2008-11-13 22:59:24 +00001543 return $this->_send_command('hello');
1544 }
Barry Mienydd671972010-10-04 16:33:58 +02001545
Derek Allard2067d1a2008-11-13 22:59:24 +00001546 // --------------------------------------------------------------------
1547
1548 /**
1549 * Send SMTP command
1550 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001551 * @param string
1552 * @param string
1553 * @return string
1554 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001555 protected function _send_command($cmd, $data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001556 {
1557 switch ($cmd)
1558 {
1559 case 'hello' :
1560
1561 if ($this->_smtp_auth OR $this->_get_encoding() == '8bit')
1562 $this->_send_data('EHLO '.$this->_get_hostname());
1563 else
1564 $this->_send_data('HELO '.$this->_get_hostname());
1565
1566 $resp = 250;
1567 break;
Radu Potopbbf04b02011-09-28 13:57:51 +03001568 case 'starttls' :
1569
1570 $this->_send_data('STARTTLS');
1571
1572 $resp = 220;
1573 break;
Derek Allard2067d1a2008-11-13 22:59:24 +00001574 case 'from' :
1575
1576 $this->_send_data('MAIL FROM:<'.$data.'>');
1577
1578 $resp = 250;
1579 break;
1580 case 'to' :
1581
1582 $this->_send_data('RCPT TO:<'.$data.'>');
1583
1584 $resp = 250;
1585 break;
1586 case 'data' :
1587
1588 $this->_send_data('DATA');
1589
1590 $resp = 354;
1591 break;
1592 case 'quit' :
1593
1594 $this->_send_data('QUIT');
1595
1596 $resp = 221;
1597 break;
1598 }
1599
1600 $reply = $this->_get_smtp_data();
1601
1602 $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>";
1603
1604 if (substr($reply, 0, 3) != $resp)
1605 {
patworkb0707982011-04-08 15:10:05 +02001606 $this->_set_error_message('lang:email_smtp_error', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001607 return FALSE;
1608 }
1609
1610 if ($cmd == 'quit')
1611 {
1612 fclose($this->_smtp_connect);
1613 }
1614
1615 return TRUE;
1616 }
Barry Mienydd671972010-10-04 16:33:58 +02001617
Derek Allard2067d1a2008-11-13 22:59:24 +00001618 // --------------------------------------------------------------------
1619
1620 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -05001621 * SMTP Authenticate
Derek Allard2067d1a2008-11-13 22:59:24 +00001622 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001623 * @return bool
1624 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001625 protected function _smtp_authenticate()
Derek Allard2067d1a2008-11-13 22:59:24 +00001626 {
1627 if ( ! $this->_smtp_auth)
1628 {
1629 return TRUE;
1630 }
1631
Andrey Andreev76f15c92012-03-01 13:05:07 +02001632 if ($this->smtp_user == '' && $this->smtp_pass == '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001633 {
patworkb0707982011-04-08 15:10:05 +02001634 $this->_set_error_message('lang:email_no_smtp_unpw');
Derek Allard2067d1a2008-11-13 22:59:24 +00001635 return FALSE;
1636 }
1637
1638 $this->_send_data('AUTH LOGIN');
1639
1640 $reply = $this->_get_smtp_data();
1641
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001642 if (strncmp($reply, '334', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001643 {
patworkb0707982011-04-08 15:10:05 +02001644 $this->_set_error_message('lang:email_failed_smtp_login', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001645 return FALSE;
1646 }
1647
1648 $this->_send_data(base64_encode($this->smtp_user));
1649
1650 $reply = $this->_get_smtp_data();
1651
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001652 if (strncmp($reply, '334', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001653 {
patworkb0707982011-04-08 15:10:05 +02001654 $this->_set_error_message('lang:email_smtp_auth_un', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001655 return FALSE;
1656 }
1657
1658 $this->_send_data(base64_encode($this->smtp_pass));
1659
1660 $reply = $this->_get_smtp_data();
1661
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001662 if (strncmp($reply, '235', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001663 {
patworkb0707982011-04-08 15:10:05 +02001664 $this->_set_error_message('lang:email_smtp_auth_pw', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001665 return FALSE;
1666 }
1667
1668 return TRUE;
1669 }
Barry Mienydd671972010-10-04 16:33:58 +02001670
Derek Allard2067d1a2008-11-13 22:59:24 +00001671 // --------------------------------------------------------------------
1672
1673 /**
1674 * Send SMTP data
1675 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001676 * @return bool
1677 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001678 protected function _send_data($data)
Derek Allard2067d1a2008-11-13 22:59:24 +00001679 {
1680 if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
1681 {
patworkb0707982011-04-08 15:10:05 +02001682 $this->_set_error_message('lang:email_smtp_data_failure', $data);
Derek Allard2067d1a2008-11-13 22:59:24 +00001683 return FALSE;
1684 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001685
1686 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001687 }
Barry Mienydd671972010-10-04 16:33:58 +02001688
Derek Allard2067d1a2008-11-13 22:59:24 +00001689 // --------------------------------------------------------------------
1690
1691 /**
1692 * Get SMTP data
1693 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001694 * @return string
1695 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001696 protected function _get_smtp_data()
Derek Allard2067d1a2008-11-13 22:59:24 +00001697 {
1698 $data = "";
1699
1700 while ($str = fgets($this->_smtp_connect, 512))
1701 {
1702 $data .= $str;
1703
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001704 if ($str[3] == " ")
Derek Allard2067d1a2008-11-13 22:59:24 +00001705 {
1706 break;
1707 }
1708 }
1709
1710 return $data;
1711 }
Barry Mienydd671972010-10-04 16:33:58 +02001712
Derek Allard2067d1a2008-11-13 22:59:24 +00001713 // --------------------------------------------------------------------
1714
1715 /**
1716 * Get Hostname
1717 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001718 * @return string
1719 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001720 protected function _get_hostname()
Derek Allard2067d1a2008-11-13 22:59:24 +00001721 {
1722 return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
1723 }
Barry Mienydd671972010-10-04 16:33:58 +02001724
Derek Allard2067d1a2008-11-13 22:59:24 +00001725 // --------------------------------------------------------------------
1726
1727 /**
1728 * Get IP
1729 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001730 * @return string
1731 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001732 protected function _get_ip()
Derek Allard2067d1a2008-11-13 22:59:24 +00001733 {
1734 if ($this->_IP !== FALSE)
1735 {
1736 return $this->_IP;
1737 }
1738
Andrey Andreev76f15c92012-03-01 13:05:07 +02001739 $cip = ( ! empty($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
1740 $rip = ( ! empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : FALSE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001741 if ($cip) $this->_IP = $cip;
1742 elseif ($rip) $this->_IP = $rip;
1743 else
1744 {
Andrey Andreev76f15c92012-03-01 13:05:07 +02001745 $fip = ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001746 if ($fip)
1747 {
1748 $this->_IP = $fip;
1749 }
1750 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001751
Robin Sowell76b369e2010-03-19 11:15:28 -04001752 if (strpos($this->_IP, ',') !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001753 {
1754 $x = explode(',', $this->_IP);
1755 $this->_IP = end($x);
1756 }
1757
1758 if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
1759 {
1760 $this->_IP = '0.0.0.0';
1761 }
1762
Derek Allard2067d1a2008-11-13 22:59:24 +00001763 return $this->_IP;
1764 }
Barry Mienydd671972010-10-04 16:33:58 +02001765
Derek Allard2067d1a2008-11-13 22:59:24 +00001766 // --------------------------------------------------------------------
1767
1768 /**
1769 * Get Debug Message
1770 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001771 * @return string
1772 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001773 public function print_debugger()
Derek Allard2067d1a2008-11-13 22:59:24 +00001774 {
1775 $msg = '';
1776
1777 if (count($this->_debug_msg) > 0)
1778 {
1779 foreach ($this->_debug_msg as $val)
1780 {
1781 $msg .= $val;
1782 }
1783 }
1784
1785 $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
1786 return $msg;
1787 }
Barry Mienydd671972010-10-04 16:33:58 +02001788
Derek Allard2067d1a2008-11-13 22:59:24 +00001789 // --------------------------------------------------------------------
1790
1791 /**
1792 * Set Message
1793 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001794 * @param string
Andrey Andreev081c9462012-03-01 12:58:11 +02001795 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00001796 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001797 protected function _set_error_message($msg, $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001798 {
1799 $CI =& get_instance();
1800 $CI->lang->load('email');
1801
Andrey Andreev76f15c92012-03-01 13:05:07 +02001802 if (substr($msg, 0, 5) !== 'lang:' OR FALSE === ($line = $CI->lang->line(substr($msg, 5))))
Derek Allard2067d1a2008-11-13 22:59:24 +00001803 {
1804 $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
1805 }
1806 else
1807 {
1808 $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />";
1809 }
1810 }
Barry Mienydd671972010-10-04 16:33:58 +02001811
Derek Allard2067d1a2008-11-13 22:59:24 +00001812 // --------------------------------------------------------------------
1813
1814 /**
1815 * Mime Types
1816 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001817 * @param string
1818 * @return string
1819 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001820 protected function _mime_types($ext = "")
Derek Allard2067d1a2008-11-13 22:59:24 +00001821 {
1822 $mimes = array( 'hqx' => 'application/mac-binhex40',
1823 'cpt' => 'application/mac-compactpro',
1824 'doc' => 'application/msword',
1825 'bin' => 'application/macbinary',
1826 'dms' => 'application/octet-stream',
1827 'lha' => 'application/octet-stream',
1828 'lzh' => 'application/octet-stream',
1829 'exe' => 'application/octet-stream',
1830 'class' => 'application/octet-stream',
1831 'psd' => 'application/octet-stream',
1832 'so' => 'application/octet-stream',
1833 'sea' => 'application/octet-stream',
1834 'dll' => 'application/octet-stream',
1835 'oda' => 'application/oda',
1836 'pdf' => 'application/pdf',
1837 'ai' => 'application/postscript',
1838 'eps' => 'application/postscript',
1839 'ps' => 'application/postscript',
1840 'smi' => 'application/smil',
1841 'smil' => 'application/smil',
1842 'mif' => 'application/vnd.mif',
1843 'xls' => 'application/vnd.ms-excel',
1844 'ppt' => 'application/vnd.ms-powerpoint',
1845 'wbxml' => 'application/vnd.wap.wbxml',
1846 'wmlc' => 'application/vnd.wap.wmlc',
1847 'dcr' => 'application/x-director',
1848 'dir' => 'application/x-director',
1849 'dxr' => 'application/x-director',
1850 'dvi' => 'application/x-dvi',
1851 'gtar' => 'application/x-gtar',
1852 'php' => 'application/x-httpd-php',
1853 'php4' => 'application/x-httpd-php',
1854 'php3' => 'application/x-httpd-php',
1855 'phtml' => 'application/x-httpd-php',
1856 'phps' => 'application/x-httpd-php-source',
1857 'js' => 'application/x-javascript',
1858 'swf' => 'application/x-shockwave-flash',
1859 'sit' => 'application/x-stuffit',
1860 'tar' => 'application/x-tar',
1861 'tgz' => 'application/x-tar',
1862 'xhtml' => 'application/xhtml+xml',
1863 'xht' => 'application/xhtml+xml',
1864 'zip' => 'application/zip',
1865 'mid' => 'audio/midi',
1866 'midi' => 'audio/midi',
1867 'mpga' => 'audio/mpeg',
1868 'mp2' => 'audio/mpeg',
1869 'mp3' => 'audio/mpeg',
1870 'aif' => 'audio/x-aiff',
1871 'aiff' => 'audio/x-aiff',
1872 'aifc' => 'audio/x-aiff',
1873 'ram' => 'audio/x-pn-realaudio',
1874 'rm' => 'audio/x-pn-realaudio',
1875 'rpm' => 'audio/x-pn-realaudio-plugin',
1876 'ra' => 'audio/x-realaudio',
1877 'rv' => 'video/vnd.rn-realvideo',
1878 'wav' => 'audio/x-wav',
1879 'bmp' => 'image/bmp',
1880 'gif' => 'image/gif',
1881 'jpeg' => 'image/jpeg',
1882 'jpg' => 'image/jpeg',
1883 'jpe' => 'image/jpeg',
1884 'png' => 'image/png',
1885 'tiff' => 'image/tiff',
1886 'tif' => 'image/tiff',
1887 'css' => 'text/css',
1888 'html' => 'text/html',
1889 'htm' => 'text/html',
1890 'shtml' => 'text/html',
1891 'txt' => 'text/plain',
1892 'text' => 'text/plain',
1893 'log' => 'text/plain',
1894 'rtx' => 'text/richtext',
1895 'rtf' => 'text/rtf',
1896 'xml' => 'text/xml',
1897 'xsl' => 'text/xml',
1898 'mpeg' => 'video/mpeg',
1899 'mpg' => 'video/mpeg',
1900 'mpe' => 'video/mpeg',
1901 'qt' => 'video/quicktime',
1902 'mov' => 'video/quicktime',
1903 'avi' => 'video/x-msvideo',
1904 'movie' => 'video/x-sgi-movie',
1905 'doc' => 'application/msword',
1906 'word' => 'application/msword',
1907 'xl' => 'application/excel',
1908 'eml' => 'message/rfc822'
1909 );
1910
1911 return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
1912 }
1913
1914}
Derek Allard2067d1a2008-11-13 22:59:24 +00001915
1916/* End of file Email.php */
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001917/* Location: ./system/libraries/Email.php */