blob: 1066535c7fc3fa89a48057d266bbb263612b590b [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
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @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
67 private $_safe_mode = FALSE;
68 private $_subject = "";
69 private $_body = "";
70 private $_finalbody = "";
71 private $_alt_boundary = "";
72 private $_atc_boundary = "";
73 private $_header_str = "";
74 private $_smtp_connect = "";
75 private $_encoding = "8bit";
76 private $_IP = FALSE;
77 private $_smtp_auth = FALSE;
78 private $_replyto_flag = FALSE;
79 private $_debug_msg = array();
80 private $_recipients = array();
81 private $_cc_array = array();
82 private $_bcc_array = array();
83 private $_headers = array();
84 private $_attach_name = array();
85 private $_attach_type = array();
86 private $_attach_disp = array();
87 private $_protocols = array('mail', 'sendmail', 'smtp');
88 private $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix)
89 private $_bit_depths = array('7bit', '8bit');
90 private $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
Derek Allard2067d1a2008-11-13 22:59:24 +000091
92
93 /**
94 * Constructor - Sets Email Preferences
95 *
96 * The constructor can be passed an array of config values
97 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +000098 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000099 {
100 if (count($config) > 0)
101 {
102 $this->initialize($config);
103 }
104 else
105 {
106 $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200107 $this->_safe_mode = (bool) @ini_get("safe_mode");
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 }
109
110 log_message('debug', "Email Class Initialized");
111 }
112
113 // --------------------------------------------------------------------
114
115 /**
116 * Initialize preferences
117 *
118 * @access public
119 * @param array
120 * @return void
121 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000122 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 foreach ($config as $key => $val)
125 {
126 if (isset($this->$key))
127 {
128 $method = 'set_'.$key;
129
130 if (method_exists($this, $method))
131 {
132 $this->$method($val);
133 }
134 else
135 {
136 $this->$key = $val;
137 }
138 }
139 }
Eric Barnes6113f542010-12-29 13:36:12 -0500140 $this->clear();
Derek Allard2067d1a2008-11-13 22:59:24 +0000141
142 $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200143 $this->_safe_mode = (bool) @ini_get("safe_mode");
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000144
145 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 }
Barry Mienydd671972010-10-04 16:33:58 +0200147
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 // --------------------------------------------------------------------
149
150 /**
151 * Initialize the Email Data
152 *
153 * @access public
Bo-Yi Wu83320eb2011-09-15 13:28:02 +0800154 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 * @return void
156 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000157 public function clear($clear_attachments = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000158 {
159 $this->_subject = "";
160 $this->_body = "";
161 $this->_finalbody = "";
162 $this->_header_str = "";
163 $this->_replyto_flag = FALSE;
164 $this->_recipients = array();
Derek Jonesd1606352010-09-01 11:16:07 -0500165 $this->_cc_array = array();
166 $this->_bcc_array = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 $this->_headers = array();
168 $this->_debug_msg = array();
169
170 $this->_set_header('User-Agent', $this->useragent);
171 $this->_set_header('Date', $this->_set_date());
172
173 if ($clear_attachments !== FALSE)
174 {
175 $this->_attach_name = array();
176 $this->_attach_type = array();
177 $this->_attach_disp = array();
178 }
Eric Barnes6113f542010-12-29 13:36:12 -0500179
Greg Akera769deb2010-11-10 15:47:29 -0600180 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000181 }
Barry Mienydd671972010-10-04 16:33:58 +0200182
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 // --------------------------------------------------------------------
184
185 /**
186 * Set FROM
187 *
188 * @access public
189 * @param string
190 * @param string
191 * @return void
192 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000193 public function from($from, $name = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 {
195 if (preg_match( '/\<(.*)\>/', $from, $match))
196 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200197 $from = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 }
199
200 if ($this->validate)
201 {
202 $this->validate_email($this->_str_to_array($from));
203 }
204
205 // prepare the display name
206 if ($name != '')
207 {
208 // only use Q encoding if there are characters that would require it
209 if ( ! preg_match('/[\200-\377]/', $name))
210 {
211 // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
Derek Jonesc630bcf2008-11-17 21:09:45 +0000212 $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"';
Derek Allard2067d1a2008-11-13 22:59:24 +0000213 }
214 else
215 {
216 $name = $this->_prep_q_encoding($name, TRUE);
217 }
218 }
219
220 $this->_set_header('From', $name.' <'.$from.'>');
221 $this->_set_header('Return-Path', '<'.$from.'>');
Eric Barnes6113f542010-12-29 13:36:12 -0500222
Greg Akera769deb2010-11-10 15:47:29 -0600223 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 }
Barry Mienydd671972010-10-04 16:33:58 +0200225
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 // --------------------------------------------------------------------
227
228 /**
229 * Set Reply-to
230 *
231 * @access public
232 * @param string
233 * @param string
234 * @return void
235 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000236 public function reply_to($replyto, $name = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 {
238 if (preg_match( '/\<(.*)\>/', $replyto, $match))
239 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200240 $replyto = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 }
242
243 if ($this->validate)
244 {
245 $this->validate_email($this->_str_to_array($replyto));
246 }
247
248 if ($name == '')
249 {
250 $name = $replyto;
251 }
252
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200253 if (strncmp($name, '"', 1) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 {
255 $name = '"'.$name.'"';
256 }
257
258 $this->_set_header('Reply-To', $name.' <'.$replyto.'>');
259 $this->_replyto_flag = TRUE;
Greg Akera769deb2010-11-10 15:47:29 -0600260
261 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 }
Barry Mienydd671972010-10-04 16:33:58 +0200263
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 // --------------------------------------------------------------------
265
266 /**
267 * Set Recipients
268 *
269 * @access public
270 * @param string
271 * @return void
272 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000273 public function to($to)
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 {
275 $to = $this->_str_to_array($to);
276 $to = $this->clean_email($to);
277
278 if ($this->validate)
279 {
280 $this->validate_email($to);
281 }
282
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200283 if ($this->_get_protocol() !== 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000284 {
285 $this->_set_header('To', implode(", ", $to));
286 }
287
288 switch ($this->_get_protocol())
289 {
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000290 case 'smtp' :
291 $this->_recipients = $to;
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 break;
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000293 case 'sendmail' :
294 case 'mail' :
295 $this->_recipients = implode(", ", $to);
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 break;
297 }
Eric Barnes6113f542010-12-29 13:36:12 -0500298
Greg Akera769deb2010-11-10 15:47:29 -0600299 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 }
Barry Mienydd671972010-10-04 16:33:58 +0200301
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 // --------------------------------------------------------------------
303
304 /**
305 * Set CC
306 *
307 * @access public
308 * @param string
309 * @return void
310 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000311 public function cc($cc)
Derek Allard2067d1a2008-11-13 22:59:24 +0000312 {
313 $cc = $this->_str_to_array($cc);
314 $cc = $this->clean_email($cc);
315
316 if ($this->validate)
317 {
318 $this->validate_email($cc);
319 }
320
321 $this->_set_header('Cc', implode(", ", $cc));
322
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200323 if ($this->_get_protocol() === 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 {
325 $this->_cc_array = $cc;
326 }
Eric Barnes6113f542010-12-29 13:36:12 -0500327
Greg Akera769deb2010-11-10 15:47:29 -0600328 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 }
Barry Mienydd671972010-10-04 16:33:58 +0200330
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 // --------------------------------------------------------------------
332
333 /**
334 * Set BCC
335 *
336 * @access public
337 * @param string
338 * @param string
339 * @return void
340 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000341 public function bcc($bcc, $limit = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 {
343 if ($limit != '' && is_numeric($limit))
344 {
345 $this->bcc_batch_mode = TRUE;
346 $this->bcc_batch_size = $limit;
347 }
348
349 $bcc = $this->_str_to_array($bcc);
350 $bcc = $this->clean_email($bcc);
351
352 if ($this->validate)
353 {
354 $this->validate_email($bcc);
355 }
356
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200357 if ($this->_get_protocol() === 'smtp' OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size))
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 {
359 $this->_bcc_array = $bcc;
360 }
361 else
362 {
363 $this->_set_header('Bcc', implode(", ", $bcc));
364 }
Eric Barnes6113f542010-12-29 13:36:12 -0500365
Greg Akera769deb2010-11-10 15:47:29 -0600366 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 }
Barry Mienydd671972010-10-04 16:33:58 +0200368
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 // --------------------------------------------------------------------
370
371 /**
372 * Set Email Subject
373 *
374 * @access public
375 * @param string
376 * @return void
377 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000378 public function subject($subject)
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 {
380 $subject = $this->_prep_q_encoding($subject);
381 $this->_set_header('Subject', $subject);
Greg Akera769deb2010-11-10 15:47:29 -0600382 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 }
Barry Mienydd671972010-10-04 16:33:58 +0200384
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 // --------------------------------------------------------------------
386
387 /**
388 * Set Body
389 *
390 * @access public
391 * @param string
392 * @return void
393 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000394 public function message($body)
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 {
diegorivera33c32802011-10-19 02:56:15 -0200396 $this->_body = rtrim(str_replace("\r", "", $body));
397
Andrey Andreevaf728622011-10-20 10:11:59 +0300398 /* strip slashes only if magic quotes is ON
399 if we do it with magic quotes OFF, it strips real, user-inputted chars.
400
401 NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
402 it will probably not exist in future versions at all.
403 */
404 if ( ! is_php('5.4') && get_magic_quotes_gpc())
diegorivera9fca6152011-10-19 11:18:45 -0200405 {
diegorivera33c32802011-10-19 02:56:15 -0200406 $this->_body = stripslashes($this->_body);
diegorivera9fca6152011-10-19 11:18:45 -0200407 }
diegorivera33c32802011-10-19 02:56:15 -0200408
Greg Akera769deb2010-11-10 15:47:29 -0600409 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 }
Barry Mienydd671972010-10-04 16:33:58 +0200411
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 // --------------------------------------------------------------------
413
414 /**
415 * Assign file attachments
416 *
417 * @access public
418 * @param string
419 * @return void
420 */
trit10eb14d2011-11-23 15:48:21 -0500421 public function attach($filename, $disposition = '', $newname = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 {
trit151fc682011-11-23 07:30:06 -0500423 $this->_attach_name[] = array($filename, $newname);
Phil Sturgeon0aaf42b2011-08-10 08:06:37 -0600424 $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
tritd5269982011-11-23 17:22:44 -0500425 $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters
Greg Akera769deb2010-11-10 15:47:29 -0600426 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 }
428
429 // --------------------------------------------------------------------
430
431 /**
432 * Add a Header Item
433 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600434 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 * @param string
436 * @param string
437 * @return void
438 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600439 protected function _set_header($header, $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
441 $this->_headers[$header] = $value;
442 }
Barry Mienydd671972010-10-04 16:33:58 +0200443
Derek Allard2067d1a2008-11-13 22:59:24 +0000444 // --------------------------------------------------------------------
445
446 /**
447 * Convert a String to an Array
448 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600449 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 * @param string
451 * @return array
452 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600453 protected function _str_to_array($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 {
455 if ( ! is_array($email))
456 {
457 if (strpos($email, ',') !== FALSE)
458 {
459 $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY);
460 }
461 else
462 {
463 $email = trim($email);
464 settype($email, "array");
465 }
466 }
467 return $email;
468 }
Barry Mienydd671972010-10-04 16:33:58 +0200469
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 // --------------------------------------------------------------------
471
472 /**
473 * Set Multipart Value
474 *
475 * @access public
476 * @param string
477 * @return void
478 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000479 public function set_alt_message($str = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 {
Dan Horrigand0ddeaf2011-08-21 09:07:27 -0400481 $this->alt_message = (string) $str;
Greg Akera769deb2010-11-10 15:47:29 -0600482 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 }
Barry Mienydd671972010-10-04 16:33:58 +0200484
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 // --------------------------------------------------------------------
486
487 /**
488 * Set Mailtype
489 *
490 * @access public
491 * @param string
492 * @return void
493 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000494 public function set_mailtype($type = 'text')
Derek Allard2067d1a2008-11-13 22:59:24 +0000495 {
496 $this->mailtype = ($type == 'html') ? 'html' : 'text';
Greg Akera769deb2010-11-10 15:47:29 -0600497 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 }
Barry Mienydd671972010-10-04 16:33:58 +0200499
Derek Allard2067d1a2008-11-13 22:59:24 +0000500 // --------------------------------------------------------------------
501
502 /**
503 * Set Wordwrap
504 *
505 * @access public
Dan Horrigan628e6602011-08-21 09:08:31 -0400506 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000507 * @return void
508 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000509 public function set_wordwrap($wordwrap = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 {
Dan Horrigan628e6602011-08-21 09:08:31 -0400511 $this->wordwrap = (bool) $wordwrap;
Greg Akera769deb2010-11-10 15:47:29 -0600512 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 }
Barry Mienydd671972010-10-04 16:33:58 +0200514
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 // --------------------------------------------------------------------
516
517 /**
518 * Set Protocol
519 *
520 * @access public
521 * @param string
522 * @return void
523 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000524 public function set_protocol($protocol = 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000525 {
526 $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol);
Greg Akera769deb2010-11-10 15:47:29 -0600527 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000528 }
Barry Mienydd671972010-10-04 16:33:58 +0200529
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 // --------------------------------------------------------------------
531
532 /**
533 * Set Priority
534 *
535 * @access public
536 * @param integer
537 * @return void
538 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000539 public function set_priority($n = 3)
Derek Allard2067d1a2008-11-13 22:59:24 +0000540 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200541 if ( ! is_numeric($n) OR $n < 1 OR $n > 5)
Derek Allard2067d1a2008-11-13 22:59:24 +0000542 {
543 $this->priority = 3;
544 return;
545 }
546
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200547 $this->priority = (int) $n;
Greg Akera769deb2010-11-10 15:47:29 -0600548 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 }
Barry Mienydd671972010-10-04 16:33:58 +0200550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 // --------------------------------------------------------------------
552
553 /**
554 * Set Newline Character
555 *
556 * @access public
557 * @param string
558 * @return void
559 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000560 public function set_newline($newline = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200562 $this->newline = in_array($newline, array("\n", "\r\n", "\r")) ? $newline : "\n";
Greg Akera769deb2010-11-10 15:47:29 -0600563 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000564 }
Barry Mienydd671972010-10-04 16:33:58 +0200565
Derek Allard2067d1a2008-11-13 22:59:24 +0000566 // --------------------------------------------------------------------
567
568 /**
569 * Set CRLF
570 *
571 * @access public
572 * @param string
573 * @return void
574 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000575 public function set_crlf($crlf = "\n")
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200577 $this->crlf = ($crlf !== "\n" AND $crlf !== "\r\n" AND $crlf !== "\r") ? "\n" : $crlf;
Greg Akera769deb2010-11-10 15:47:29 -0600578 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000579 }
Barry Mienydd671972010-10-04 16:33:58 +0200580
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 // --------------------------------------------------------------------
582
583 /**
584 * Set Message Boundary
585 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600586 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000587 * @return void
588 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600589 protected function _set_boundaries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000590 {
591 $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative
592 $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary
593 }
Barry Mienydd671972010-10-04 16:33:58 +0200594
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 // --------------------------------------------------------------------
596
597 /**
598 * Get the Message ID
599 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600600 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000601 * @return string
602 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600603 protected function _get_message_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200605 $from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000606
Derek Jones37f4b9c2011-07-01 17:56:50 -0500607 return "<".uniqid('').strstr($from, '@').">";
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 }
Barry Mienydd671972010-10-04 16:33:58 +0200609
Derek Allard2067d1a2008-11-13 22:59:24 +0000610 // --------------------------------------------------------------------
611
612 /**
613 * Get Mail Protocol
614 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600615 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 * @param bool
617 * @return string
618 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600619 protected function _get_protocol($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000620 {
621 $this->protocol = strtolower($this->protocol);
622 $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
623
624 if ($return == TRUE)
625 {
626 return $this->protocol;
627 }
628 }
Barry Mienydd671972010-10-04 16:33:58 +0200629
Derek Allard2067d1a2008-11-13 22:59:24 +0000630 // --------------------------------------------------------------------
631
632 /**
633 * Get Mail Encoding
634 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600635 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000636 * @param bool
637 * @return string
638 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600639 protected function _get_encoding($return = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000640 {
641 $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
642
643 foreach ($this->_base_charsets as $charset)
644 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200645 if (strncmp($charset, $this->charset, strlen($charset)) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000646 {
647 $this->_encoding = '7bit';
648 }
649 }
650
651 if ($return == TRUE)
652 {
653 return $this->_encoding;
654 }
655 }
656
657 // --------------------------------------------------------------------
658
659 /**
660 * Get content type (text/html/attachment)
661 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600662 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000663 * @return string
664 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600665 protected function _get_content_type()
Derek Allard2067d1a2008-11-13 22:59:24 +0000666 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200667 if ($this->mailtype === 'html' && count($this->_attach_name) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000668 {
669 return 'html';
670 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200671 elseif ($this->mailtype === 'html' && count($this->_attach_name) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000672 {
673 return 'html-attach';
674 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200675 elseif ($this->mailtype === 'text' && count($this->_attach_name) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000676 {
677 return 'plain-attach';
678 }
679 else
680 {
681 return 'plain';
682 }
683 }
Barry Mienydd671972010-10-04 16:33:58 +0200684
Derek Allard2067d1a2008-11-13 22:59:24 +0000685 // --------------------------------------------------------------------
686
687 /**
688 * Set RFC 822 Date
689 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600690 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000691 * @return string
692 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600693 protected function _set_date()
Derek Allard2067d1a2008-11-13 22:59:24 +0000694 {
695 $timezone = date("Z");
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200696 $operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+';
Derek Allard2067d1a2008-11-13 22:59:24 +0000697 $timezone = abs($timezone);
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200698 $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
Derek Allard2067d1a2008-11-13 22:59:24 +0000699
700 return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone);
701 }
Barry Mienydd671972010-10-04 16:33:58 +0200702
Derek Allard2067d1a2008-11-13 22:59:24 +0000703 // --------------------------------------------------------------------
704
705 /**
706 * Mime message
707 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600708 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000709 * @return string
710 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600711 protected function _get_mime_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000712 {
713 return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format.";
714 }
Barry Mienydd671972010-10-04 16:33:58 +0200715
Derek Allard2067d1a2008-11-13 22:59:24 +0000716 // --------------------------------------------------------------------
717
718 /**
719 * Validate Email Address
720 *
721 * @access public
722 * @param string
723 * @return bool
724 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000725 public function validate_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000726 {
727 if ( ! is_array($email))
728 {
patworkb0707982011-04-08 15:10:05 +0200729 $this->_set_error_message('lang:email_must_be_array');
Derek Allard2067d1a2008-11-13 22:59:24 +0000730 return FALSE;
731 }
732
733 foreach ($email as $val)
734 {
735 if ( ! $this->valid_email($val))
736 {
patworkb0707982011-04-08 15:10:05 +0200737 $this->_set_error_message('lang:email_invalid_address', $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000738 return FALSE;
739 }
740 }
741
742 return TRUE;
743 }
Barry Mienydd671972010-10-04 16:33:58 +0200744
Derek Allard2067d1a2008-11-13 22:59:24 +0000745 // --------------------------------------------------------------------
746
747 /**
748 * Email Validation
749 *
750 * @access public
751 * @param string
752 * @return bool
753 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000754 public function valid_email($address)
Derek Allard2067d1a2008-11-13 22:59:24 +0000755 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200756 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 +0000757 }
Barry Mienydd671972010-10-04 16:33:58 +0200758
Derek Allard2067d1a2008-11-13 22:59:24 +0000759 // --------------------------------------------------------------------
760
761 /**
762 * Clean Extended Email Address: Joe Smith <joe@smith.com>
763 *
764 * @access public
765 * @param string
766 * @return string
767 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000768 public function clean_email($email)
Derek Allard2067d1a2008-11-13 22:59:24 +0000769 {
770 if ( ! is_array($email))
771 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200772 return (preg_match('/\<(.*)\>/', $email, $match)) ? $match[1] : $email;
Derek Allard2067d1a2008-11-13 22:59:24 +0000773 }
774
775 $clean_email = array();
776
777 foreach ($email as $addy)
778 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200779 $clean_email[] = (preg_match( '/\<(.*)\>/', $addy, $match)) ? $match[1] : $addy;
Derek Allard2067d1a2008-11-13 22:59:24 +0000780 }
781
782 return $clean_email;
783 }
Barry Mienydd671972010-10-04 16:33:58 +0200784
Derek Allard2067d1a2008-11-13 22:59:24 +0000785 // --------------------------------------------------------------------
786
787 /**
788 * Build alternative plain text message
789 *
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000790 * This public function provides the raw message for use
Derek Allard2067d1a2008-11-13 22:59:24 +0000791 * in plain-text headers of HTML-formatted emails.
792 * If the user hasn't specified his own alternative message
793 * it creates one by stripping the HTML
794 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600795 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000796 * @return string
797 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600798 protected function _get_alt_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000799 {
800 if ($this->alt_message != "")
801 {
802 return $this->word_wrap($this->alt_message, '76');
803 }
804
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200805 $body = (preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match)) ? $match[1] : $this->_body;
806 $body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000807
808 for ($i = 20; $i >= 3; $i--)
809 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200810 $body = str_replace(str_repeat("\n", $i), "\n\n", $body);
Derek Allard2067d1a2008-11-13 22:59:24 +0000811 }
812
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200813 return $this->word_wrap($body, 76);
Derek Allard2067d1a2008-11-13 22:59:24 +0000814 }
Barry Mienydd671972010-10-04 16:33:58 +0200815
Derek Allard2067d1a2008-11-13 22:59:24 +0000816 // --------------------------------------------------------------------
817
818 /**
819 * Word Wrap
820 *
821 * @access public
822 * @param string
823 * @param integer
824 * @return string
825 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000826 public function word_wrap($str, $charlim = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000827 {
828 // Se the character limit
829 if ($charlim == '')
830 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200831 $charlim = ($this->wrapchars == "") ? 76 : $this->wrapchars;
Derek Allard2067d1a2008-11-13 22:59:24 +0000832 }
833
834 // Reduce multiple spaces
835 $str = preg_replace("| +|", " ", $str);
836
837 // Standardize newlines
838 if (strpos($str, "\r") !== FALSE)
839 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200840 $str = str_replace(array("\r\n", "\r"), "\n", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000841 }
842
843 // If the current word is surrounded by {unwrap} tags we'll
844 // strip the entire chunk and replace it with a marker.
845 $unwrap = array();
846 if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
847 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200848 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000849 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200850 $unwrap[] = $matches[1][$i];
851 $str = str_replace($matches[1][$i], "{{unwrapped".$i."}}", $str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000852 }
853 }
854
Phil Sturgeona0f980e2011-01-13 10:59:12 +0000855 // Use PHP's native public function to do the initial wordwrap.
Derek Allard2067d1a2008-11-13 22:59:24 +0000856 // We set the cut flag to FALSE so that any individual words that are
Derek Jones37f4b9c2011-07-01 17:56:50 -0500857 // too long get left alone. In the next step we'll deal with them.
Derek Allard2067d1a2008-11-13 22:59:24 +0000858 $str = wordwrap($str, $charlim, "\n", FALSE);
859
860 // Split the string into individual lines of text and cycle through them
861 $output = "";
862 foreach (explode("\n", $str) as $line)
863 {
864 // Is the line within the allowed character count?
865 // If so we'll join it to the output and continue
866 if (strlen($line) <= $charlim)
867 {
868 $output .= $line.$this->newline;
869 continue;
870 }
871
872 $temp = '';
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200873 do
Derek Allard2067d1a2008-11-13 22:59:24 +0000874 {
875 // If the over-length word is a URL we won't wrap it
876 if (preg_match("!\[url.+\]|://|wwww.!", $line))
877 {
878 break;
879 }
880
881 // Trim the word down
882 $temp .= substr($line, 0, $charlim-1);
883 $line = substr($line, $charlim-1);
884 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200885 while (strlen($line) > $charlim);
Derek Allard2067d1a2008-11-13 22:59:24 +0000886
887 // If $temp contains data it means we had to split up an over-length
888 // word into smaller chunks so we'll add it back to our current line
889 if ($temp != '')
890 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200891 $output .= $temp.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000892 }
893
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200894 $output .= $line.$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +0000895 }
896
897 // Put our markers back
898 if (count($unwrap) > 0)
899 {
900 foreach ($unwrap as $key => $val)
901 {
902 $output = str_replace("{{unwrapped".$key."}}", $val, $output);
903 }
904 }
905
906 return $output;
907 }
Barry Mienydd671972010-10-04 16:33:58 +0200908
Derek Allard2067d1a2008-11-13 22:59:24 +0000909 // --------------------------------------------------------------------
910
911 /**
912 * Build final headers
913 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600914 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000915 * @param string
916 * @return string
917 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600918 protected function _build_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +0000919 {
920 $this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
921 $this->_set_header('X-Mailer', $this->useragent);
922 $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]);
923 $this->_set_header('Message-ID', $this->_get_message_id());
924 $this->_set_header('Mime-Version', '1.0');
925 }
Barry Mienydd671972010-10-04 16:33:58 +0200926
Derek Allard2067d1a2008-11-13 22:59:24 +0000927 // --------------------------------------------------------------------
928
929 /**
930 * Write Headers as a string
931 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600932 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000933 * @return void
934 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600935 protected function _write_headers()
Derek Allard2067d1a2008-11-13 22:59:24 +0000936 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200937 if ($this->protocol === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000938 {
939 $this->_subject = $this->_headers['Subject'];
940 unset($this->_headers['Subject']);
941 }
942
943 reset($this->_headers);
944 $this->_header_str = "";
945
Pascal Kriete14287f32011-02-14 13:39:34 -0500946 foreach ($this->_headers as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000947 {
948 $val = trim($val);
949
950 if ($val != "")
951 {
952 $this->_header_str .= $key.": ".$val.$this->newline;
953 }
954 }
955
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200956 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +0000957 {
Derek Jones1d890882009-02-10 20:32:14 +0000958 $this->_header_str = rtrim($this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +0000959 }
960 }
Barry Mienydd671972010-10-04 16:33:58 +0200961
Derek Allard2067d1a2008-11-13 22:59:24 +0000962 // --------------------------------------------------------------------
963
964 /**
965 * Build Final Body and attachments
966 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600967 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +0000968 * @return void
969 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -0600970 protected function _build_message()
Derek Allard2067d1a2008-11-13 22:59:24 +0000971 {
Andrey Andreevb71e06b2011-12-22 19:22:50 +0200972 if ($this->wordwrap === TRUE AND $this->mailtype !== 'html')
Derek Allard2067d1a2008-11-13 22:59:24 +0000973 {
974 $this->_body = $this->word_wrap($this->_body);
975 }
976
977 $this->_set_boundaries();
978 $this->_write_headers();
979
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200980 $hdr = ($this->_get_protocol() === 'mail') ? $this->newline : '';
Brandon Jones485d7412010-11-09 16:38:17 -0500981 $body = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000982
983 switch ($this->_get_content_type())
984 {
985 case 'plain' :
986
Andrey Andreev1bd3d882011-12-22 15:38:20 +0200987 $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline
988 . "Content-Transfer-Encoding: " . $this->_get_encoding();
Derek Allard2067d1a2008-11-13 22:59:24 +0000989
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;
993 $this->_finalbody = $this->_body;
Derek Allard2067d1a2008-11-13 22:59:24 +0000994 }
Brandon Jones485d7412010-11-09 16:38:17 -0500995 else
996 {
997 $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body;
998 }
Eric Barnes6113f542010-12-29 13:36:12 -0500999
Derek Allard2067d1a2008-11-13 22:59:24 +00001000 return;
1001
Derek Allard2067d1a2008-11-13 22:59:24 +00001002 case 'html' :
1003
1004 if ($this->send_multipart === FALSE)
1005 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001006 $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline
1007 . "Content-Transfer-Encoding: quoted-printable";
Derek Allard2067d1a2008-11-13 22:59:24 +00001008 }
1009 else
1010 {
Derek Jonesa45e7612009-02-10 18:33:01 +00001011 $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001012
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001013 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1014 . "--" . $this->_alt_boundary . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001015
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001016 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1017 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
1018 . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001019
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001020 . "Content-Type: text/html; charset=" . $this->charset . $this->newline
1021 . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001022 }
Eric Barnes6113f542010-12-29 13:36:12 -05001023
Brandon Jones485d7412010-11-09 16:38:17 -05001024 $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -05001025
1026
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001027 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001028 {
1029 $this->_header_str .= $hdr;
Brandon Jones485d7412010-11-09 16:38:17 -05001030 }
1031 else
1032 {
1033 $this->_finalbody = $hdr . $this->_finalbody;
Derek Allard2067d1a2008-11-13 22:59:24 +00001034 }
1035
Derek Allard2067d1a2008-11-13 22:59:24 +00001036
1037 if ($this->send_multipart !== FALSE)
1038 {
Brandon Jones485d7412010-11-09 16:38:17 -05001039 $this->_finalbody .= "--" . $this->_alt_boundary . "--";
Derek Allard2067d1a2008-11-13 22:59:24 +00001040 }
1041
Derek Allard2067d1a2008-11-13 22:59:24 +00001042 return;
1043
Derek Allard2067d1a2008-11-13 22:59:24 +00001044 case 'plain-attach' :
1045
Derek Jonesa45e7612009-02-10 18:33:01 +00001046 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001047
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001048 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001049 {
1050 $this->_header_str .= $hdr;
Eric Barnes6113f542010-12-29 13:36:12 -05001051 }
1052
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001053 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1054 . "--" . $this->_atc_boundary . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001055
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001056 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1057 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
Derek Allard2067d1a2008-11-13 22:59:24 +00001058
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001059 . $this->_body . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001060
1061 break;
1062 case 'html-attach' :
1063
Derek Jonesa45e7612009-02-10 18:33:01 +00001064 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline;
Eric Barnes6113f542010-12-29 13:36:12 -05001065
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001066 if ($this->_get_protocol() === 'mail')
Derek Allard2067d1a2008-11-13 22:59:24 +00001067 {
1068 $this->_header_str .= $hdr;
Derek Allard2067d1a2008-11-13 22:59:24 +00001069 }
1070
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001071 $body .= $this->_get_mime_message() . $this->newline . $this->newline
1072 . "--" . $this->_atc_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001073
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001074 . "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline
1075 . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001076
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001077 . "Content-Type: text/plain; charset=" . $this->charset . $this->newline
1078 . "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline
1079 . $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001080
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001081 . "Content-Type: text/html; charset=" . $this->charset . $this->newline
1082 . "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline
Brandon Jones485d7412010-11-09 16:38:17 -05001083
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001084 . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline
1085 . "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001086
1087 break;
1088 }
1089
1090 $attachment = array();
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001091 for ($i = 0, $c = count($this->_attach_name), $z = 0; $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001092 {
tritbc4ac992011-11-23 07:19:41 -05001093 $filename = $this->_attach_name[$i][0];
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001094 $basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1];
Derek Allard2067d1a2008-11-13 22:59:24 +00001095 $ctype = $this->_attach_type[$i];
1096
tritbc4ac992011-11-23 07:19:41 -05001097 if ( ! file_exists($filename))
Derek Allard2067d1a2008-11-13 22:59:24 +00001098 {
tritbc4ac992011-11-23 07:19:41 -05001099 $this->_set_error_message('lang:email_attachment_missing', $filename);
Derek Allard2067d1a2008-11-13 22:59:24 +00001100 return FALSE;
1101 }
1102
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001103 $attachment[$z++] = "--".$this->_atc_boundary.$this->newline
1104 . "Content-type: ".$ctype."; "
1105 . "name=\"".$basename."\"".$this->newline
1106 . "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline
1107 . "Content-Transfer-Encoding: base64".$this->newline;
Derek Allard2067d1a2008-11-13 22:59:24 +00001108
tritbc4ac992011-11-23 07:19:41 -05001109 $file = filesize($filename) +1;
Derek Allard2067d1a2008-11-13 22:59:24 +00001110
tritbc4ac992011-11-23 07:19:41 -05001111 if ( ! $fp = fopen($filename, FOPEN_READ))
Derek Allard2067d1a2008-11-13 22:59:24 +00001112 {
tritbc4ac992011-11-23 07:19:41 -05001113 $this->_set_error_message('lang:email_attachment_unreadable', $filename);
Derek Allard2067d1a2008-11-13 22:59:24 +00001114 return FALSE;
1115 }
1116
1117 $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file)));
1118 fclose($fp);
1119 }
1120
Brandon Jones485d7412010-11-09 16:38:17 -05001121 $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001122 $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr . $body;
Derek Allard2067d1a2008-11-13 22:59:24 +00001123 return;
1124 }
Barry Mienydd671972010-10-04 16:33:58 +02001125
Derek Allard2067d1a2008-11-13 22:59:24 +00001126 // --------------------------------------------------------------------
1127
1128 /**
1129 * Prep Quoted Printable
1130 *
1131 * Prepares string for Quoted-Printable Content-Transfer-Encoding
1132 * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
1133 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001134 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001135 * @param string
1136 * @param integer
1137 * @return string
1138 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001139 protected function _prep_quoted_printable($str, $charlim = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001140 {
1141 // Set the character limit
1142 // Don't allow over 76, as that will make servers and MUAs barf
1143 // all over quoted-printable data
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001144 if ($charlim == '' OR $charlim > 76)
Derek Allard2067d1a2008-11-13 22:59:24 +00001145 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001146 $charlim = 76;
Derek Allard2067d1a2008-11-13 22:59:24 +00001147 }
1148
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001149 // Reduce multiple spaces & remove nulls
1150 $str = preg_replace(array("| +|", '/\x00+/'), array(' ', ''), $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001151
1152 // Standardize newlines
1153 if (strpos($str, "\r") !== FALSE)
1154 {
1155 $str = str_replace(array("\r\n", "\r"), "\n", $str);
1156 }
1157
1158 // We are intentionally wrapping so mail servers will encode characters
1159 // properly and MUAs will behave, so {unwrap} must go!
1160 $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);
1161
Derek Allard2067d1a2008-11-13 22:59:24 +00001162 $escape = '=';
1163 $output = '';
1164
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001165 foreach (explode("\n", $str) as $line)
Derek Allard2067d1a2008-11-13 22:59:24 +00001166 {
1167 $length = strlen($line);
1168 $temp = '';
1169
1170 // Loop through each character in the line to add soft-wrap
1171 // characters at the end of a line " =\r\n" and add the newly
1172 // processed line(s) to the output (see comment on $crlf class property)
1173 for ($i = 0; $i < $length; $i++)
1174 {
1175 // Grab the next character
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001176 $char = $line[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001177 $ascii = ord($char);
1178
1179 // Convert spaces and tabs but only if it's the end of the line
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001180 if ($i === ($length - 1) && ($ascii === 32 OR $ascii === 9))
Derek Allard2067d1a2008-11-13 22:59:24 +00001181 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001182 $char = $escape.sprintf('%02s', dechex($ascii));
Derek Allard2067d1a2008-11-13 22:59:24 +00001183 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001184 elseif ($ascii === 61) // encode = signs
Derek Allard2067d1a2008-11-13 22:59:24 +00001185 {
Derek Jones37f4b9c2011-07-01 17:56:50 -05001186 $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D
Derek Allard2067d1a2008-11-13 22:59:24 +00001187 }
1188
1189 // If we're at the character limit, add the line to the output,
1190 // reset our temp variable, and keep on chuggin'
1191 if ((strlen($temp) + strlen($char)) >= $charlim)
1192 {
1193 $output .= $temp.$escape.$this->crlf;
1194 $temp = '';
1195 }
1196
1197 // Add the character to our temporary line
1198 $temp .= $char;
1199 }
1200
1201 // Add our completed line to the output
1202 $output .= $temp.$this->crlf;
1203 }
1204
1205 // get rid of extra CRLF tacked onto the end
1206 $output = substr($output, 0, strlen($this->crlf) * -1);
1207
1208 return $output;
1209 }
1210
1211 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001212
Derek Allard2067d1a2008-11-13 22:59:24 +00001213 /**
1214 * Prep Q Encoding
1215 *
Derek Jones37f4b9c2011-07-01 17:56:50 -05001216 * Performs "Q Encoding" on a string for use in email headers. It's related
Derek Allard2067d1a2008-11-13 22:59:24 +00001217 * but not identical to quoted-printable, so it has its own method
1218 *
1219 * @access public
1220 * @param str
1221 * @param bool // set to TRUE for processing From: headers
1222 * @return str
1223 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001224 protected function _prep_q_encoding($str, $from = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001225 {
1226 $str = str_replace(array("\r", "\n"), array('', ''), $str);
1227
1228 // Line length must not exceed 76 characters, so we adjust for
1229 // a space, 7 extra characters =??Q??=, and the charset that we will add to each line
1230 $limit = 75 - 7 - strlen($this->charset);
1231
1232 // these special characters must be converted too
1233 $convert = array('_', '=', '?');
1234
1235 if ($from === TRUE)
1236 {
1237 $convert[] = ',';
1238 $convert[] = ';';
1239 }
1240
1241 $output = '';
1242 $temp = '';
1243
1244 for ($i = 0, $length = strlen($str); $i < $length; $i++)
1245 {
1246 // Grab the next character
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001247 $char = $str[$i];
Derek Allard2067d1a2008-11-13 22:59:24 +00001248 $ascii = ord($char);
1249
1250 // convert ALL non-printable ASCII characters and our specials
1251 if ($ascii < 32 OR $ascii > 126 OR in_array($char, $convert))
1252 {
1253 $char = '='.dechex($ascii);
1254 }
1255
1256 // handle regular spaces a bit more compactly than =20
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001257 if ($ascii === 32)
Derek Allard2067d1a2008-11-13 22:59:24 +00001258 {
1259 $char = '_';
1260 }
1261
1262 // If we're at the character limit, add the line to the output,
1263 // reset our temp variable, and keep on chuggin'
1264 if ((strlen($temp) + strlen($char)) >= $limit)
1265 {
1266 $output .= $temp.$this->crlf;
1267 $temp = '';
1268 }
1269
1270 // Add the character to our temporary line
1271 $temp .= $char;
1272 }
1273
1274 $str = $output.$temp;
1275
1276 // wrap each line with the shebang, charset, and transfer encoding
1277 // the preceding space on successive lines is required for header "folding"
1278 $str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str));
1279
1280 return $str;
1281 }
1282
1283 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001284
Derek Allard2067d1a2008-11-13 22:59:24 +00001285 /**
1286 * Send Email
1287 *
1288 * @access public
1289 * @return bool
1290 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001291 public function send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001292 {
1293 if ($this->_replyto_flag == FALSE)
1294 {
1295 $this->reply_to($this->_headers['From']);
1296 }
1297
Derek Jones37f4b9c2011-07-01 17:56:50 -05001298 if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND
Derek Allard2067d1a2008-11-13 22:59:24 +00001299 ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
1300 ( ! isset($this->_headers['Cc'])))
1301 {
patworkb0707982011-04-08 15:10:05 +02001302 $this->_set_error_message('lang:email_no_recipients');
Derek Allard2067d1a2008-11-13 22:59:24 +00001303 return FALSE;
1304 }
1305
1306 $this->_build_headers();
1307
Andrey Andreevb71e06b2011-12-22 19:22:50 +02001308 if ($this->bcc_batch_mode AND count($this->_bcc_array) > $this->bcc_batch_size)
Derek Allard2067d1a2008-11-13 22:59:24 +00001309 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001310 return $this->batch_bcc_send();
Derek Allard2067d1a2008-11-13 22:59:24 +00001311 }
1312
1313 $this->_build_message();
1314
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001315 return $this->_spool_email();
Derek Allard2067d1a2008-11-13 22:59:24 +00001316 }
Barry Mienydd671972010-10-04 16:33:58 +02001317
Derek Allard2067d1a2008-11-13 22:59:24 +00001318 // --------------------------------------------------------------------
1319
1320 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -05001321 * Batch Bcc Send. Sends groups of BCCs in batches
Derek Allard2067d1a2008-11-13 22:59:24 +00001322 *
1323 * @access public
1324 * @return bool
1325 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001326 public function batch_bcc_send()
Derek Allard2067d1a2008-11-13 22:59:24 +00001327 {
1328 $float = $this->bcc_batch_size -1;
1329
1330 $set = "";
1331
1332 $chunk = array();
1333
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001334 for ($i = 0, $c = count($this->_bcc_array); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001335 {
1336 if (isset($this->_bcc_array[$i]))
1337 {
1338 $set .= ", ".$this->_bcc_array[$i];
1339 }
1340
1341 if ($i == $float)
1342 {
1343 $chunk[] = substr($set, 1);
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001344 $float += $this->bcc_batch_size;
Derek Allard2067d1a2008-11-13 22:59:24 +00001345 $set = "";
1346 }
1347
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001348 if ($i === $c-1)
Derek Allard2067d1a2008-11-13 22:59:24 +00001349 {
1350 $chunk[] = substr($set, 1);
1351 }
1352 }
1353
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001354 for ($i = 0, $c = count($chunk); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001355 {
1356 unset($this->_headers['Bcc']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001357
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001358 $bcc = $this->clean_email($this->_str_to_array($chunk[$i]));
Derek Allard2067d1a2008-11-13 22:59:24 +00001359
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001360 if ($this->protocol !== 'smtp')
Derek Allard2067d1a2008-11-13 22:59:24 +00001361 {
1362 $this->_set_header('Bcc', implode(", ", $bcc));
1363 }
1364 else
1365 {
1366 $this->_bcc_array = $bcc;
1367 }
1368
1369 $this->_build_message();
1370 $this->_spool_email();
1371 }
1372 }
Barry Mienydd671972010-10-04 16:33:58 +02001373
Derek Allard2067d1a2008-11-13 22:59:24 +00001374 // --------------------------------------------------------------------
1375
1376 /**
1377 * Unwrap special elements
1378 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001379 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001380 * @return void
1381 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001382 protected function _unwrap_specials()
Derek Allard2067d1a2008-11-13 22:59:24 +00001383 {
1384 $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
1385 }
Barry Mienydd671972010-10-04 16:33:58 +02001386
Derek Allard2067d1a2008-11-13 22:59:24 +00001387 // --------------------------------------------------------------------
1388
1389 /**
1390 * Strip line-breaks via callback
1391 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001392 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001393 * @return string
1394 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001395 protected function _remove_nl_callback($matches)
Derek Allard2067d1a2008-11-13 22:59:24 +00001396 {
1397 if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
1398 {
1399 $matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]);
1400 }
1401
1402 return $matches[1];
1403 }
Barry Mienydd671972010-10-04 16:33:58 +02001404
Derek Allard2067d1a2008-11-13 22:59:24 +00001405 // --------------------------------------------------------------------
1406
1407 /**
1408 * Spool mail to the mail server
1409 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001410 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001411 * @return bool
1412 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001413 protected function _spool_email()
Derek Allard2067d1a2008-11-13 22:59:24 +00001414 {
1415 $this->_unwrap_specials();
1416
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001417 $method = '_send_with_' . $this->_get_protocol();
1418 if ( ! $this->$method())
Derek Allard2067d1a2008-11-13 22:59:24 +00001419 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001420 $this->_set_error_message('lang:email_send_failure_' . ($this->_get_protocol() === 'mail' ? 'phpmail' : $this->_get_protocol()));
Derek Allard2067d1a2008-11-13 22:59:24 +00001421 }
1422
patworkb0707982011-04-08 15:10:05 +02001423 $this->_set_error_message('lang:email_sent', $this->_get_protocol());
Derek Allard2067d1a2008-11-13 22:59:24 +00001424 return TRUE;
1425 }
Barry Mienydd671972010-10-04 16:33:58 +02001426
Derek Allard2067d1a2008-11-13 22:59:24 +00001427 // --------------------------------------------------------------------
1428
1429 /**
1430 * Send using mail()
1431 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001432 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001433 * @return bool
1434 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001435 protected function _send_with_mail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001436 {
1437 if ($this->_safe_mode == TRUE)
1438 {
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001439 return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001440 }
1441 else
1442 {
1443 // most documentation of sendmail using the "-f" flag lacks a space after it, however
1444 // we've encountered servers that seem to require it to be in place.
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001445 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 +00001446 }
1447 }
Barry Mienydd671972010-10-04 16:33:58 +02001448
Derek Allard2067d1a2008-11-13 22:59:24 +00001449 // --------------------------------------------------------------------
1450
1451 /**
1452 * Send using Sendmail
1453 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001454 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001455 * @return bool
1456 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001457 protected function _send_with_sendmail()
Derek Allard2067d1a2008-11-13 22:59:24 +00001458 {
1459 $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
1460
Derek Jones4cefaa42009-04-29 19:13:56 +00001461 if ($fp === FALSE OR $fp === NULL)
1462 {
1463 // server probably has popen disabled, so nothing we can do to get a verbose error.
1464 return FALSE;
1465 }
Derek Jones71141ce2010-03-02 16:41:20 -06001466
Derek Jonesc630bcf2008-11-17 21:09:45 +00001467 fputs($fp, $this->_header_str);
1468 fputs($fp, $this->_finalbody);
1469
Barry Mienydd671972010-10-04 16:33:58 +02001470 $status = pclose($fp);
Eric Barnes6113f542010-12-29 13:36:12 -05001471
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001472 if ($status !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001473 {
patworkb0707982011-04-08 15:10:05 +02001474 $this->_set_error_message('lang:email_exit_status', $status);
1475 $this->_set_error_message('lang:email_no_socket');
Derek Allard2067d1a2008-11-13 22:59:24 +00001476 return FALSE;
1477 }
1478
Derek Allard2067d1a2008-11-13 22:59:24 +00001479 return TRUE;
1480 }
Barry Mienydd671972010-10-04 16:33:58 +02001481
Derek Allard2067d1a2008-11-13 22:59:24 +00001482 // --------------------------------------------------------------------
1483
1484 /**
1485 * Send using SMTP
1486 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001487 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001488 * @return bool
1489 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001490 protected function _send_with_smtp()
Derek Allard2067d1a2008-11-13 22:59:24 +00001491 {
1492 if ($this->smtp_host == '')
1493 {
patworkb0707982011-04-08 15:10:05 +02001494 $this->_set_error_message('lang:email_no_hostname');
Derek Allard2067d1a2008-11-13 22:59:24 +00001495 return FALSE;
1496 }
1497
1498 $this->_smtp_connect();
1499 $this->_smtp_authenticate();
1500
1501 $this->_send_command('from', $this->clean_email($this->_headers['From']));
1502
Pascal Kriete14287f32011-02-14 13:39:34 -05001503 foreach ($this->_recipients as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001504 {
1505 $this->_send_command('to', $val);
1506 }
1507
1508 if (count($this->_cc_array) > 0)
1509 {
Pascal Kriete14287f32011-02-14 13:39:34 -05001510 foreach ($this->_cc_array as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001511 {
1512 if ($val != "")
1513 {
1514 $this->_send_command('to', $val);
1515 }
1516 }
1517 }
1518
1519 if (count($this->_bcc_array) > 0)
1520 {
Pascal Kriete14287f32011-02-14 13:39:34 -05001521 foreach ($this->_bcc_array as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001522 {
1523 if ($val != "")
1524 {
1525 $this->_send_command('to', $val);
1526 }
1527 }
1528 }
1529
1530 $this->_send_command('data');
1531
1532 // perform dot transformation on any lines that begin with a dot
1533 $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody));
1534
1535 $this->_send_data('.');
1536
1537 $reply = $this->_get_smtp_data();
1538
1539 $this->_set_error_message($reply);
1540
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001541 if (strncmp($reply, '250', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001542 {
patworkb0707982011-04-08 15:10:05 +02001543 $this->_set_error_message('lang:email_smtp_error', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001544 return FALSE;
1545 }
1546
1547 $this->_send_command('quit');
1548 return TRUE;
1549 }
Barry Mienydd671972010-10-04 16:33:58 +02001550
Derek Allard2067d1a2008-11-13 22:59:24 +00001551 // --------------------------------------------------------------------
1552
1553 /**
1554 * SMTP Connect
1555 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001556 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001557 * @param string
1558 * @return string
1559 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001560 protected function _smtp_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +00001561 {
Phil Sturgeonc00a5a02011-11-22 15:25:32 +00001562 $ssl = ($this->smtp_crypto == 'ssl') ? 'ssl://' : NULL;
Radu Potop4c589ae2011-09-29 10:19:55 +03001563
Radu Potopbbf04b02011-09-28 13:57:51 +03001564 $this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
Derek Allard2067d1a2008-11-13 22:59:24 +00001565 $this->smtp_port,
1566 $errno,
1567 $errstr,
1568 $this->smtp_timeout);
1569
Pascal Kriete14287f32011-02-14 13:39:34 -05001570 if ( ! is_resource($this->_smtp_connect))
Derek Allard2067d1a2008-11-13 22:59:24 +00001571 {
patworkb0707982011-04-08 15:10:05 +02001572 $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr);
Derek Allard2067d1a2008-11-13 22:59:24 +00001573 return FALSE;
1574 }
1575
1576 $this->_set_error_message($this->_get_smtp_data());
Radu Potopbbf04b02011-09-28 13:57:51 +03001577
1578 if ($this->smtp_crypto == 'tls')
1579 {
1580 $this->_send_command('hello');
1581 $this->_send_command('starttls');
Phil Sturgeonc00a5a02011-11-22 15:25:32 +00001582
Radu Potop4c589ae2011-09-29 10:19:55 +03001583 $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
Radu Potop4c589ae2011-09-29 10:19:55 +03001584
Sean Fishere862ddd2011-10-26 22:45:00 -03001585 if ($crypto !== TRUE)
1586 {
1587 $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data());
1588 return FALSE;
1589 }
Radu Potopbbf04b02011-09-28 13:57:51 +03001590 }
1591
Derek Allard2067d1a2008-11-13 22:59:24 +00001592 return $this->_send_command('hello');
1593 }
Barry Mienydd671972010-10-04 16:33:58 +02001594
Derek Allard2067d1a2008-11-13 22:59:24 +00001595 // --------------------------------------------------------------------
1596
1597 /**
1598 * Send SMTP command
1599 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001600 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001601 * @param string
1602 * @param string
1603 * @return string
1604 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001605 protected function _send_command($cmd, $data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001606 {
1607 switch ($cmd)
1608 {
1609 case 'hello' :
1610
1611 if ($this->_smtp_auth OR $this->_get_encoding() == '8bit')
1612 $this->_send_data('EHLO '.$this->_get_hostname());
1613 else
1614 $this->_send_data('HELO '.$this->_get_hostname());
1615
1616 $resp = 250;
1617 break;
Radu Potopbbf04b02011-09-28 13:57:51 +03001618 case 'starttls' :
1619
1620 $this->_send_data('STARTTLS');
1621
1622 $resp = 220;
1623 break;
Derek Allard2067d1a2008-11-13 22:59:24 +00001624 case 'from' :
1625
1626 $this->_send_data('MAIL FROM:<'.$data.'>');
1627
1628 $resp = 250;
1629 break;
1630 case 'to' :
1631
1632 $this->_send_data('RCPT TO:<'.$data.'>');
1633
1634 $resp = 250;
1635 break;
1636 case 'data' :
1637
1638 $this->_send_data('DATA');
1639
1640 $resp = 354;
1641 break;
1642 case 'quit' :
1643
1644 $this->_send_data('QUIT');
1645
1646 $resp = 221;
1647 break;
1648 }
1649
1650 $reply = $this->_get_smtp_data();
1651
1652 $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>";
1653
1654 if (substr($reply, 0, 3) != $resp)
1655 {
patworkb0707982011-04-08 15:10:05 +02001656 $this->_set_error_message('lang:email_smtp_error', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001657 return FALSE;
1658 }
1659
1660 if ($cmd == 'quit')
1661 {
1662 fclose($this->_smtp_connect);
1663 }
1664
1665 return TRUE;
1666 }
Barry Mienydd671972010-10-04 16:33:58 +02001667
Derek Allard2067d1a2008-11-13 22:59:24 +00001668 // --------------------------------------------------------------------
1669
1670 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -05001671 * SMTP Authenticate
Derek Allard2067d1a2008-11-13 22:59:24 +00001672 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001673 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001674 * @return bool
1675 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001676 protected function _smtp_authenticate()
Derek Allard2067d1a2008-11-13 22:59:24 +00001677 {
1678 if ( ! $this->_smtp_auth)
1679 {
1680 return TRUE;
1681 }
1682
Derek Jones37f4b9c2011-07-01 17:56:50 -05001683 if ($this->smtp_user == "" AND $this->smtp_pass == "")
Derek Allard2067d1a2008-11-13 22:59:24 +00001684 {
patworkb0707982011-04-08 15:10:05 +02001685 $this->_set_error_message('lang:email_no_smtp_unpw');
Derek Allard2067d1a2008-11-13 22:59:24 +00001686 return FALSE;
1687 }
1688
1689 $this->_send_data('AUTH LOGIN');
1690
1691 $reply = $this->_get_smtp_data();
1692
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001693 if (strncmp($reply, '334', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001694 {
patworkb0707982011-04-08 15:10:05 +02001695 $this->_set_error_message('lang:email_failed_smtp_login', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001696 return FALSE;
1697 }
1698
1699 $this->_send_data(base64_encode($this->smtp_user));
1700
1701 $reply = $this->_get_smtp_data();
1702
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001703 if (strncmp($reply, '334', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001704 {
patworkb0707982011-04-08 15:10:05 +02001705 $this->_set_error_message('lang:email_smtp_auth_un', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001706 return FALSE;
1707 }
1708
1709 $this->_send_data(base64_encode($this->smtp_pass));
1710
1711 $reply = $this->_get_smtp_data();
1712
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001713 if (strncmp($reply, '235', 3) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001714 {
patworkb0707982011-04-08 15:10:05 +02001715 $this->_set_error_message('lang:email_smtp_auth_pw', $reply);
Derek Allard2067d1a2008-11-13 22:59:24 +00001716 return FALSE;
1717 }
1718
1719 return TRUE;
1720 }
Barry Mienydd671972010-10-04 16:33:58 +02001721
Derek Allard2067d1a2008-11-13 22:59:24 +00001722 // --------------------------------------------------------------------
1723
1724 /**
1725 * Send SMTP data
1726 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001727 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001728 * @return bool
1729 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001730 protected function _send_data($data)
Derek Allard2067d1a2008-11-13 22:59:24 +00001731 {
1732 if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
1733 {
patworkb0707982011-04-08 15:10:05 +02001734 $this->_set_error_message('lang:email_smtp_data_failure', $data);
Derek Allard2067d1a2008-11-13 22:59:24 +00001735 return FALSE;
1736 }
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001737
1738 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001739 }
Barry Mienydd671972010-10-04 16:33:58 +02001740
Derek Allard2067d1a2008-11-13 22:59:24 +00001741 // --------------------------------------------------------------------
1742
1743 /**
1744 * Get SMTP data
1745 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001746 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001747 * @return string
1748 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001749 protected function _get_smtp_data()
Derek Allard2067d1a2008-11-13 22:59:24 +00001750 {
1751 $data = "";
1752
1753 while ($str = fgets($this->_smtp_connect, 512))
1754 {
1755 $data .= $str;
1756
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001757 if ($str[3] == " ")
Derek Allard2067d1a2008-11-13 22:59:24 +00001758 {
1759 break;
1760 }
1761 }
1762
1763 return $data;
1764 }
Barry Mienydd671972010-10-04 16:33:58 +02001765
Derek Allard2067d1a2008-11-13 22:59:24 +00001766 // --------------------------------------------------------------------
1767
1768 /**
1769 * Get Hostname
1770 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001771 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001772 * @return string
1773 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001774 protected function _get_hostname()
Derek Allard2067d1a2008-11-13 22:59:24 +00001775 {
1776 return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
1777 }
Barry Mienydd671972010-10-04 16:33:58 +02001778
Derek Allard2067d1a2008-11-13 22:59:24 +00001779 // --------------------------------------------------------------------
1780
1781 /**
1782 * Get IP
1783 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001784 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001785 * @return string
1786 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001787 protected function _get_ip()
Derek Allard2067d1a2008-11-13 22:59:24 +00001788 {
1789 if ($this->_IP !== FALSE)
1790 {
1791 return $this->_IP;
1792 }
1793
1794 $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
1795 $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001796 if ($cip) $this->_IP = $cip;
1797 elseif ($rip) $this->_IP = $rip;
1798 else
1799 {
1800 $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
1801 if ($fip)
1802 {
1803 $this->_IP = $fip;
1804 }
1805 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001806
Robin Sowell76b369e2010-03-19 11:15:28 -04001807 if (strpos($this->_IP, ',') !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001808 {
1809 $x = explode(',', $this->_IP);
1810 $this->_IP = end($x);
1811 }
1812
1813 if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
1814 {
1815 $this->_IP = '0.0.0.0';
1816 }
1817
Derek Allard2067d1a2008-11-13 22:59:24 +00001818 return $this->_IP;
1819 }
Barry Mienydd671972010-10-04 16:33:58 +02001820
Derek Allard2067d1a2008-11-13 22:59:24 +00001821 // --------------------------------------------------------------------
1822
1823 /**
1824 * Get Debug Message
1825 *
1826 * @access public
1827 * @return string
1828 */
Phil Sturgeona0f980e2011-01-13 10:59:12 +00001829 public function print_debugger()
Derek Allard2067d1a2008-11-13 22:59:24 +00001830 {
1831 $msg = '';
1832
1833 if (count($this->_debug_msg) > 0)
1834 {
1835 foreach ($this->_debug_msg as $val)
1836 {
1837 $msg .= $val;
1838 }
1839 }
1840
1841 $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
1842 return $msg;
1843 }
Barry Mienydd671972010-10-04 16:33:58 +02001844
Derek Allard2067d1a2008-11-13 22:59:24 +00001845 // --------------------------------------------------------------------
1846
1847 /**
1848 * Set Message
1849 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001850 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001851 * @param string
1852 * @return string
1853 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001854 protected function _set_error_message($msg, $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001855 {
1856 $CI =& get_instance();
1857 $CI->lang->load('email');
1858
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001859 if (substr($msg, 0, 5) !== 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5))))
Derek Allard2067d1a2008-11-13 22:59:24 +00001860 {
1861 $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
1862 }
1863 else
1864 {
1865 $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />";
1866 }
1867 }
Barry Mienydd671972010-10-04 16:33:58 +02001868
Derek Allard2067d1a2008-11-13 22:59:24 +00001869 // --------------------------------------------------------------------
1870
1871 /**
1872 * Mime Types
1873 *
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001874 * @access protected
Derek Allard2067d1a2008-11-13 22:59:24 +00001875 * @param string
1876 * @return string
1877 */
Phil Sturgeon6d2f13a2011-07-20 10:04:52 -06001878 protected function _mime_types($ext = "")
Derek Allard2067d1a2008-11-13 22:59:24 +00001879 {
1880 $mimes = array( 'hqx' => 'application/mac-binhex40',
1881 'cpt' => 'application/mac-compactpro',
1882 'doc' => 'application/msword',
1883 'bin' => 'application/macbinary',
1884 'dms' => 'application/octet-stream',
1885 'lha' => 'application/octet-stream',
1886 'lzh' => 'application/octet-stream',
1887 'exe' => 'application/octet-stream',
1888 'class' => 'application/octet-stream',
1889 'psd' => 'application/octet-stream',
1890 'so' => 'application/octet-stream',
1891 'sea' => 'application/octet-stream',
1892 'dll' => 'application/octet-stream',
1893 'oda' => 'application/oda',
1894 'pdf' => 'application/pdf',
1895 'ai' => 'application/postscript',
1896 'eps' => 'application/postscript',
1897 'ps' => 'application/postscript',
1898 'smi' => 'application/smil',
1899 'smil' => 'application/smil',
1900 'mif' => 'application/vnd.mif',
1901 'xls' => 'application/vnd.ms-excel',
1902 'ppt' => 'application/vnd.ms-powerpoint',
1903 'wbxml' => 'application/vnd.wap.wbxml',
1904 'wmlc' => 'application/vnd.wap.wmlc',
1905 'dcr' => 'application/x-director',
1906 'dir' => 'application/x-director',
1907 'dxr' => 'application/x-director',
1908 'dvi' => 'application/x-dvi',
1909 'gtar' => 'application/x-gtar',
1910 'php' => 'application/x-httpd-php',
1911 'php4' => 'application/x-httpd-php',
1912 'php3' => 'application/x-httpd-php',
1913 'phtml' => 'application/x-httpd-php',
1914 'phps' => 'application/x-httpd-php-source',
1915 'js' => 'application/x-javascript',
1916 'swf' => 'application/x-shockwave-flash',
1917 'sit' => 'application/x-stuffit',
1918 'tar' => 'application/x-tar',
1919 'tgz' => 'application/x-tar',
1920 'xhtml' => 'application/xhtml+xml',
1921 'xht' => 'application/xhtml+xml',
1922 'zip' => 'application/zip',
1923 'mid' => 'audio/midi',
1924 'midi' => 'audio/midi',
1925 'mpga' => 'audio/mpeg',
1926 'mp2' => 'audio/mpeg',
1927 'mp3' => 'audio/mpeg',
1928 'aif' => 'audio/x-aiff',
1929 'aiff' => 'audio/x-aiff',
1930 'aifc' => 'audio/x-aiff',
1931 'ram' => 'audio/x-pn-realaudio',
1932 'rm' => 'audio/x-pn-realaudio',
1933 'rpm' => 'audio/x-pn-realaudio-plugin',
1934 'ra' => 'audio/x-realaudio',
1935 'rv' => 'video/vnd.rn-realvideo',
1936 'wav' => 'audio/x-wav',
1937 'bmp' => 'image/bmp',
1938 'gif' => 'image/gif',
1939 'jpeg' => 'image/jpeg',
1940 'jpg' => 'image/jpeg',
1941 'jpe' => 'image/jpeg',
1942 'png' => 'image/png',
1943 'tiff' => 'image/tiff',
1944 'tif' => 'image/tiff',
1945 'css' => 'text/css',
1946 'html' => 'text/html',
1947 'htm' => 'text/html',
1948 'shtml' => 'text/html',
1949 'txt' => 'text/plain',
1950 'text' => 'text/plain',
1951 'log' => 'text/plain',
1952 'rtx' => 'text/richtext',
1953 'rtf' => 'text/rtf',
1954 'xml' => 'text/xml',
1955 'xsl' => 'text/xml',
1956 'mpeg' => 'video/mpeg',
1957 'mpg' => 'video/mpeg',
1958 'mpe' => 'video/mpeg',
1959 'qt' => 'video/quicktime',
1960 'mov' => 'video/quicktime',
1961 'avi' => 'video/x-msvideo',
1962 'movie' => 'video/x-sgi-movie',
1963 'doc' => 'application/msword',
1964 'word' => 'application/msword',
1965 'xl' => 'application/excel',
1966 'eml' => 'message/rfc822'
1967 );
1968
1969 return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
1970 }
1971
1972}
1973// END CI_Email class
1974
1975/* End of file Email.php */
Andrey Andreev1bd3d882011-12-22 15:38:20 +02001976/* Location: ./system/libraries/Email.php */