blob: 027ec0adb87ec778714ffad9cb68a2cc397d6f82 [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
28// ------------------------------------------------------------------------
29
30/**
31 * CodeIgniter Email Class
32 *
33 * Permits email to be sent using Mail, Sendmail, or SMTP.
34 *
35 * @package CodeIgniter
36 * @subpackage Libraries
37 * @category Libraries
Derek Jonesf4a4bd82011-10-20 12:18:42 -050038 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000039 * @link http://codeigniter.com/user_guide/libraries/email.html
40 */
trita15dd4f2011-11-23 07:40:05 -050041class CI_Email {
Derek Allard2067d1a2008-11-13 22:59:24 +000042
Andrey Andreev1bd3d882011-12-22 15:38:20 +020043 public $useragent = "CodeIgniter";
44 public $mailpath = "/usr/sbin/sendmail"; // Sendmail path
45 public $protocol = "mail"; // mail/sendmail/smtp
46 public $smtp_host = ""; // SMTP Server. Example: mail.earthlink.net
47 public $smtp_user = ""; // SMTP Username
48 public $smtp_pass = ""; // SMTP Password
49 public $smtp_port = "25"; // SMTP Port
50 public $smtp_timeout = 5; // SMTP Timeout in seconds
51 public $smtp_crypto = ""; // SMTP Encryption. Can be null, tls or ssl.
52 public $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off
53 public $wrapchars = "76"; // Number of characters to wrap at.
54 public $mailtype = "text"; // text/html Defines email formatting
55 public $charset = "utf-8"; // Default char set: iso-8859-1 or us-ascii
56 public $multipart = "mixed"; // "mixed" (in the body) or "related" (separate)
57 public $alt_message = ''; // Alternative message for HTML emails
58 public $validate = FALSE; // TRUE/FALSE. Enables email validation
59 public $priority = "3"; // Default priority (1 - 5)
60 public $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
61 public $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers,
Derek Allard2067d1a2008-11-13 22:59:24 +000062 // even on the receiving end think they need to muck with CRLFs, so using "\n", while
63 // distasteful, is the only thing that seems to work for all environments.
Andrey Andreev1bd3d882011-12-22 15:38:20 +020064 public $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo.
65 public $bcc_batch_mode = FALSE; // TRUE/FALSE Turns on/off Bcc batch feature
66 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 +020067
68 protected $_safe_mode = FALSE;
69 protected $_subject = '';
70 protected $_body = '';
71 protected $_finalbody = '';
72 protected $_alt_boundary = '';
73 protected $_atc_boundary = '';
74 protected $_header_str = '';
75 protected $_smtp_connect = '';
76 protected $_encoding = '8bit';
77 protected $_IP = FALSE;
78 protected $_smtp_auth = FALSE;
79 protected $_replyto_flag = FALSE;
80 protected $_debug_msg = array();
81 protected $_recipients = array();
82 protected $_cc_array = array();
83 protected $_bcc_array = array();
84 protected $_headers = array();
85 protected $_attach_name = array();
86 protected $_attach_type = array();
87 protected $_attach_disp = array();
88 protected $_protocols = array('mail', 'sendmail', 'smtp');
89 protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
90 protected $_bit_depths = array('7bit', '8bit');
91 protected $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
Derek Allard2067d1a2008-11-13 22:59:24 +000092
93
94 /**
95 * Constructor - Sets Email Preferences
96 *
97 * The constructor can be passed an array of config values
98 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +000099 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 {
101 if (count($config) > 0)
102 {
103 $this->initialize($config);
104 }
105 else
106 {
107 $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200108 $this->_safe_mode = (bool) @ini_get("safe_mode");
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 }
110
111 log_message('debug', "Email Class Initialized");
112 }
113
114 // --------------------------------------------------------------------
115
116 /**
117 * Initialize preferences
118 *
119 * @access public
120 * @param array
121 * @return void
122 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000123 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000125 foreach ($config as $key => $val)
126 {
127 if (isset($this->$key))
128 {
129 $method = 'set_'.$key;
130
131 if (method_exists($this, $method))
132 {
133 $this->$method($val);
134 }
135 else
136 {
137 $this->$key = $val;
138 }
139 }
140 }
Eric Barnes6113f542010-12-29 13:36:12 -0500141 $this->clear();
Derek Allard2067d1a2008-11-13 22:59:24 +0000142
143 $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200144 $this->_safe_mode = (bool) @ini_get("safe_mode");
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000145
146 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 }
Barry Mienydd671972010-10-04 16:33:58 +0200148
Derek Allard2067d1a2008-11-13 22:59:24 +0000149 // --------------------------------------------------------------------
150
151 /**
152 * Initialize the Email Data
153 *
154 * @access public
Bo-Yi Wu83320eb2011-09-15 13:28:02 +0800155 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 * @return void
157 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000158 public function clear($clear_attachments = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 {
160 $this->_subject = "";
161 $this->_body = "";
162 $this->_finalbody = "";
163 $this->_header_str = "";
164 $this->_replyto_flag = FALSE;
165 $this->_recipients = array();
Derek Jonesd1606352010-09-01 11:16:07 -0500166 $this->_cc_array = array();
167 $this->_bcc_array = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 $this->_headers = array();
169 $this->_debug_msg = array();
170
171 $this->_set_header('User-Agent', $this->useragent);
172 $this->_set_header('Date', $this->_set_date());
173
174 if ($clear_attachments !== FALSE)
175 {
176 $this->_attach_name = array();
177 $this->_attach_type = array();
178 $this->_attach_disp = array();
179 }
Eric Barnes6113f542010-12-29 13:36:12 -0500180
Greg Akera769deb2010-11-10 15:47:29 -0600181 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 }
Barry Mienydd671972010-10-04 16:33:58 +0200183
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 // --------------------------------------------------------------------
185
186 /**
187 * Set FROM
188 *
189 * @access public
190 * @param string
191 * @param string
192 * @return void
193 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000194 public function from($from, $name = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 {
196 if (preg_match( '/\<(.*)\>/', $from, $match))
197 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200198 $from = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 }
200
201 if ($this->validate)
202 {
203 $this->validate_email($this->_str_to_array($from));
204 }
205
206 // prepare the display name
207 if ($name != '')
208 {
209 // only use Q encoding if there are characters that would require it
210 if ( ! preg_match('/[\200-\377]/', $name))
211 {
212 // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
Derek Jonesc630bcf2008-11-17 21:09:45 +0000213 $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"';
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 }
215 else
216 {
217 $name = $this->_prep_q_encoding($name, TRUE);
218 }
219 }
220
221 $this->_set_header('From', $name.' <'.$from.'>');
222 $this->_set_header('Return-Path', '<'.$from.'>');
Eric Barnes6113f542010-12-29 13:36:12 -0500223
Greg Akera769deb2010-11-10 15:47:29 -0600224 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 }
Barry Mienydd671972010-10-04 16:33:58 +0200226
Derek Allard2067d1a2008-11-13 22:59:24 +0000227 // --------------------------------------------------------------------
228
229 /**
230 * Set Reply-to
231 *
232 * @access public
233 * @param string
234 * @param string
235 * @return void
236 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000237 public function reply_to($replyto, $name = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 {
239 if (preg_match( '/\<(.*)\>/', $replyto, $match))
240 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200241 $replyto = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 }
243
244 if ($this->validate)
245 {
246 $this->validate_email($this->_str_to_array($replyto));
247 }
248
249 if ($name == '')
250 {
251 $name = $replyto;
252 }
253
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200254 if (strncmp($name, '"', 1) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000255 {
256 $name = '"'.$name.'"';
257 }
258
259 $this->_set_header('Reply-To', $name.' <'.$replyto.'>');
260 $this->_replyto_flag = TRUE;
Greg Akera769deb2010-11-10 15:47:29 -0600261
262 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 }
Barry Mienydd671972010-10-04 16:33:58 +0200264
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 // --------------------------------------------------------------------
266
267 /**
268 * Set Recipients
269 *
270 * @access public
271 * @param string
272 * @return void
273 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000274 public function to($to)
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 {
276 $to = $this->_str_to_array($to);
277 $to = $this->clean_email($to);
278
279 if ($this->validate)
280 {
281 $this->validate_email($to);
282 }
283
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200284 if ($this->_get_protocol() !== 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 {
286 $this->_set_header('To', implode(", ", $to));
287 }
288
289 switch ($this->_get_protocol())
290 {
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000291 case 'smtp' :
292 $this->_recipients = $to;
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 break;
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000294 case 'sendmail' :
295 case 'mail' :
296 $this->_recipients = implode(", ", $to);
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 break;
298 }
Eric Barnes6113f542010-12-29 13:36:12 -0500299
Greg Akera769deb2010-11-10 15:47:29 -0600300 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 }
Barry Mienydd671972010-10-04 16:33:58 +0200302
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 // --------------------------------------------------------------------
304
305 /**
306 * Set CC
307 *
308 * @access public
309 * @param string
310 * @return void
311 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000312 public function cc($cc)
Derek Allard2067d1a2008-11-13 22:59:24 +0000313 {
314 $cc = $this->_str_to_array($cc);
315 $cc = $this->clean_email($cc);
316
317 if ($this->validate)
318 {
319 $this->validate_email($cc);
320 }
321
322 $this->_set_header('Cc', implode(", ", $cc));
323
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200324 if ($this->_get_protocol() === 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 {
326 $this->_cc_array = $cc;
327 }
Eric Barnes6113f542010-12-29 13:36:12 -0500328
Greg Akera769deb2010-11-10 15:47:29 -0600329 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 }
Barry Mienydd671972010-10-04 16:33:58 +0200331
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 // --------------------------------------------------------------------
333
334 /**
335 * Set BCC
336 *
337 * @access public
338 * @param string
339 * @param string
340 * @return void
341 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000342 public function bcc($bcc, $limit = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 {
344 if ($limit != '' && is_numeric($limit))
345 {
346 $this->bcc_batch_mode = TRUE;
347 $this->bcc_batch_size = $limit;
348 }
349
350 $bcc = $this->_str_to_array($bcc);
351 $bcc = $this->clean_email($bcc);
352
353 if ($this->validate)
354 {
355 $this->validate_email($bcc);
356 }
357
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200358 if ($this->_get_protocol() === 'smtp' OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size))
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 {
360 $this->_bcc_array = $bcc;
361 }
362 else
363 {
364 $this->_set_header('Bcc', implode(", ", $bcc));
365 }
Eric Barnes6113f542010-12-29 13:36:12 -0500366
Greg Akera769deb2010-11-10 15:47:29 -0600367 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 }
Barry Mienydd671972010-10-04 16:33:58 +0200369
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 // --------------------------------------------------------------------
371
372 /**
373 * Set Email Subject
374 *
375 * @access public
376 * @param string
377 * @return void
378 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000379 public function subject($subject)
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 {
381 $subject = $this->_prep_q_encoding($subject);
382 $this->_set_header('Subject', $subject);
Greg Akera769deb2010-11-10 15:47:29 -0600383 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 }
Barry Mienydd671972010-10-04 16:33:58 +0200385
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 // --------------------------------------------------------------------
387
388 /**
389 * Set Body
390 *
391 * @access public
392 * @param string
393 * @return void
394 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000395 public function message($body)
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 {
diegorivera33c32802011-10-19 02:56:15 -0200397 $this->_body = rtrim(str_replace("\r", "", $body));
398
Andrey Andreevaf728622011-10-20 10:11:59 +0300399 /* strip slashes only if magic quotes is ON
400 if we do it with magic quotes OFF, it strips real, user-inputted chars.
401
402 NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
403 it will probably not exist in future versions at all.
404 */
405 if ( ! is_php('5.4') && get_magic_quotes_gpc())
diegorivera9fca6152011-10-19 11:18:45 -0200406 {
diegorivera33c32802011-10-19 02:56:15 -0200407 $this->_body = stripslashes($this->_body);
diegorivera9fca6152011-10-19 11:18:45 -0200408 }
diegorivera33c32802011-10-19 02:56:15 -0200409
Greg Akera769deb2010-11-10 15:47:29 -0600410 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 }
Barry Mienydd671972010-10-04 16:33:58 +0200412
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 // --------------------------------------------------------------------
414
415 /**
416 * Assign file attachments
417 *
418 * @access public
419 * @param string
420 * @return void
421 */
trit10eb14d2011-11-23 15:48:21 -0500422 public function attach($filename, $disposition = '', $newname = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 {
trit151fc682011-11-23 07:30:06 -0500424 $this->_attach_name[] = array($filename, $newname);
Phil Sturgeon0aaf42b2011-08-10 08:06:37 -0600425 $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
tritd5269982011-11-23 17:22:44 -0500426 $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters
Greg Akera769deb2010-11-10 15:47:29 -0600427 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000428 }
429
430 // --------------------------------------------------------------------
431
432 /**
433 * Add a Header Item
434 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600435 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 * @param string
437 * @param string
438 * @return void
439 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600440 protected function _set_header($header, $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 {
442 $this->_headers[$header] = $value;
443 }
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 // --------------------------------------------------------------------
446
447 /**
448 * Convert a String to an Array
449 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600450 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * @param string
452 * @return array
453 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600454 protected function _str_to_array($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 {
456 if ( ! is_array($email))
457 {
458 if (strpos($email, ',') !== FALSE)
459 {
460 $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY);
461 }
462 else
463 {
464 $email = trim($email);
465 settype($email, "array");
466 }
467 }
468 return $email;
469 }
Barry Mienydd671972010-10-04 16:33:58 +0200470
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 // --------------------------------------------------------------------
472
473 /**
474 * Set Multipart Value
475 *
476 * @access public
477 * @param string
478 * @return void
479 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000480 public function set_alt_message($str = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 {
Dan Horrigand0ddeaf2011-08-21 09:07:27 -0400482 $this->alt_message = (string) $str;
Greg Akera769deb2010-11-10 15:47:29 -0600483 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 }
Barry Mienydd671972010-10-04 16:33:58 +0200485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 // --------------------------------------------------------------------
487
488 /**
489 * Set Mailtype
490 *
491 * @access public
492 * @param string
493 * @return void
494 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000495 public function set_mailtype($type = 'text')
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 {
497 $this->mailtype = ($type == 'html') ? 'html' : 'text';
Greg Akera769deb2010-11-10 15:47:29 -0600498 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 }
Barry Mienydd671972010-10-04 16:33:58 +0200500
Derek Allard2067d1a2008-11-13 22:59:24 +0000501 // --------------------------------------------------------------------
502
503 /**
504 * Set Wordwrap
505 *
506 * @access public
Dan Horrigan628e6602011-08-21 09:08:31 -0400507 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000508 * @return void
509 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000510 public function set_wordwrap($wordwrap = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 {
Dan Horrigan628e6602011-08-21 09:08:31 -0400512 $this->wordwrap = (bool) $wordwrap;
Greg Akera769deb2010-11-10 15:47:29 -0600513 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 }
Barry Mienydd671972010-10-04 16:33:58 +0200515
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 // --------------------------------------------------------------------
517
518 /**
519 * Set Protocol
520 *
521 * @access public
522 * @param string
523 * @return void
524 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000525 public function set_protocol($protocol = 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000526 {
527 $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol);
Greg Akera769deb2010-11-10 15:47:29 -0600528 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000529 }
Barry Mienydd671972010-10-04 16:33:58 +0200530
Derek Allard2067d1a2008-11-13 22:59:24 +0000531 // --------------------------------------------------------------------
532
533 /**
534 * Set Priority
535 *
536 * @access public
537 * @param integer
538 * @return void
539 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000540 public function set_priority($n = 3)
Derek Allard2067d1a2008-11-13 22:59:24 +0000541 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200542 if ( ! is_numeric($n) OR $n < 1 OR $n > 5)
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 {
544 $this->priority = 3;
545 return;
546 }
547
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200548 $this->priority = (int) $n;
Greg Akera769deb2010-11-10 15:47:29 -0600549 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000550 }
Barry Mienydd671972010-10-04 16:33:58 +0200551
Derek Allard2067d1a2008-11-13 22:59:24 +0000552 // --------------------------------------------------------------------
553
554 /**
555 * Set Newline Character
556 *
557 * @access public
558 * @param string
559 * @return void
560 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000561 public function set_newline($newline = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000562 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200563 $this->newline = in_array($newline, array("\n", "\r\n", "\r")) ? $newline : "\n";
Greg Akera769deb2010-11-10 15:47:29 -0600564 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000565 }
Barry Mienydd671972010-10-04 16:33:58 +0200566
Derek Allard2067d1a2008-11-13 22:59:24 +0000567 // --------------------------------------------------------------------
568
569 /**
570 * Set CRLF
571 *
572 * @access public
573 * @param string
574 * @return void
575 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000576 public function set_crlf($crlf = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200578 $this->crlf = ($crlf !== "\n" AND $crlf !== "\r\n" AND $crlf !== "\r") ? "\n" : $crlf;
Greg Akera769deb2010-11-10 15:47:29 -0600579 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 }
Barry Mienydd671972010-10-04 16:33:58 +0200581
Derek Allard2067d1a2008-11-13 22:59:24 +0000582 // --------------------------------------------------------------------
583
584 /**
585 * Set Message Boundary
586 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600587 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 * @return void
589 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600590 protected function _set_boundaries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000591 {
592 $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative
593 $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary
594 }
Barry Mienydd671972010-10-04 16:33:58 +0200595
Derek Allard2067d1a2008-11-13 22:59:24 +0000596 // --------------------------------------------------------------------
597
598 /**
599 * Get the Message ID
600 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600601 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 * @return string
603 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600604 protected function _get_message_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000605 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200606 $from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000607
Derek Jones37f4b9c2011-07-01 17:56:50 -0500608 return "<".uniqid('').strstr($from, '@').">";
Derek Allard2067d1a2008-11-13 22:59:24 +0000609 }
Barry Mienydd671972010-10-04 16:33:58 +0200610
Derek Allard2067d1a2008-11-13 22:59:24 +0000611 // --------------------------------------------------------------------
612
613 /**
614 * Get Mail Protocol
615 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600616 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000617 * @param bool
618 * @return string
619 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600620 protected function _get_protocol($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 {
622 $this->protocol = strtolower($this->protocol);
623 $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
624
625 if ($return == TRUE)
626 {
627 return $this->protocol;
628 }
629 }
Barry Mienydd671972010-10-04 16:33:58 +0200630
Derek Allard2067d1a2008-11-13 22:59:24 +0000631 // --------------------------------------------------------------------
632
633 /**
634 * Get Mail Encoding
635 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600636 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000637 * @param bool
638 * @return string
639 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600640 protected function _get_encoding($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000641 {
642 $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
643
644 foreach ($this->_base_charsets as $charset)
645 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200646 if (strncmp($charset, $this->charset, strlen($charset)) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000647 {
648 $this->_encoding = '7bit';
649 }
650 }
651
652 if ($return == TRUE)
653 {
654 return $this->_encoding;
655 }
656 }
657
658 // --------------------------------------------------------------------
659
660 /**
661 * Get content type (text/html/attachment)
662 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600663 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000664 * @return string
665 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600666 protected function _get_content_type()
Derek Allard2067d1a2008-11-13 22:59:24 +0000667 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200668 if ($this->mailtype === 'html' && count($this->_attach_name) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000669 {
670 return 'html';
671 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200672 elseif ($this->mailtype === 'html' && count($this->_attach_name) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000673 {
674 return 'html-attach';
675 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200676 elseif ($this->mailtype === 'text' && count($this->_attach_name) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000677 {
678 return 'plain-attach';
679 }
680 else
681 {
682 return 'plain';
683 }
684 }
Barry Mienydd671972010-10-04 16:33:58 +0200685
Derek Allard2067d1a2008-11-13 22:59:24 +0000686 // --------------------------------------------------------------------
687
688 /**
689 * Set RFC 822 Date
690 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600691 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000692 * @return string
693 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600694 protected function _set_date()
Derek Allard2067d1a2008-11-13 22:59:24 +0000695 {
696 $timezone = date("Z");
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200697 $operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+';
Derek Allard2067d1a2008-11-13 22:59:24 +0000698 $timezone = abs($timezone);
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200699 $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
Derek Allard2067d1a2008-11-13 22:59:24 +0000700
701 return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone);
702 }
Barry Mienydd671972010-10-04 16:33:58 +0200703
Derek Allard2067d1a2008-11-13 22:59:24 +0000704 // --------------------------------------------------------------------
705
706 /**
707 * Mime message
708 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600709 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000710 * @return string
711 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600712 protected function _get_mime_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000713 {
714 return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format.";
715 }
Barry Mienydd671972010-10-04 16:33:58 +0200716
Derek Allard2067d1a2008-11-13 22:59:24 +0000717 // --------------------------------------------------------------------
718
719 /**
720 * Validate Email Address
721 *
722 * @access public
723 * @param string
724 * @return bool
725 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000726 public function validate_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000727 {
728 if ( ! is_array($email))
729 {
patworkb0707982011-04-08 15:10:05 +0200730 $this->_set_error_message('lang:email_must_be_array');
Derek Allard2067d1a2008-11-13 22:59:24 +0000731 return FALSE;
732 }
733
734 foreach ($email as $val)
735 {
736 if ( ! $this->valid_email($val))
737 {
patworkb0707982011-04-08 15:10:05 +0200738 $this->_set_error_message('lang:email_invalid_address', $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000739 return FALSE;
740 }
741 }
742
743 return TRUE;
744 }
Barry Mienydd671972010-10-04 16:33:58 +0200745
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 // --------------------------------------------------------------------
747
748 /**
749 * Email Validation
750 *
751 * @access public
752 * @param string
753 * @return bool
754 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000755 public function valid_email($address)
Derek Allard2067d1a2008-11-13 22:59:24 +0000756 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200757 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 +0000758 }
Barry Mienydd671972010-10-04 16:33:58 +0200759
Derek Allard2067d1a2008-11-13 22:59:24 +0000760 // --------------------------------------------------------------------
761
762 /**
763 * Clean Extended Email Address: Joe Smith <joe@smith.com>
764 *
765 * @access public
766 * @param string
767 * @return string
768 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000769 public function clean_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000770 {
771 if ( ! is_array($email))
772 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200773 return (preg_match('/\<(.*)\>/', $email, $match)) ? $match[1] : $email;
Derek Allard2067d1a2008-11-13 22:59:24 +0000774 }
775
776 $clean_email = array();
777
778 foreach ($email as $addy)
779 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200780 $clean_email[] = (preg_match( '/\<(.*)\>/', $addy, $match)) ? $match[1] : $addy;
Derek Allard2067d1a2008-11-13 22:59:24 +0000781 }
782
783 return $clean_email;
784 }
Barry Mienydd671972010-10-04 16:33:58 +0200785
Derek Allard2067d1a2008-11-13 22:59:24 +0000786 // --------------------------------------------------------------------
787
788 /**
789 * Build alternative plain text message
790 *
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000791 * This public function provides the raw message for use
Derek Allard2067d1a2008-11-13 22:59:24 +0000792 * in plain-text headers of HTML-formatted emails.
793 * If the user hasn't specified his own alternative message
794 * it creates one by stripping the HTML
795 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600796 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000797 * @return string
798 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600799 protected function _get_alt_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000800 {
801 if ($this->alt_message != "")
802 {
803 return $this->word_wrap($this->alt_message, '76');
804 }
805
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200806 $body = (preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match)) ? $match[1] : $this->_body;
807 $body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000808
809 for ($i = 20; $i >= 3; $i--)
810 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200811 $body = str_replace(str_repeat("\n", $i), "\n\n", $body);
Derek Allard2067d1a2008-11-13 22:59:24 +0000812 }
813
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200814 return $this->word_wrap($body, 76);
Derek Allard2067d1a2008-11-13 22:59:24 +0000815 }
Barry Mienydd671972010-10-04 16:33:58 +0200816
Derek Allard2067d1a2008-11-13 22:59:24 +0000817 // --------------------------------------------------------------------
818
819 /**
820 * Word Wrap
821 *
822 * @access public
823 * @param string
824 * @param integer
825 * @return string
826 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000827 public function word_wrap($str, $charlim = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000828 {
829 // Se the character limit
830 if ($charlim == '')
831 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200832 $charlim = ($this->wrapchars == "") ? 76 : $this->wrapchars;
Derek Allard2067d1a2008-11-13 22:59:24 +0000833 }
834
835 // Reduce multiple spaces
836 $str = preg_replace("| +|", " ", $str);
837
838 // Standardize newlines
839 if (strpos($str, "\r") !== FALSE)
840 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200841 $str = str_replace(array("\r\n", "\r"), "\n", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000842 }
843
844 // If the current word is surrounded by {unwrap} tags we'll
845 // strip the entire chunk and replace it with a marker.
846 $unwrap = array();
847 if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
848 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200849 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000850 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200851 $unwrap[] = $matches[1][$i];
852 $str = str_replace($matches[1][$i], "{{unwrapped".$i."}}", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000853 }
854 }
855
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000856 // Use PHP's native public function to do the initial wordwrap.
Derek Allard2067d1a2008-11-13 22:59:24 +0000857 // We set the cut flag to FALSE so that any individual words that are
Derek Jones37f4b9c2011-07-01 17:56:50 -0500858 // too long get left alone. In the next step we'll deal with them.
Derek Allard2067d1a2008-11-13 22:59:24 +0000859 $str = wordwrap($str, $charlim, "\n", FALSE);
860
861 // Split the string into individual lines of text and cycle through them
862 $output = "";
863 foreach (explode("\n", $str) as $line)
864 {
865 // Is the line within the allowed character count?
866 // If so we'll join it to the output and continue
867 if (strlen($line) <= $charlim)
868 {
869 $output .= $line.$this->newline;
870 continue;
871 }
872
873 $temp = '';
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200874 do
Derek Allard2067d1a2008-11-13 22:59:24 +0000875 {
876 // If the over-length word is a URL we won't wrap it
877 if (preg_match("!\[url.+\]|://|wwww.!", $line))
878 {
879 break;
880 }
881
882 // Trim the word down
883 $temp .= substr($line, 0, $charlim-1);
884 $line = substr($line, $charlim-1);
885 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200886 while (strlen($line) > $charlim);
Derek Allard2067d1a2008-11-13 22:59:24 +0000887
888 // If $temp contains data it means we had to split up an over-length
889 // word into smaller chunks so we'll add it back to our current line
890 if ($temp != '')
891 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200892 $output .= $temp.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000893 }
894
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200895 $output .= $line.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000896 }
897
898 // Put our markers back
899 if (count($unwrap) > 0)
900 {
901 foreach ($unwrap as $key => $val)
902 {
903 $output = str_replace("{{unwrapped".$key."}}", $val, $output);
904 }
905 }
906
907 return $output;
908 }
Barry Mienydd671972010-10-04 16:33:58 +0200909
Derek Allard2067d1a2008-11-13 22:59:24 +0000910 // --------------------------------------------------------------------
911
912 /**
913 * Build final headers
914 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600915 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000916 * @param string
917 * @return string
918 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600919 protected function _build_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +0000920 {
921 $this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
922 $this->_set_header('X-Mailer', $this->useragent);
923 $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]);
924 $this->_set_header('Message-ID', $this->_get_message_id());
925 $this->_set_header('Mime-Version', '1.0');
926 }
Barry Mienydd671972010-10-04 16:33:58 +0200927
Derek Allard2067d1a2008-11-13 22:59:24 +0000928 // --------------------------------------------------------------------
929
930 /**
931 * Write Headers as a string
932 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600933 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000934 * @return void
935 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600936 protected function _write_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200938 if ($this->protocol === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000939 {
940 $this->_subject = $this->_headers['Subject'];
941 unset($this->_headers['Subject']);
942 }
943
944 reset($this->_headers);
945 $this->_header_str = "";
946
Pascal Kriete14287f32011-02-14 13:39:34 -0500947 foreach ($this->_headers as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000948 {
949 $val = trim($val);
950
951 if ($val != "")
952 {
953 $this->_header_str .= $key.": ".$val.$this->newline;
954 }
955 }
956
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200957 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000958 {
Derek Jones1d890882009-02-10 20:32:14 +0000959 $this->_header_str = rtrim($this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000960 }
961 }
Barry Mienydd671972010-10-04 16:33:58 +0200962
Derek Allard2067d1a2008-11-13 22:59:24 +0000963 // --------------------------------------------------------------------
964
965 /**
966 * Build Final Body and attachments
967 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600968 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000969 * @return void
970 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600971 protected function _build_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000972 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200973 if ($this->wordwrap === TRUE AND $this->mailtype !== 'html')
Derek Allard2067d1a2008-11-13 22:59:24 +0000974 {
975 $this->_body = $this->word_wrap($this->_body);
976 }
977
978 $this->_set_boundaries();
979 $this->_write_headers();
980
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200981 $hdr = ($this->_get_protocol() === 'mail') ? $this->newline : '';
Brandon Jones485d7412010-11-09 16:38:17 -0500982 $body = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000983
984 switch ($this->_get_content_type())
985 {
986 case 'plain' :
987
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200988 $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline
989 . "Content-Transfer-Encoding: " . $this->_get_encoding();
Derek Allard2067d1a2008-11-13 22:59:24 +0000990
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200991 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000992 {
993 $this->_header_str .= $hdr;
994 $this->_finalbody = $this->_body;
Derek Allard2067d1a2008-11-13 22:59:24 +0000995 }
Brandon Jones485d7412010-11-09 16:38:17 -0500996 else
997 {
998 $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body;
999 }
Eric Barnes6113f542010-12-29 13:36:12 -05001000
Derek Allard2067d1a2008-11-13 22:59:24 +00001001 return;
1002
Derek Allard2067d1a2008-11-13 22:59:24 +00001003 case 'html' :
1004
1005 if ($this->send_multipart === FALSE)
1006 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001007 $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline
1008 . "Content-Transfer-Encoding: quoted-printable";
Derek Allard2067d1a2008-11-13 22:59:24 +00001009 }
1010 else
1011 {
Derek Jonesa45e7612009-02-10 18:33:01 +00001012 $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001013
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001014 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1015 . "--" . $this->_alt_boundary . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001016
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001017 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1018 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
1019 . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001020
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001021 . "Content-Type: text/html; charset=" . $this->charset . $this->newline
1022 . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001023 }
Eric Barnes6113f542010-12-29 13:36:12 -05001024
Brandon Jones485d7412010-11-09 16:38:17 -05001025 $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -05001026
1027
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001028 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001029 {
1030 $this->_header_str .= $hdr;
Brandon Jones485d7412010-11-09 16:38:17 -05001031 }
1032 else
1033 {
1034 $this->_finalbody = $hdr . $this->_finalbody;
Derek Allard2067d1a2008-11-13 22:59:24 +00001035 }
1036
Derek Allard2067d1a2008-11-13 22:59:24 +00001037
1038 if ($this->send_multipart !== FALSE)
1039 {
Brandon Jones485d7412010-11-09 16:38:17 -05001040 $this->_finalbody .= "--" . $this->_alt_boundary . "--";
Derek Allard2067d1a2008-11-13 22:59:24 +00001041 }
1042
Derek Allard2067d1a2008-11-13 22:59:24 +00001043 return;
1044
Derek Allard2067d1a2008-11-13 22:59:24 +00001045 case 'plain-attach' :
1046
Derek Jonesa45e7612009-02-10 18:33:01 +00001047 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001048
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001049 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001050 {
1051 $this->_header_str .= $hdr;
Eric Barnes6113f542010-12-29 13:36:12 -05001052 }
1053
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001054 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1055 . "--" . $this->_atc_boundary . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001056
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001057 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1058 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001059
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001060 . $this->_body . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001061
1062 break;
1063 case 'html-attach' :
1064
Derek Jonesa45e7612009-02-10 18:33:01 +00001065 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -05001066
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001067 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001068 {
1069 $this->_header_str .= $hdr;
Derek Allard2067d1a2008-11-13 22:59:24 +00001070 }
1071
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001072 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1073 . "--" . $this->_atc_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001074
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001075 . "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline
1076 . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001077
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001078 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1079 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
1080 . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001081
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001082 . "Content-Type: text/html; charset=" . $this->charset . $this->newline
1083 . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001084
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001085 . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline
1086 . "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001087
1088 break;
1089 }
1090
1091 $attachment = array();
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001092 for ($i = 0, $c = count($this->_attach_name), $z = 0; $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001093 {
tritbc4ac992011-11-23 07:19:41 -05001094 $filename = $this->_attach_name[$i][0];
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001095 $basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1];
Derek Allard2067d1a2008-11-13 22:59:24 +00001096 $ctype = $this->_attach_type[$i];
1097
tritbc4ac992011-11-23 07:19:41 -05001098 if ( ! file_exists($filename))
Derek Allard2067d1a2008-11-13 22:59:24 +00001099 {
tritbc4ac992011-11-23 07:19:41 -05001100 $this->_set_error_message('lang:email_attachment_missing', $filename);
Derek Allard2067d1a2008-11-13 22:59:24 +00001101 return FALSE;
1102 }
1103
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001104 $attachment[$z++] = "--".$this->_atc_boundary.$this->newline
1105 . "Content-type: ".$ctype."; "
1106 . "name=\"".$basename."\"".$this->newline
1107 . "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline
1108 . "Content-Transfer-Encoding: base64".$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001109
tritbc4ac992011-11-23 07:19:41 -05001110 $file = filesize($filename) +1;
Derek Allard2067d1a2008-11-13 22:59:24 +00001111
tritbc4ac992011-11-23 07:19:41 -05001112 if ( ! $fp = fopen($filename, FOPEN_READ))
Derek Allard2067d1a2008-11-13 22:59:24 +00001113 {
tritbc4ac992011-11-23 07:19:41 -05001114 $this->_set_error_message('lang:email_attachment_unreadable', $filename);
Derek Allard2067d1a2008-11-13 22:59:24 +00001115 return FALSE;
1116 }
1117
1118 $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file)));
1119 fclose($fp);
1120 }
1121
Brandon Jones485d7412010-11-09 16:38:17 -05001122 $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001123 $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr . $body;
Derek Allard2067d1a2008-11-13 22:59:24 +00001124 return;
1125 }
Barry Mienydd671972010-10-04 16:33:58 +02001126
Derek Allard2067d1a2008-11-13 22:59:24 +00001127 // --------------------------------------------------------------------
1128
1129 /**
1130 * Prep Quoted Printable
1131 *
1132 * Prepares string for Quoted-Printable Content-Transfer-Encoding
1133 * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
1134 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001135 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001136 * @param string
1137 * @param integer
1138 * @return string
1139 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001140 protected function _prep_quoted_printable($str, $charlim = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001141 {
1142 // Set the character limit
1143 // Don't allow over 76, as that will make servers and MUAs barf
1144 // all over quoted-printable data
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001145 if ($charlim == '' OR $charlim > 76)
Derek Allard2067d1a2008-11-13 22:59:24 +00001146 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001147 $charlim = 76;
Derek Allard2067d1a2008-11-13 22:59:24 +00001148 }
1149
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001150 // Reduce multiple spaces & remove nulls
1151 $str = preg_replace(array("| +|", '/\x00+/'), array(' ', ''), $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001152
1153 // Standardize newlines
1154 if (strpos($str, "\r") !== FALSE)
1155 {
1156 $str = str_replace(array("\r\n", "\r"), "\n", $str);
1157 }
1158
1159 // We are intentionally wrapping so mail servers will encode characters
1160 // properly and MUAs will behave, so {unwrap} must go!
1161 $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);
1162
Derek Allard2067d1a2008-11-13 22:59:24 +00001163 $escape = '=';
1164 $output = '';
1165
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001166 foreach (explode("\n", $str) as $line)
Derek Allard2067d1a2008-11-13 22:59:24 +00001167 {
1168 $length = strlen($line);
1169 $temp = '';
1170
1171 // Loop through each character in the line to add soft-wrap
1172 // characters at the end of a line " =\r\n" and add the newly
1173 // processed line(s) to the output (see comment on $crlf class property)
1174 for ($i = 0; $i < $length; $i++)
1175 {
1176 // Grab the next character
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001177 $char = $line[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001178 $ascii = ord($char);
1179
1180 // Convert spaces and tabs but only if it's the end of the line
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001181 if ($i === ($length - 1) && ($ascii === 32 OR $ascii === 9))
Derek Allard2067d1a2008-11-13 22:59:24 +00001182 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001183 $char = $escape.sprintf('%02s', dechex($ascii));
Derek Allard2067d1a2008-11-13 22:59:24 +00001184 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001185 elseif ($ascii === 61) // encode = signs
Derek Allard2067d1a2008-11-13 22:59:24 +00001186 {
Derek Jones37f4b9c2011-07-01 17:56:50 -05001187 $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D
Derek Allard2067d1a2008-11-13 22:59:24 +00001188 }
1189
1190 // If we're at the character limit, add the line to the output,
1191 // reset our temp variable, and keep on chuggin'
1192 if ((strlen($temp) + strlen($char)) >= $charlim)
1193 {
1194 $output .= $temp.$escape.$this->crlf;
1195 $temp = '';
1196 }
1197
1198 // Add the character to our temporary line
1199 $temp .= $char;
1200 }
1201
1202 // Add our completed line to the output
1203 $output .= $temp.$this->crlf;
1204 }
1205
1206 // get rid of extra CRLF tacked onto the end
1207 $output = substr($output, 0, strlen($this->crlf) * -1);
1208
1209 return $output;
1210 }
1211
1212 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001213
Derek Allard2067d1a2008-11-13 22:59:24 +00001214 /**
1215 * Prep Q Encoding
1216 *
Derek Jones37f4b9c2011-07-01 17:56:50 -05001217 * Performs "Q Encoding" on a string for use in email headers. It's related
Derek Allard2067d1a2008-11-13 22:59:24 +00001218 * but not identical to quoted-printable, so it has its own method
1219 *
1220 * @access public
1221 * @param str
1222 * @param bool // set to TRUE for processing From: headers
1223 * @return str
1224 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001225 protected function _prep_q_encoding($str, $from = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001226 {
1227 $str = str_replace(array("\r", "\n"), array('', ''), $str);
1228
1229 // Line length must not exceed 76 characters, so we adjust for
1230 // a space, 7 extra characters =??Q??=, and the charset that we will add to each line
1231 $limit = 75 - 7 - strlen($this->charset);
1232
1233 // these special characters must be converted too
1234 $convert = array('_', '=', '?');
1235
1236 if ($from === TRUE)
1237 {
1238 $convert[] = ',';
1239 $convert[] = ';';
1240 }
1241
1242 $output = '';
1243 $temp = '';
1244
1245 for ($i = 0, $length = strlen($str); $i < $length; $i++)
1246 {
1247 // Grab the next character
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001248 $char = $str[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001249 $ascii = ord($char);
1250
1251 // convert ALL non-printable ASCII characters and our specials
1252 if ($ascii < 32 OR $ascii > 126 OR in_array($char, $convert))
1253 {
1254 $char = '='.dechex($ascii);
1255 }
1256
1257 // handle regular spaces a bit more compactly than =20
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001258 if ($ascii === 32)
Derek Allard2067d1a2008-11-13 22:59:24 +00001259 {
1260 $char = '_';
1261 }
1262
1263 // If we're at the character limit, add the line to the output,
1264 // reset our temp variable, and keep on chuggin'
1265 if ((strlen($temp) + strlen($char)) >= $limit)
1266 {
1267 $output .= $temp.$this->crlf;
1268 $temp = '';
1269 }
1270
1271 // Add the character to our temporary line
1272 $temp .= $char;
1273 }
1274
1275 $str = $output.$temp;
1276
1277 // wrap each line with the shebang, charset, and transfer encoding
1278 // the preceding space on successive lines is required for header "folding"
1279 $str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
1280
1281 return $str;
1282 }
1283
1284 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001285
Derek Allard2067d1a2008-11-13 22:59:24 +00001286 /**
1287 * Send Email
1288 *
1289 * @access public
1290 * @return bool
1291 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001292 public function send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001293 {
1294 if ($this->_replyto_flag == FALSE)
1295 {
1296 $this->reply_to($this->_headers['From']);
1297 }
1298
Derek Jones37f4b9c2011-07-01 17:56:50 -05001299 if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND
Derek Allard2067d1a2008-11-13 22:59:24 +00001300 ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
1301 ( ! isset($this->_headers['Cc'])))
1302 {
patworkb0707982011-04-08 15:10:05 +02001303 $this->_set_error_message('lang:email_no_recipients');
Derek Allard2067d1a2008-11-13 22:59:24 +00001304 return FALSE;
1305 }
1306
1307 $this->_build_headers();
1308
Andrey Andreevb71e06b2011-12-22 19:22:50 +02001309 if ($this->bcc_batch_mode AND count($this->_bcc_array) > $this->bcc_batch_size)
Derek Allard2067d1a2008-11-13 22:59:24 +00001310 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001311 return $this->batch_bcc_send();
Derek Allard2067d1a2008-11-13 22:59:24 +00001312 }
1313
1314 $this->_build_message();
1315
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001316 return $this->_spool_email();
Derek Allard2067d1a2008-11-13 22:59:24 +00001317 }
Barry Mienydd671972010-10-04 16:33:58 +02001318
Derek Allard2067d1a2008-11-13 22:59:24 +00001319 // --------------------------------------------------------------------
1320
1321 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -05001322 * Batch Bcc Send. Sends groups of BCCs in batches
Derek Allard2067d1a2008-11-13 22:59:24 +00001323 *
1324 * @access public
1325 * @return bool
1326 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001327 public function batch_bcc_send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001328 {
1329 $float = $this->bcc_batch_size -1;
1330
1331 $set = "";
1332
1333 $chunk = array();
1334
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001335 for ($i = 0, $c = count($this->_bcc_array); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001336 {
1337 if (isset($this->_bcc_array[$i]))
1338 {
1339 $set .= ", ".$this->_bcc_array[$i];
1340 }
1341
1342 if ($i == $float)
1343 {
1344 $chunk[] = substr($set, 1);
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001345 $float += $this->bcc_batch_size;
Derek Allard2067d1a2008-11-13 22:59:24 +00001346 $set = "";
1347 }
1348
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001349 if ($i === $c-1)
Derek Allard2067d1a2008-11-13 22:59:24 +00001350 {
1351 $chunk[] = substr($set, 1);
1352 }
1353 }
1354
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001355 for ($i = 0, $c = count($chunk); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001356 {
1357 unset($this->_headers['Bcc']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001358
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001359 $bcc = $this->clean_email($this->_str_to_array($chunk[$i]));
Derek Allard2067d1a2008-11-13 22:59:24 +00001360
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001361 if ($this->protocol !== 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +00001362 {
1363 $this->_set_header('Bcc', implode(", ", $bcc));
1364 }
1365 else
1366 {
1367 $this->_bcc_array = $bcc;
1368 }
1369
1370 $this->_build_message();
1371 $this->_spool_email();
1372 }
1373 }
Barry Mienydd671972010-10-04 16:33:58 +02001374
Derek Allard2067d1a2008-11-13 22:59:24 +00001375 // --------------------------------------------------------------------
1376
1377 /**
1378 * Unwrap special elements
1379 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001380 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001381 * @return void
1382 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001383 protected function _unwrap_specials()
Derek Allard2067d1a2008-11-13 22:59:24 +00001384 {
1385 $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
1386 }
Barry Mienydd671972010-10-04 16:33:58 +02001387
Derek Allard2067d1a2008-11-13 22:59:24 +00001388 // --------------------------------------------------------------------
1389
1390 /**
1391 * Strip line-breaks via callback
1392 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001393 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001394 * @return string
1395 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001396 protected function _remove_nl_callback($matches)
Derek Allard2067d1a2008-11-13 22:59:24 +00001397 {
1398 if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
1399 {
1400 $matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]);
1401 }
1402
1403 return $matches[1];
1404 }
Barry Mienydd671972010-10-04 16:33:58 +02001405
Derek Allard2067d1a2008-11-13 22:59:24 +00001406 // --------------------------------------------------------------------
1407
1408 /**
1409 * Spool mail to the mail server
1410 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001411 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001412 * @return bool
1413 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001414 protected function _spool_email()
Derek Allard2067d1a2008-11-13 22:59:24 +00001415 {
1416 $this->_unwrap_specials();
1417
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001418 $method = '_send_with_' . $this->_get_protocol();
1419 if ( ! $this->$method())
Derek Allard2067d1a2008-11-13 22:59:24 +00001420 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001421 $this->_set_error_message('lang:email_send_failure_' . ($this->_get_protocol() === 'mail' ? 'phpmail' : $this->_get_protocol()));
Derek Allard2067d1a2008-11-13 22:59:24 +00001422 }
1423
patworkb0707982011-04-08 15:10:05 +02001424 $this->_set_error_message('lang:email_sent', $this->_get_protocol());
Derek Allard2067d1a2008-11-13 22:59:24 +00001425 return TRUE;
1426 }
Barry Mienydd671972010-10-04 16:33:58 +02001427
Derek Allard2067d1a2008-11-13 22:59:24 +00001428 // --------------------------------------------------------------------
1429
1430 /**
1431 * Send using mail()
1432 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001433 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001434 * @return bool
1435 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001436 protected function _send_with_mail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001437 {
1438 if ($this->_safe_mode == TRUE)
1439 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001440 return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001441 }
1442 else
1443 {
1444 // most documentation of sendmail using the "-f" flag lacks a space after it, however
1445 // we've encountered servers that seem to require it to be in place.
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001446 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 +00001447 }
1448 }
Barry Mienydd671972010-10-04 16:33:58 +02001449
Derek Allard2067d1a2008-11-13 22:59:24 +00001450 // --------------------------------------------------------------------
1451
1452 /**
1453 * Send using Sendmail
1454 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001455 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001456 * @return bool
1457 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001458 protected function _send_with_sendmail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001459 {
1460 $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
1461
Derek Jones4cefaa42009-04-29 19:13:56 +00001462 if ($fp === FALSE OR $fp === NULL)
1463 {
1464 // server probably has popen disabled, so nothing we can do to get a verbose error.
1465 return FALSE;
1466 }
Derek Jones71141ce2010-03-02 16:41:20 -06001467
Derek Jonesc630bcf2008-11-17 21:09:45 +00001468 fputs($fp, $this->_header_str);
1469 fputs($fp, $this->_finalbody);
1470
Barry Mienydd671972010-10-04 16:33:58 +02001471 $status = pclose($fp);
Eric Barnes6113f542010-12-29 13:36:12 -05001472
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001473 if ($status !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001474 {
patworkb0707982011-04-08 15:10:05 +02001475 $this->_set_error_message('lang:email_exit_status', $status);
1476 $this->_set_error_message('lang:email_no_socket');
Derek Allard2067d1a2008-11-13 22:59:24 +00001477 return FALSE;
1478 }
1479
Derek Allard2067d1a2008-11-13 22:59:24 +00001480 return TRUE;
1481 }
Barry Mienydd671972010-10-04 16:33:58 +02001482
Derek Allard2067d1a2008-11-13 22:59:24 +00001483 // --------------------------------------------------------------------
1484
1485 /**
1486 * Send using SMTP
1487 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001488 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001489 * @return bool
1490 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001491 protected function _send_with_smtp()
Derek Allard2067d1a2008-11-13 22:59:24 +00001492 {
1493 if ($this->smtp_host == '')
1494 {
patworkb0707982011-04-08 15:10:05 +02001495 $this->_set_error_message('lang:email_no_hostname');
Derek Allard2067d1a2008-11-13 22:59:24 +00001496 return FALSE;
1497 }
1498
1499 $this->_smtp_connect();
1500 $this->_smtp_authenticate();
1501
1502 $this->_send_command('from', $this->clean_email($this->_headers['From']));
1503
Pascal Kriete14287f32011-02-14 13:39:34 -05001504 foreach ($this->_recipients as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001505 {
1506 $this->_send_command('to', $val);
1507 }
1508
1509 if (count($this->_cc_array) > 0)
1510 {
Pascal Kriete14287f32011-02-14 13:39:34 -05001511 foreach ($this->_cc_array as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001512 {
1513 if ($val != "")
1514 {
1515 $this->_send_command('to', $val);
1516 }
1517 }
1518 }
1519
1520 if (count($this->_bcc_array) > 0)
1521 {
Pascal Kriete14287f32011-02-14 13:39:34 -05001522 foreach ($this->_bcc_array as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001523 {
1524 if ($val != "")
1525 {
1526 $this->_send_command('to', $val);
1527 }
1528 }
1529 }
1530
1531 $this->_send_command('data');
1532
1533 // perform dot transformation on any lines that begin with a dot
1534 $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody));
1535
1536 $this->_send_data('.');
1537
1538 $reply = $this->_get_smtp_data();
1539
1540 $this->_set_error_message($reply);
1541
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001542 if (strncmp($reply, '250', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001543 {
patworkb0707982011-04-08 15:10:05 +02001544 $this->_set_error_message('lang:email_smtp_error', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001545 return FALSE;
1546 }
1547
1548 $this->_send_command('quit');
1549 return TRUE;
1550 }
Barry Mienydd671972010-10-04 16:33:58 +02001551
Derek Allard2067d1a2008-11-13 22:59:24 +00001552 // --------------------------------------------------------------------
1553
1554 /**
1555 * SMTP Connect
1556 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001557 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001558 * @param string
1559 * @return string
1560 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001561 protected function _smtp_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +00001562 {
Phil Sturgeonc00a5a02011-11-22 15:25:32 +00001563 $ssl = ($this->smtp_crypto == 'ssl') ? 'ssl://' : NULL;
Radu Potop4c589ae2011-09-29 10:19:55 +03001564
Radu Potopbbf04b02011-09-28 13:57:51 +03001565 $this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
Derek Allard2067d1a2008-11-13 22:59:24 +00001566 $this->smtp_port,
1567 $errno,
1568 $errstr,
1569 $this->smtp_timeout);
1570
Pascal Kriete14287f32011-02-14 13:39:34 -05001571 if ( ! is_resource($this->_smtp_connect))
Derek Allard2067d1a2008-11-13 22:59:24 +00001572 {
patworkb0707982011-04-08 15:10:05 +02001573 $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr);
Derek Allard2067d1a2008-11-13 22:59:24 +00001574 return FALSE;
1575 }
1576
1577 $this->_set_error_message($this->_get_smtp_data());
Radu Potopbbf04b02011-09-28 13:57:51 +03001578
1579 if ($this->smtp_crypto == 'tls')
1580 {
1581 $this->_send_command('hello');
1582 $this->_send_command('starttls');
Phil Sturgeonc00a5a02011-11-22 15:25:32 +00001583
Radu Potop4c589ae2011-09-29 10:19:55 +03001584 $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
Radu Potop4c589ae2011-09-29 10:19:55 +03001585
Sean Fishere862ddd2011-10-26 22:45:00 -03001586 if ($crypto !== TRUE)
1587 {
1588 $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data());
1589 return FALSE;
1590 }
Radu Potopbbf04b02011-09-28 13:57:51 +03001591 }
1592
Derek Allard2067d1a2008-11-13 22:59:24 +00001593 return $this->_send_command('hello');
1594 }
Barry Mienydd671972010-10-04 16:33:58 +02001595
Derek Allard2067d1a2008-11-13 22:59:24 +00001596 // --------------------------------------------------------------------
1597
1598 /**
1599 * Send SMTP command
1600 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001601 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001602 * @param string
1603 * @param string
1604 * @return string
1605 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001606 protected function _send_command($cmd, $data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001607 {
1608 switch ($cmd)
1609 {
1610 case 'hello' :
1611
1612 if ($this->_smtp_auth OR $this->_get_encoding() == '8bit')
1613 $this->_send_data('EHLO '.$this->_get_hostname());
1614 else
1615 $this->_send_data('HELO '.$this->_get_hostname());
1616
1617 $resp = 250;
1618 break;
Radu Potopbbf04b02011-09-28 13:57:51 +03001619 case 'starttls' :
1620
1621 $this->_send_data('STARTTLS');
1622
1623 $resp = 220;
1624 break;
Derek Allard2067d1a2008-11-13 22:59:24 +00001625 case 'from' :
1626
1627 $this->_send_data('MAIL FROM:<'.$data.'>');
1628
1629 $resp = 250;
1630 break;
1631 case 'to' :
1632
1633 $this->_send_data('RCPT TO:<'.$data.'>');
1634
1635 $resp = 250;
1636 break;
1637 case 'data' :
1638
1639 $this->_send_data('DATA');
1640
1641 $resp = 354;
1642 break;
1643 case 'quit' :
1644
1645 $this->_send_data('QUIT');
1646
1647 $resp = 221;
1648 break;
1649 }
1650
1651 $reply = $this->_get_smtp_data();
1652
1653 $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>";
1654
1655 if (substr($reply, 0, 3) != $resp)
1656 {
patworkb0707982011-04-08 15:10:05 +02001657 $this->_set_error_message('lang:email_smtp_error', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001658 return FALSE;
1659 }
1660
1661 if ($cmd == 'quit')
1662 {
1663 fclose($this->_smtp_connect);
1664 }
1665
1666 return TRUE;
1667 }
Barry Mienydd671972010-10-04 16:33:58 +02001668
Derek Allard2067d1a2008-11-13 22:59:24 +00001669 // --------------------------------------------------------------------
1670
1671 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -05001672 * SMTP Authenticate
Derek Allard2067d1a2008-11-13 22:59:24 +00001673 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001674 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001675 * @return bool
1676 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001677 protected function _smtp_authenticate()
Derek Allard2067d1a2008-11-13 22:59:24 +00001678 {
1679 if ( ! $this->_smtp_auth)
1680 {
1681 return TRUE;
1682 }
1683
Derek Jones37f4b9c2011-07-01 17:56:50 -05001684 if ($this->smtp_user == "" AND $this->smtp_pass == "")
Derek Allard2067d1a2008-11-13 22:59:24 +00001685 {
patworkb0707982011-04-08 15:10:05 +02001686 $this->_set_error_message('lang:email_no_smtp_unpw');
Derek Allard2067d1a2008-11-13 22:59:24 +00001687 return FALSE;
1688 }
1689
1690 $this->_send_data('AUTH LOGIN');
1691
1692 $reply = $this->_get_smtp_data();
1693
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001694 if (strncmp($reply, '334', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001695 {
patworkb0707982011-04-08 15:10:05 +02001696 $this->_set_error_message('lang:email_failed_smtp_login', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001697 return FALSE;
1698 }
1699
1700 $this->_send_data(base64_encode($this->smtp_user));
1701
1702 $reply = $this->_get_smtp_data();
1703
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001704 if (strncmp($reply, '334', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001705 {
patworkb0707982011-04-08 15:10:05 +02001706 $this->_set_error_message('lang:email_smtp_auth_un', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001707 return FALSE;
1708 }
1709
1710 $this->_send_data(base64_encode($this->smtp_pass));
1711
1712 $reply = $this->_get_smtp_data();
1713
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001714 if (strncmp($reply, '235', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001715 {
patworkb0707982011-04-08 15:10:05 +02001716 $this->_set_error_message('lang:email_smtp_auth_pw', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001717 return FALSE;
1718 }
1719
1720 return TRUE;
1721 }
Barry Mienydd671972010-10-04 16:33:58 +02001722
Derek Allard2067d1a2008-11-13 22:59:24 +00001723 // --------------------------------------------------------------------
1724
1725 /**
1726 * Send SMTP data
1727 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001728 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001729 * @return bool
1730 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001731 protected function _send_data($data)
Derek Allard2067d1a2008-11-13 22:59:24 +00001732 {
1733 if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
1734 {
patworkb0707982011-04-08 15:10:05 +02001735 $this->_set_error_message('lang:email_smtp_data_failure', $data);
Derek Allard2067d1a2008-11-13 22:59:24 +00001736 return FALSE;
1737 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001738
1739 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001740 }
Barry Mienydd671972010-10-04 16:33:58 +02001741
Derek Allard2067d1a2008-11-13 22:59:24 +00001742 // --------------------------------------------------------------------
1743
1744 /**
1745 * Get SMTP data
1746 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001747 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001748 * @return string
1749 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001750 protected function _get_smtp_data()
Derek Allard2067d1a2008-11-13 22:59:24 +00001751 {
1752 $data = "";
1753
1754 while ($str = fgets($this->_smtp_connect, 512))
1755 {
1756 $data .= $str;
1757
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001758 if ($str[3] == " ")
Derek Allard2067d1a2008-11-13 22:59:24 +00001759 {
1760 break;
1761 }
1762 }
1763
1764 return $data;
1765 }
Barry Mienydd671972010-10-04 16:33:58 +02001766
Derek Allard2067d1a2008-11-13 22:59:24 +00001767 // --------------------------------------------------------------------
1768
1769 /**
1770 * Get Hostname
1771 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001772 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001773 * @return string
1774 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001775 protected function _get_hostname()
Derek Allard2067d1a2008-11-13 22:59:24 +00001776 {
1777 return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
1778 }
Barry Mienydd671972010-10-04 16:33:58 +02001779
Derek Allard2067d1a2008-11-13 22:59:24 +00001780 // --------------------------------------------------------------------
1781
1782 /**
1783 * Get IP
1784 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001785 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001786 * @return string
1787 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001788 protected function _get_ip()
Derek Allard2067d1a2008-11-13 22:59:24 +00001789 {
1790 if ($this->_IP !== FALSE)
1791 {
1792 return $this->_IP;
1793 }
1794
1795 $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
1796 $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001797 if ($cip) $this->_IP = $cip;
1798 elseif ($rip) $this->_IP = $rip;
1799 else
1800 {
1801 $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
1802 if ($fip)
1803 {
1804 $this->_IP = $fip;
1805 }
1806 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001807
Robin Sowell76b369e2010-03-19 11:15:28 -04001808 if (strpos($this->_IP, ',') !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001809 {
1810 $x = explode(',', $this->_IP);
1811 $this->_IP = end($x);
1812 }
1813
1814 if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
1815 {
1816 $this->_IP = '0.0.0.0';
1817 }
1818
Derek Allard2067d1a2008-11-13 22:59:24 +00001819 return $this->_IP;
1820 }
Barry Mienydd671972010-10-04 16:33:58 +02001821
Derek Allard2067d1a2008-11-13 22:59:24 +00001822 // --------------------------------------------------------------------
1823
1824 /**
1825 * Get Debug Message
1826 *
1827 * @access public
1828 * @return string
1829 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001830 public function print_debugger()
Derek Allard2067d1a2008-11-13 22:59:24 +00001831 {
1832 $msg = '';
1833
1834 if (count($this->_debug_msg) > 0)
1835 {
1836 foreach ($this->_debug_msg as $val)
1837 {
1838 $msg .= $val;
1839 }
1840 }
1841
1842 $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
1843 return $msg;
1844 }
Barry Mienydd671972010-10-04 16:33:58 +02001845
Derek Allard2067d1a2008-11-13 22:59:24 +00001846 // --------------------------------------------------------------------
1847
1848 /**
1849 * Set Message
1850 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001851 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001852 * @param string
1853 * @return string
1854 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001855 protected function _set_error_message($msg, $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001856 {
1857 $CI =& get_instance();
1858 $CI->lang->load('email');
1859
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001860 if (substr($msg, 0, 5) !== 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5))))
Derek Allard2067d1a2008-11-13 22:59:24 +00001861 {
1862 $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
1863 }
1864 else
1865 {
1866 $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />";
1867 }
1868 }
Barry Mienydd671972010-10-04 16:33:58 +02001869
Derek Allard2067d1a2008-11-13 22:59:24 +00001870 // --------------------------------------------------------------------
1871
1872 /**
1873 * Mime Types
1874 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001875 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001876 * @param string
1877 * @return string
1878 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001879 protected function _mime_types($ext = "")
Derek Allard2067d1a2008-11-13 22:59:24 +00001880 {
1881 $mimes = array( 'hqx' => 'application/mac-binhex40',
1882 'cpt' => 'application/mac-compactpro',
1883 'doc' => 'application/msword',
1884 'bin' => 'application/macbinary',
1885 'dms' => 'application/octet-stream',
1886 'lha' => 'application/octet-stream',
1887 'lzh' => 'application/octet-stream',
1888 'exe' => 'application/octet-stream',
1889 'class' => 'application/octet-stream',
1890 'psd' => 'application/octet-stream',
1891 'so' => 'application/octet-stream',
1892 'sea' => 'application/octet-stream',
1893 'dll' => 'application/octet-stream',
1894 'oda' => 'application/oda',
1895 'pdf' => 'application/pdf',
1896 'ai' => 'application/postscript',
1897 'eps' => 'application/postscript',
1898 'ps' => 'application/postscript',
1899 'smi' => 'application/smil',
1900 'smil' => 'application/smil',
1901 'mif' => 'application/vnd.mif',
1902 'xls' => 'application/vnd.ms-excel',
1903 'ppt' => 'application/vnd.ms-powerpoint',
1904 'wbxml' => 'application/vnd.wap.wbxml',
1905 'wmlc' => 'application/vnd.wap.wmlc',
1906 'dcr' => 'application/x-director',
1907 'dir' => 'application/x-director',
1908 'dxr' => 'application/x-director',
1909 'dvi' => 'application/x-dvi',
1910 'gtar' => 'application/x-gtar',
1911 'php' => 'application/x-httpd-php',
1912 'php4' => 'application/x-httpd-php',
1913 'php3' => 'application/x-httpd-php',
1914 'phtml' => 'application/x-httpd-php',
1915 'phps' => 'application/x-httpd-php-source',
1916 'js' => 'application/x-javascript',
1917 'swf' => 'application/x-shockwave-flash',
1918 'sit' => 'application/x-stuffit',
1919 'tar' => 'application/x-tar',
1920 'tgz' => 'application/x-tar',
1921 'xhtml' => 'application/xhtml+xml',
1922 'xht' => 'application/xhtml+xml',
1923 'zip' => 'application/zip',
1924 'mid' => 'audio/midi',
1925 'midi' => 'audio/midi',
1926 'mpga' => 'audio/mpeg',
1927 'mp2' => 'audio/mpeg',
1928 'mp3' => 'audio/mpeg',
1929 'aif' => 'audio/x-aiff',
1930 'aiff' => 'audio/x-aiff',
1931 'aifc' => 'audio/x-aiff',
1932 'ram' => 'audio/x-pn-realaudio',
1933 'rm' => 'audio/x-pn-realaudio',
1934 'rpm' => 'audio/x-pn-realaudio-plugin',
1935 'ra' => 'audio/x-realaudio',
1936 'rv' => 'video/vnd.rn-realvideo',
1937 'wav' => 'audio/x-wav',
1938 'bmp' => 'image/bmp',
1939 'gif' => 'image/gif',
1940 'jpeg' => 'image/jpeg',
1941 'jpg' => 'image/jpeg',
1942 'jpe' => 'image/jpeg',
1943 'png' => 'image/png',
1944 'tiff' => 'image/tiff',
1945 'tif' => 'image/tiff',
1946 'css' => 'text/css',
1947 'html' => 'text/html',
1948 'htm' => 'text/html',
1949 'shtml' => 'text/html',
1950 'txt' => 'text/plain',
1951 'text' => 'text/plain',
1952 'log' => 'text/plain',
1953 'rtx' => 'text/richtext',
1954 'rtf' => 'text/rtf',
1955 'xml' => 'text/xml',
1956 'xsl' => 'text/xml',
1957 'mpeg' => 'video/mpeg',
1958 'mpg' => 'video/mpeg',
1959 'mpe' => 'video/mpeg',
1960 'qt' => 'video/quicktime',
1961 'mov' => 'video/quicktime',
1962 'avi' => 'video/x-msvideo',
1963 'movie' => 'video/x-sgi-movie',
1964 'doc' => 'application/msword',
1965 'word' => 'application/msword',
1966 'xl' => 'application/excel',
1967 'eml' => 'message/rfc822'
1968 );
1969
1970 return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
1971 }
1972
1973}
1974// END CI_Email class
1975
1976/* End of file Email.php */
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001977/* Location: ./system/libraries/Email.php */