blob: fd3fb8f1739d1abec73bea9bee3050b154199d04 [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
admine79dc712006-09-26 03:52:45 +000016// INITIALIZE THE CLASS ---------------------------------------------------
17
admin41a16852006-09-26 18:17:19 +000018$config = array();
19if (file_exists(APPPATH.'config/email'.EXT))
20{
21 include_once(APPPATH.'config/email'.EXT);
22}
23
admine79dc712006-09-26 03:52:45 +000024$obj =& get_instance();
admin41a16852006-09-26 18:17:19 +000025$obj->init_class('CI_Email', 'email', $config);
admine79dc712006-09-26 03:52:45 +000026
adminb0dd10f2006-08-25 17:25:49 +000027// ------------------------------------------------------------------------
28
29/**
30 * Code Igniter Email Class
31 *
32 * Permits email to be sent using Mail, Sendmail, or SMTP.
33 *
34 * @package CodeIgniter
35 * @subpackage Libraries
36 * @category Libraries
37 * @author Rick Ellis
38 * @link http://www.codeigniter.com/user_guide/libraries/email.html
39 */
40class CI_Email {
41
42 var $useragent = "Code Igniter";
43 var $mailpath = "/usr/sbin/sendmail"; // Sendmail path
44 var $protocol = "mail"; // mail/sendmail/smtp
45 var $smtp_host = ""; // SMTP Server. Example: mail.earthlink.net
46 var $smtp_user = ""; // SMTP Username
47 var $smtp_pass = ""; // SMTP Password
48 var $smtp_port = "25"; // SMTP Port
49 var $smtp_timeout = 5; // SMTP Timeout in seconds
50 var $wordwrap = TRUE; // true/false Turns word-wrap on/off
51 var $wrapchars = "76"; // Number of characters to wrap at.
52 var $mailtype = "text"; // text/html Defines email formatting
53 var $charset = "utf-8"; // Default char set: iso-8859-1 or us-ascii
54 var $multipart = "mixed"; // "mixed" (in the body) or "related" (separate)
55 var $alt_message = ''; // Alternative message for HTML emails
56 var $validate = FALSE; // true/false. Enables email validation
57 var $priority = "3"; // Default priority (1 - 5)
58 var $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
59 var $bcc_batch_mode = FALSE; // true/false Turns on/off Bcc batch feature
60 var $bcc_batch_size = 200; // If bcc_batch_mode = true, sets max number of Bccs in each batch
61 var $_subject = "";
62 var $_body = "";
63 var $_finalbody = "";
64 var $_alt_boundary = "";
65 var $_atc_boundary = "";
66 var $_header_str = "";
67 var $_smtp_connect = "";
68 var $_encoding = "8bit";
69 var $_safe_mode = FALSE;
70 var $_IP = FALSE;
71 var $_smtp_auth = FALSE;
72 var $_replyto_flag = FALSE;
73 var $_debug_msg = array();
74 var $_recipients = array();
75 var $_cc_array = array();
76 var $_bcc_array = array();
77 var $_headers = array();
78 var $_attach_name = array();
79 var $_attach_type = array();
80 var $_attach_disp = array();
81 var $_protocols = array('mail', 'sendmail', 'smtp');
82 var $_base_charsets = array('iso-8859-1', 'us-ascii');
83 var $_bit_depths = array('7bit', '8bit');
84 var $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');
85
86
87 /**
88 * Constructor - Sets Email Preferences
89 *
90 * The constructor can be passed an array of config values
91 */
92 function CI_Email($config = array())
93 {
94 if (count($config) > 0)
95 {
96 $this->initialize($config);
97 }
98
99 log_message('debug', "Email Class Initialized");
100 }
101 // END CI_Email()
102
103 // --------------------------------------------------------------------
104
105 /**
106 * Initialize preferences
107 *
108 * @access public
109 * @param array
110 * @return void
111 */
112 function initialize($config = array())
113 {
114 $this->clear();
115 foreach ($config as $key => $val)
116 {
117 if (isset($this->$key))
118 {
119 $method = 'set_'.$key;
120
121 if (method_exists($this, $method))
122 {
123 $this->$method($val);
124 }
125 else
126 {
127 $this->$key = $val;
128 }
129 }
130 }
131 $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
132 $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE;
133 }
134 // END initialize()
135
136 // --------------------------------------------------------------------
137
138 /**
139 * Initialize the Email Data
140 *
141 * @access public
142 * @return void
143 */
admind16d6c22006-09-21 00:45:12 +0000144 function clear($clear_attachments = FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000145 {
146 $this->_subject = "";
147 $this->_body = "";
148 $this->_finalbody = "";
149 $this->_header_str = "";
150 $this->_replyto_flag = FALSE;
151 $this->_recipients = array();
152 $this->_headers = array();
153 $this->_debug_msg = array();
154
155 $this->_set_header('User-Agent', $this->useragent);
156 $this->_set_header('Date', $this->_set_date());
admind16d6c22006-09-21 00:45:12 +0000157
158 if ($clear_attachments !== FALSE)
159 {
160 $this->_attach_name = array();
161 $this->_attach_type = array();
162 $this->_attach_disp = array();
163 }
adminb0dd10f2006-08-25 17:25:49 +0000164 }
165 // END clear()
166
167 // --------------------------------------------------------------------
168
169 /**
170 * Set FROM
171 *
172 * @access public
173 * @param string
174 * @param string
175 * @return void
176 */
177 function from($from, $name = '')
178 {
179 if (preg_match( '/\<(.*)\>/', $from, $match))
180 $from = $match['1'];
181
182 if ($this->validate)
183 $this->validate_email($this->_str_to_array($from));
184
185 if ($name != '' && substr($name, 0, 1) != '"')
186 {
187 $name = '"'.$name.'"';
188 }
189
190 $this->_set_header('From', $name.' <'.$from.'>');
191 $this->_set_header('Return-Path', '<'.$from.'>');
192 }
193 // END from()
194
195 // --------------------------------------------------------------------
196
197 /**
198 * Set Reply-to
199 *
200 * @access public
201 * @param string
202 * @param string
203 * @return void
204 */
205 function reply_to($replyto, $name = '')
206 {
207 if (preg_match( '/\<(.*)\>/', $replyto, $match))
208 $replyto = $match['1'];
209
210 if ($this->validate)
211 $this->validate_email($this->_str_to_array($replyto));
212
213 if ($name == '')
214 {
215 $name = $replyto;
216 }
217
218 if (substr($name, 0, 1) != '"')
219 {
220 $name = '"'.$name.'"';
221 }
222
223 $this->_set_header('Reply-To', $name.' <'.$replyto.'>');
224 $this->_replyto_flag = TRUE;
225 }
226 // END reply_to()
227
228 // --------------------------------------------------------------------
229
230 /**
231 * Set Recipients
232 *
233 * @access public
234 * @param string
235 * @return void
236 */
237 function to($to)
238 {
239 $to = $this->_str_to_array($to);
240 $to = $this->clean_email($to);
241
242 if ($this->validate)
243 $this->validate_email($to);
244
245 if ($this->_get_protocol() != 'mail')
246 $this->_set_header('To', implode(", ", $to));
247
248 switch ($this->_get_protocol())
249 {
250 case 'smtp' : $this->_recipients = $to;
251 break;
252 case 'sendmail' : $this->_recipients = implode(", ", $to);
253 break;
254 case 'mail' : $this->_recipients = implode(", ", $to);
255 break;
256 }
257 }
258 // END to()
259
260 // --------------------------------------------------------------------
261
262 /**
263 * Set CC
264 *
265 * @access public
266 * @param string
267 * @return void
268 */
269 function cc($cc)
270 {
271 $cc = $this->_str_to_array($cc);
272 $cc = $this->clean_email($cc);
273
274 if ($this->validate)
275 $this->validate_email($cc);
276
277 $this->_set_header('Cc', implode(", ", $cc));
278
279 if ($this->_get_protocol() == "smtp")
280 $this->_cc_array = $cc;
281 }
282 // END cc()
283
284 // --------------------------------------------------------------------
285
286 /**
287 * Set BCC
288 *
289 * @access public
290 * @param string
291 * @param string
292 * @return void
293 */
294 function bcc($bcc, $limit = '')
295 {
admin1cf89aa2006-09-03 18:24:39 +0000296 if ($limit != '' && is_numeric($limit))
adminb0dd10f2006-08-25 17:25:49 +0000297 {
298 $this->bcc_batch_mode = true;
299 $this->bcc_batch_size = $limit;
300 }
301
302 $bcc = $this->_str_to_array($bcc);
303 $bcc = $this->clean_email($bcc);
304
305 if ($this->validate)
306 $this->validate_email($bcc);
307
308 if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size))
309 $this->_bcc_array = $bcc;
310 else
311 $this->_set_header('Bcc', implode(", ", $bcc));
312 }
313 // END bcc()
314
315 // --------------------------------------------------------------------
316
317 /**
318 * Set Email Subject
319 *
320 * @access public
321 * @param string
322 * @return void
323 */
324 function subject($subject)
325 {
326 $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject);
327 $subject = preg_replace("/(\t)/", " ", $subject);
328
329 $this->_set_header('Subject', trim($subject));
330 }
331 // END subject()
332
333 // --------------------------------------------------------------------
334
335 /**
336 * Set Body
337 *
338 * @access public
339 * @param string
340 * @return void
341 */
342 function message($body)
343 {
344 $body = rtrim(str_replace("\r", "", $body));
345
346 if ($this->wordwrap === TRUE AND $this->mailtype != 'html')
347 $this->_body = $this->word_wrap($body);
348 else
349 $this->_body = $body;
350
351 $this->_body = stripslashes($this->_body);
352 }
353 // END message()
354
355 // --------------------------------------------------------------------
356
357 /**
358 * Assign file attachments
359 *
360 * @access public
361 * @param string
362 * @return string
363 */
364 function attach($filename, $disposition = 'attachment')
365 {
366 $this->_attach_name[] = $filename;
367 $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename))));
368 $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters
369 }
370 // END attach()
371
372 // --------------------------------------------------------------------
373
374 /**
375 * Add a Header Item
376 *
377 * @access public
378 * @param string
379 * @param string
380 * @return void
381 */
382 function _set_header($header, $value)
383 {
384 $this->_headers[$header] = $value;
385 }
386 // END _set_header()
387
388 // --------------------------------------------------------------------
389
390 /**
391 * Convert a String to an Array
392 *
393 * @access public
394 * @param string
395 * @return array
396 */
397 function _str_to_array($email)
398 {
399 if ( ! is_array($email))
400 {
401 if (ereg(',$', $email))
402 $email = substr($email, 0, -1);
403
404 if (ereg('^,', $email))
405 $email = substr($email, 1);
406
407 if (ereg(',', $email))
408 {
409 $x = explode(',', $email);
410 $email = array();
411
412 for ($i = 0; $i < count($x); $i ++)
413 $email[] = trim($x[$i]);
414 }
415 else
416 {
417 $email = trim($email);
418 settype($email, "array");
419 }
420 }
421 return $email;
422 }
423 // END _str_to_array()
424
425 // --------------------------------------------------------------------
426
427 /**
428 * Set Multipart Value
429 *
430 * @access public
431 * @param string
432 * @return void
433 */
434 function set_alt_message($str = '')
435 {
436 $this->alt_message = ($str == '') ? '' : $str;
437 }
438 // END set_alt_message()
439
440 // --------------------------------------------------------------------
441
442 /**
443 * Set Mailtype
444 *
445 * @access public
446 * @param string
447 * @return void
448 */
449 function set_mailtype($type = 'text')
450 {
451 $this->mailtype = ($type == 'html') ? 'html' : 'text';
452 }
453 // END set_mailtype()
454
455 // --------------------------------------------------------------------
456
457 /**
458 * Set Wordwrap
459 *
460 * @access public
461 * @param string
462 * @return void
463 */
464 function set_wordwrap($wordwrap = TRUE)
465 {
466 $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE;
467 }
468 // END set_wordwrap()
469
470 // --------------------------------------------------------------------
471
472 /**
473 * Set Protocal
474 *
475 * @access public
476 * @param string
477 * @return void
478 */
479 function set_protocol($protocol = 'mail')
480 {
481 $this->protocol = ( ! in_array($protocol, $this->_protocols)) ? 'mail' : strtolower($protocol);
482 }
483 // END set_protocol()
484
485 // --------------------------------------------------------------------
486
487 /**
488 * Set Priority
489 *
490 * @access public
491 * @param integer
492 * @return void
493 */
494 function set_priority($n = 3)
495 {
admin1cf89aa2006-09-03 18:24:39 +0000496 if ( ! is_numeric($n))
adminb0dd10f2006-08-25 17:25:49 +0000497 {
498 $this->priority = 3;
499 return;
500 }
501
502 if ($n < 1 OR $n > 5)
503 {
504 $this->priority = 3;
505 return;
506 }
507
508 $this->priority = $n;
509 }
510 // END set_priority()
511
512 // --------------------------------------------------------------------
513
514 /**
515 * Set Newline Character
516 *
517 * @access public
518 * @param string
519 * @return void
520 */
521 function set_newline($newline = "\n")
522 {
523 if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r")
524 {
525 $this->newline = "\n";
526 return;
527 }
528
529 $this->newline = $newline;
530 }
531 // END set_newline()
532
533 // --------------------------------------------------------------------
534
535 /**
536 * Set Message Boundry
537 *
538 * @access private
539 * @return void
540 */
541 function _set_boundaries()
542 {
543 $this->_alt_boundary = "B_ALT_".uniqid(''); // mulipart/alternative
544 $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary
545 }
546 // END _set_boundaries()
547
548 // --------------------------------------------------------------------
549
550 /**
551 * Get the Message ID
552 *
553 * @access private
554 * @return string
555 */
556 function _get_message_id()
557 {
558 $from = $this->_headers['Return-Path'];
559 $from = str_replace(">", "", $from);
560 $from = str_replace("<", "", $from);
561
562 return "<".uniqid('').strstr($from, '@').">";
563 }
564 // END _get_message_id()
565
566 // --------------------------------------------------------------------
567
568 /**
569 * Get Mail Protocol
570 *
571 * @access private
572 * @param bool
573 * @return string
574 */
575 function _get_protocol($return = true)
576 {
577 $this->protocol = strtolower($this->protocol);
578 $this->protocol = ( ! in_array($this->protocol, $this->_protocols)) ? 'mail' : $this->protocol;
579
580 if ($return == true)
581 return $this->protocol;
582 }
583 // END _get_protocol()
584
585 // --------------------------------------------------------------------
586
587 /**
588 * Get Mail Encoding
589 *
590 * @access private
591 * @param bool
592 * @return string
593 */
594 function _get_encoding($return = true)
595 {
596 $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding;
597
598 if ( ! in_array($this->charset, $this->_base_charsets))
599 $this->_encoding = "8bit";
600
601 if ($return == true)
602 return $this->_encoding;
603 }
604 // END _get_encoding()
605
606 // --------------------------------------------------------------------
607
608 /**
609 * Get content type (text/html/attachment)
610 *
611 * @access private
612 * @return string
613 */
614 function _get_content_type()
615 {
616 if ($this->mailtype == 'html' && count($this->_attach_name) == 0)
617 return 'html';
618
619 elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0)
620 return 'html-attach';
621
622 elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0)
623 return 'plain-attach';
624
625 else return 'plain';
626 }
627 // END _get_content_type()
628
629 // --------------------------------------------------------------------
630
631 /**
632 * Set RFC 822 Date
633 *
634 * @access public
635 * @return string
636 */
637 function _set_date()
638 {
639 $timezone = date("Z");
640 $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+';
641 $timezone = abs($timezone);
642 $timezone = ($timezone/3600) * 100 + ($timezone % 3600) /60;
643
644 return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone);
645 }
646 // END _set_date()
647
648 // --------------------------------------------------------------------
649
650 /**
651 * Mime message
652 *
653 * @access private
654 * @return string
655 */
656 function _get_mime_message()
657 {
658 return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format.";
659 }
660 // END _get_mime_message()
661
662 // --------------------------------------------------------------------
663
664 /**
665 * Validate Email Address
666 *
667 * @access public
668 * @param string
669 * @return bool
670 */
671 function validate_email($email)
672 {
673 if ( ! is_array($email))
674 {
675 $this->_set_error_message('email_must_be_array');
676 return FALSE;
677 }
678
679 foreach ($email as $val)
680 {
681 if ( ! $this->valid_email($val))
682 {
683 $this->_set_error_message('email_invalid_address', $val);
684 return FALSE;
685 }
686 }
687 }
688 // END validate_email()
689
690 // --------------------------------------------------------------------
691
692 /**
693 * Email Validation
694 *
695 * @access public
696 * @param string
697 * @return bool
698 */
699 function valid_email($address)
700 {
701 if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address))
702 return FALSE;
703 else
704 return TRUE;
705 }
706 // END valid_email()
707
708 // --------------------------------------------------------------------
709
710 /**
711 * Clean Extended Email Address: Joe Smith <joe@smith.com>
712 *
713 * @access public
714 * @param string
715 * @return string
716 */
717 function clean_email($email)
718 {
719 if ( ! is_array($email))
720 {
721 if (preg_match('/\<(.*)\>/', $email, $match))
722 return $match['1'];
723 else
724 return $email;
725 }
726
727 $clean_email = array();
728
729 for ($i=0; $i < count($email); $i++)
730 {
731 if (preg_match( '/\<(.*)\>/', $email[$i], $match))
732 $clean_email[] = $match['1'];
733 else
734 $clean_email[] = $email[$i];
735 }
736
737 return $clean_email;
738 }
739 // END clean_email()
740
741 // --------------------------------------------------------------------
742
743 /**
744 * Build alternative plain text message
745 *
746 * This function provides the raw message for use
747 * in plain-text headers of HTML-formatted emails.
748 * If the user hasn't specified his own alternative message
749 * it creates one by stripping the HTML
750 *
751 * @access private
752 * @return string
753 */
754 function _get_alt_message()
755 {
admind16d6c22006-09-21 00:45:12 +0000756 if ($this->alt_message != "")
757 {
758 return $this->word_wrap($this->alt_message, '76');
759 }
760
adminb0dd10f2006-08-25 17:25:49 +0000761 if (eregi( '\<body(.*)\</body\>', $this->_body, $match))
762 {
763 $body = $match['1'];
764 $body = substr($body, strpos($body, ">") + 1);
765 }
766 else
767 {
768 $body = $this->_body;
769 }
770
771 $body = trim(strip_tags($body));
772 $body = preg_replace( '#<!--(.*)--\>#', "", $body);
773 $body = str_replace("\t", "", $body);
774
775 for ($i = 20; $i >= 3; $i--)
776 {
777 $n = "";
778
779 for ($x = 1; $x <= $i; $x ++)
780 $n .= "\n";
781
782 $body = str_replace($n, "\n\n", $body);
783 }
784
785 return $this->word_wrap($body, '76');
786 }
787 // END _get_alt_message()
788
789 // --------------------------------------------------------------------
790
791 /**
792 * Word Wrap
793 *
794 * @access public
795 * @param string
796 * @param integer
797 * @return string
798 */
799 function word_wrap($str, $chars = '')
800 {
801 if ($chars == '')
802 $chars = ($this->wrapchars == "") ? "76" : $this->wrapchars;
803
804 $lines = split("\n", $str);
805
806 $output = "";
807
808 while (list(, $thisline) = each($lines))
809 {
810 if (strlen($thisline) > $chars)
811 {
812 $line = "";
813
814 $words = split(" ", $thisline);
815
816 while(list(, $thisword) = each($words))
817 {
818 while((strlen($thisword)) > $chars)
819 {
820 if (stristr($thisword, '{unwrap}') !== FALSE OR stristr($thisword, '{/unwrap}') !== FALSE)
821 {
822 break;
823 }
824
825 $cur_pos = 0;
826
827 for($i=0; $i < $chars - 1; $i++)
828 {
829 $output .= $thisword[$i];
830 $cur_pos++;
831 }
832
833 $output .= "\n";
834
835 $thisword = substr($thisword, $cur_pos, (strlen($thisword) - $cur_pos));
836 }
837
838 if ((strlen($line) + strlen($thisword)) > $chars)
839 {
840 $output .= $line."\n";
841
842 $line = $thisword." ";
843 }
844 else
845 {
846 $line .= $thisword." ";
847 }
848 }
849
850 $output .= $line."\n";
851 }
852 else
853 {
854 $output .= $thisline."\n";
855 }
856 }
857
858 return $output;
859 }
860 // END word_wrap()
861
862 // --------------------------------------------------------------------
863
864 /**
865 * Build final headers
866 *
867 * @access public
868 * @param string
869 * @return string
870 */
871 function _build_headers()
872 {
873 $this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
874 $this->_set_header('X-Mailer', $this->useragent);
875 $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]);
876 $this->_set_header('Message-ID', $this->_get_message_id());
877 $this->_set_header('Mime-Version', '1.0');
878 }
879 // END _build_headers()
880
881 // --------------------------------------------------------------------
882
883 /**
884 * Write Headers as a string
885 *
886 * @access public
887 * @return void
888 */
889 function _write_headers()
890 {
891 if ($this->protocol == 'mail')
892 {
893 $this->_subject = $this->_headers['Subject'];
894 unset($this->_headers['Subject']);
895 }
896
897 reset($this->_headers);
898 $this->_header_str = "";
899
900 foreach($this->_headers as $key => $val)
901 {
902 $val = trim($val);
903
904 if ($val != "")
905 {
906 $this->_header_str .= $key.": ".$val.$this->newline;
907 }
908 }
909
910 if ($this->_get_protocol() == 'mail')
911 $this->_header_str = substr($this->_header_str, 0, -1);
912 }
913 // END _write_headers()
914
915 // --------------------------------------------------------------------
916
917 /**
918 * Build Final Body and attachments
919 *
920 * @access public
921 * @return void
922 */
923 function _build_message()
924 {
925 $this->_set_boundaries();
926 $this->_write_headers();
927
928 $hdr = ($this->_get_protocol() == 'mail') ? $this->newline : '';
929
930 switch ($this->_get_content_type())
931 {
932 case 'plain' :
933
934 $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
935 $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding();
936
937 if ($this->_get_protocol() == 'mail')
938 {
939 $this->_header_str .= $hdr;
940 $this->_finalbody = $this->_body;
941
942 return;
943 }
944
945 $hdr .= $this->newline . $this->newline . $this->_body;
946
947 $this->_finalbody = $hdr;
948 return;
949
950 break;
951 case 'html' :
952
953 $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline;
954 $hdr .= $this->_get_mime_message() . $this->newline . $this->newline;
955 $hdr .= "--" . $this->_alt_boundary . $this->newline;
956
957 $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
958 $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline;
959 $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline;
960
961 $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
962 $hdr .= "Content-Transfer-Encoding: quoted/printable";
963
964 if ($this->_get_protocol() == 'mail')
965 {
966 $this->_header_str .= $hdr;
967 $this->_finalbody = $this->_body . $this->newline . $this->newline . "--" . $this->_alt_boundary . "--";
968
969 return;
970 }
971
972 $hdr .= $this->newline . $this->newline;
973 $hdr .= $this->_body . $this->newline . $this->newline . "--" . $this->_alt_boundary . "--";
974
975 $this->_finalbody = $hdr;
976 return;
977
978 break;
979 case 'plain-attach' :
980
981 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline;
982 $hdr .= $this->_get_mime_message() . $this->newline . $this->newline;
983 $hdr .= "--" . $this->_atc_boundary . $this->newline;
984
985 $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
986 $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding();
987
988 if ($this->_get_protocol() == 'mail')
989 {
990 $this->_header_str .= $hdr;
991
992 $body = $this->_body . $this->newline . $this->newline;
993 }
994
995 $hdr .= $this->newline . $this->newline;
996 $hdr .= $this->_body . $this->newline . $this->newline;
997
998 break;
999 case 'html-attach' :
1000
1001 $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline;
1002 $hdr .= $this->_get_mime_message() . $this->newline . $this->newline;
1003 $hdr .= "--" . $this->_atc_boundary . $this->newline;
1004
1005 $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline;
1006 $hdr .= "--" . $this->_alt_boundary . $this->newline;
1007
1008 $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
1009 $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline;
1010 $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline;
1011
1012 $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
1013 $hdr .= "Content-Transfer-Encoding: quoted/printable";
1014
1015 if ($this->_get_protocol() == 'mail')
1016 {
1017 $this->_header_str .= $hdr;
1018
1019 $body = $this->_body . $this->newline . $this->newline;
1020 $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
1021 }
1022
1023 $hdr .= $this->newline . $this->newline;
1024 $hdr .= $this->_body . $this->newline . $this->newline;
1025 $hdr .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
1026
1027 break;
1028 }
1029
1030 $attachment = array();
1031
1032 $z = 0;
1033
1034 for ($i=0; $i < count($this->_attach_name); $i++)
1035 {
1036 $filename = $this->_attach_name[$i];
1037 $basename = basename($filename);
1038 $ctype = $this->_attach_type[$i];
1039
1040 if ( ! file_exists($filename))
1041 {
1042 $this->_set_error_message('email_attachment_missing', $filename);
1043 return FALSE;
1044 }
1045
1046 $h = "--".$this->_atc_boundary.$this->newline;
1047 $h .= "Content-type: ".$ctype."; ";
1048 $h .= "name=\"".$basename."\"".$this->newline;
1049 $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline;
1050 $h .= "Content-Transfer-Encoding: base64".$this->newline;
1051
1052 $attachment[$z++] = $h;
1053 $file = filesize($filename) +1;
1054
1055 if ( ! $fp = fopen($filename, 'r'))
1056 {
1057 $this->_set_error_message('email_attachment_unredable', $filename);
1058 return FALSE;
1059 }
1060
1061 $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file)));
1062 fclose($fp);
1063 }
1064
1065 if ($this->_get_protocol() == 'mail')
1066 {
1067 $this->_finalbody = $body . implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
1068
1069 return;
1070 }
1071
1072 $this->_finalbody = $hdr.implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
1073
1074 return;
1075 }
1076 // END _build_message()
1077
1078 // --------------------------------------------------------------------
1079
1080 /**
1081 * Send Email
1082 *
1083 * @access public
1084 * @return bool
1085 */
1086 function send()
1087 {
1088 if ($this->_replyto_flag == FALSE)
1089 {
1090 $this->reply_to($this->_headers['From']);
1091 }
1092
1093 if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND
1094 ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
1095 ( ! isset($this->_headers['Cc'])))
1096 {
1097 $this->_set_error_message('email_no_recipients');
1098 return FALSE;
1099 }
1100
1101 $this->_build_headers();
1102
1103 if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0)
1104 {
1105 if (count($this->_bcc_array) > $this->bcc_batch_size)
1106 return $this->batch_bcc_send();
1107 }
1108
1109 $this->_build_message();
1110
1111 if ( ! $this->_spool_email())
1112 return FALSE;
1113 else
1114 return TRUE;
1115 }
1116 // END send()
1117
1118 // --------------------------------------------------------------------
1119
1120 /**
1121 * Batch Bcc Send. Sends groups of Bccs in batches
1122 *
1123 * @access public
1124 * @return bool
1125 */
1126 function batch_bcc_send()
1127 {
1128 $float = $this->bcc_batch_size -1;
1129
1130 $flag = 0;
1131 $set = "";
1132
1133 $chunk = array();
1134
1135 for ($i = 0; $i < count($this->_bcc_array); $i++)
1136 {
1137 if (isset($this->_bcc_array[$i]))
1138 $set .= ", ".$this->_bcc_array[$i];
1139
1140 if ($i == $float)
1141 {
1142 $chunk[] = substr($set, 1);
1143 $float = $float + $this->bcc_batch_size;
1144 $set = "";
1145 }
1146
1147 if ($i == count($this->_bcc_array)-1)
1148 $chunk[] = substr($set, 1);
1149 }
1150
1151 for ($i = 0; $i < count($chunk); $i++)
1152 {
1153 unset($this->_headers['Bcc']);
1154 unset($bcc);
1155
1156 $bcc = $this->_str_to_array($chunk[$i]);
1157 $bcc = $this->clean_email($bcc);
1158
1159 if ($this->protocol != 'smtp')
1160 $this->_set_header('Bcc', implode(", ", $bcc));
1161 else
1162 $this->_bcc_array = $bcc;
1163
1164 $this->_build_message();
1165 $this->_spool_email();
1166 }
1167 }
1168 // END batch_bcc_send()
1169
1170 // --------------------------------------------------------------------
1171
1172 /**
1173 * Unwrap special elements
1174 *
1175 * @access private
1176 * @return void
1177 */
1178 function _unwrap_specials()
1179 {
1180 $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
1181 }
1182 // END _unwrap_specials()
1183
1184 // --------------------------------------------------------------------
1185
1186 /**
1187 * Strip line-breaks via callback
1188 *
1189 * @access private
1190 * @return string
1191 */
1192 function _remove_nl_callback($matches)
1193 {
1194 return preg_replace("/(\r\n)|(\r)|(\n)/", "", $matches['1']);
1195 }
1196 // END _remove_nl_callback()
1197
1198 // --------------------------------------------------------------------
1199
1200 /**
1201 * Spool mail to the mail server
1202 *
1203 * @access private
1204 * @return bol
1205 */
1206 function _spool_email()
1207 {
1208 $this->_unwrap_specials();
1209
1210 switch ($this->_get_protocol())
1211 {
1212 case 'mail' :
1213
1214 if ( ! $this->_send_with_mail())
1215 {
1216 $this->_set_error_message('email_send_failure_phpmail');
1217 return FALSE;
1218 }
1219 break;
1220 case 'sendmail' :
1221
1222 if ( ! $this->_send_with_sendmail())
1223 {
1224 $this->_set_error_message('email_send_failure_sendmail');
1225 return FALSE;
1226 }
1227 break;
1228 case 'smtp' :
1229
1230 if ( ! $this->_send_with_smtp())
1231 {
1232 $this->_set_error_message('email_send_failure_smtp');
1233 return FALSE;
1234 }
1235 break;
1236
1237 }
1238
1239 $this->_set_error_message('email_sent', $this->_get_protocol());
1240 return true;
1241 }
1242 // END _spool_email()
1243
1244 // --------------------------------------------------------------------
1245
1246 /**
1247 * Send using mail()
1248 *
1249 * @access private
1250 * @return bool
1251 */
1252 function _send_with_mail()
1253 {
1254 if ($this->_safe_mode == TRUE)
1255 {
1256 if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
1257 return FALSE;
1258 else
1259 return TRUE;
1260 }
1261 else
1262 {
1263 if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f".$this->clean_email($this->_headers['From'])))
1264 return FALSE;
1265 else
1266 return TRUE;
1267 }
1268 }
1269 // END _send_with_mail()
1270
1271 // --------------------------------------------------------------------
1272
1273 /**
1274 * Send using Sendmail
1275 *
1276 * @access private
1277 * @return bool
1278 */
1279 function _send_with_sendmail()
1280 {
1281 $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
1282
1283 if ( ! is_resource($fp))
1284 {
1285 $this->_set_error_message('email_no_socket');
1286 return FALSE;
1287 }
1288
1289 fputs($fp, $this->_header_str);
1290 fputs($fp, $this->_finalbody);
1291 pclose($fp) >> 8 & 0xFF;
1292
1293 return TRUE;
1294 }
1295 // END _send_with_sendmail()
1296
1297 // --------------------------------------------------------------------
1298
1299 /**
1300 * Send using SMTP
1301 *
1302 * @access private
1303 * @return bool
1304 */
1305 function _send_with_smtp()
1306 {
1307 if ($this->smtp_host == '')
1308 {
1309 $this->_set_error_message('email_no_hostname');
1310 return FALSE;
1311 }
1312
1313 $this->_smtp_connect();
1314 $this->_smtp_authenticate();
1315
1316 $this->_send_command('from', $this->clean_email($this->_headers['From']));
1317
1318 foreach($this->_recipients as $val)
1319 $this->_send_command('to', $val);
1320
1321 if (count($this->_cc_array) > 0)
1322 {
1323 foreach($this->_cc_array as $val)
1324 {
1325 if ($val != "")
1326 $this->_send_command('to', $val);
1327 }
1328 }
1329
1330 if (count($this->_bcc_array) > 0)
1331 {
1332 foreach($this->_bcc_array as $val)
1333 {
1334 if ($val != "")
1335 $this->_send_command('to', $val);
1336 }
1337 }
1338
1339 $this->_send_command('data');
1340
1341 $this->_send_data($this->_header_str . $this->_finalbody);
1342
1343 $this->_send_data('.');
1344
1345 $reply = $this->_get_smtp_data();
1346
1347 $this->_set_error_message($reply);
1348
1349 if (substr($reply, 0, 3) != '250')
1350 {
1351 $this->_set_error_message('email_smtp_error', $reply);
1352 return FALSE;
1353 }
1354
1355 $this->_send_command('quit');
1356 return true;
1357 }
1358 // END _send_with_smtp()
1359
1360 // --------------------------------------------------------------------
1361
1362 /**
1363 * SMTP Connect
1364 *
1365 * @access public
1366 * @param string
1367 * @return string
1368 */
1369 function _smtp_connect()
1370 {
1371
1372 $this->_smtp_connect = fsockopen($this->smtp_host,
1373 $this->smtp_port,
1374 $errno,
1375 $errstr,
1376 $this->smtp_timeout);
1377
1378 if( ! is_resource($this->_smtp_connect))
1379 {
1380 $this->_set_error_message('email_smtp_error', $errno." ".$errstr);
1381 return FALSE;
1382 }
1383
1384 $this->_set_error_message($this->_get_smtp_data());
1385 return $this->_send_command('hello');
1386 }
1387 // END _smtp_connect()
1388
1389 // --------------------------------------------------------------------
1390
1391 /**
1392 * Send SMTP command
1393 *
1394 * @access private
1395 * @param string
1396 * @param string
1397 * @return string
1398 */
1399 function _send_command($cmd, $data = '')
1400 {
1401 switch ($cmd)
1402 {
1403 case 'hello' :
1404
1405 if ($this->_smtp_auth OR $this->_get_encoding() == '8bit')
1406 $this->_send_data('EHLO '.$this->_get_hostname());
1407 else
1408 $this->_send_data('HELO '.$this->_get_hostname());
1409
1410 $resp = 250;
1411 break;
1412 case 'from' :
1413
1414 $this->_send_data('MAIL FROM:<'.$data.'>');
1415
1416 $resp = 250;
1417 break;
1418 case 'to' :
1419
1420 $this->_send_data('RCPT TO:<'.$data.'>');
1421
1422 $resp = 250;
1423 break;
1424 case 'data' :
1425
1426 $this->_send_data('DATA');
1427
1428 $resp = 354;
1429 break;
1430 case 'quit' :
1431
1432 $this->_send_data('QUIT');
1433
1434 $resp = 221;
1435 break;
1436 }
1437
1438 $reply = $this->_get_smtp_data();
1439
1440 $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>";
1441
1442 if (substr($reply, 0, 3) != $resp)
1443 {
1444 $this->_set_error_message('email_smtp_error', $reply);
1445 return FALSE;
1446 }
1447
1448 if ($cmd == 'quit')
1449 fclose($this->_smtp_connect);
1450
1451 return true;
1452 }
1453 // END _send_command()
1454
1455 // --------------------------------------------------------------------
1456
1457 /**
1458 * SMTP Authenticate
1459 *
1460 * @access private
1461 * @return bool
1462 */
1463 function _smtp_authenticate()
1464 {
1465 if ( ! $this->_smtp_auth)
1466 return true;
1467
1468 if ($this->smtp_user == "" AND $this->smtp_pass == "")
1469 {
1470 $this->_set_error_message('email_no_smtp_unpw');
1471 return FALSE;
1472 }
1473
1474 $this->_send_data('AUTH LOGIN');
1475
1476 $reply = $this->_get_smtp_data();
1477
1478 if (substr($reply, 0, 3) != '334')
1479 {
1480 $this->_set_error_message('email_filed_smtp_login', $reply);
1481 return FALSE;
1482 }
1483
1484 $this->_send_data(base64_encode($this->smtp_user));
1485
1486 $reply = $this->_get_smtp_data();
1487
1488 if (substr($reply, 0, 3) != '334')
1489 {
1490 $this->_set_error_message('email_smtp_auth_un', $reply);
1491 return FALSE;
1492 }
1493
1494 $this->_send_data(base64_encode($this->smtp_pass));
1495
1496 $reply = $this->_get_smtp_data();
1497
1498 if (substr($reply, 0, 3) != '235')
1499 {
1500 $this->_set_error_message('email_smtp_auth_pw', $reply);
1501 return FALSE;
1502 }
1503
1504 return true;
1505 }
1506 // END _smtp_authenticate()
1507
1508 // --------------------------------------------------------------------
1509
1510 /**
1511 * Send SMTP data
1512 *
1513 * @access private
1514 * @return bool
1515 */
1516 function _send_data($data)
1517 {
1518 if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
1519 {
1520 $this->_set_error_message('email_smtp_data_failure', $data);
1521 return FALSE;
1522 }
1523 else
1524 return true;
1525 }
1526 // END _send_data()
1527
1528 // --------------------------------------------------------------------
1529
1530 /**
1531 * Get SMTP data
1532 *
1533 * @access private
1534 * @return string
1535 */
1536 function _get_smtp_data()
1537 {
1538 $data = "";
1539
1540 while ($str = fgets($this->_smtp_connect, 512))
1541 {
1542 $data .= $str;
1543
1544 if (substr($str, 3, 1) == " ")
1545 break;
1546 }
1547
1548 return $data;
1549 }
1550 // END _get_smtp_data()
1551
1552 // --------------------------------------------------------------------
1553
1554 /**
1555 * Get Hostname
1556 *
1557 * @access private
1558 * @return string
1559 */
1560 function _get_hostname()
1561 {
1562 return ($this->smtp_host != '') ? $this->smtp_host : $this->_get_ip();
1563 }
1564 // END _get_hostname()
1565
1566 // --------------------------------------------------------------------
1567
1568 /**
1569 * Get IP
1570 *
1571 * @access private
1572 * @return string
1573 */
1574 function _get_ip()
1575 {
1576 if ($this->_IP !== FALSE)
1577 {
1578 return $this->_IP;
1579 }
1580
1581 $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
1582 $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
1583 $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
1584
1585 if ($cip && $rip) $this->_IP = $cip;
1586 elseif ($rip) $this->_IP = $rip;
1587 elseif ($cip) $this->_IP = $cip;
1588 elseif ($fip) $this->_IP = $fip;
1589
1590 if (strstr($this->_IP, ','))
1591 {
1592 $x = explode(',', $this->_IP);
1593 $this->_IP = end($x);
1594 }
1595
1596 if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
1597 $this->_IP = '0.0.0.0';
1598
1599 unset($cip);
1600 unset($rip);
1601 unset($fip);
1602
1603 return $this->_IP;
1604 }
1605 // END _get_ip()
1606
1607 // --------------------------------------------------------------------
1608
1609 /**
1610 * Get Debugg Message
1611 *
1612 * @access public
1613 * @return string
1614 */
1615 function print_debugger()
1616 {
1617 $msg = '';
1618
1619 if (count($this->_debug_msg) > 0)
1620 {
1621 foreach ($this->_debug_msg as $val)
1622 {
1623 $msg .= $val;
1624 }
1625 }
1626
1627 $msg .= "<pre>".$this->_header_str."\n".$this->_subject."\n".$this->_finalbody.'</pre>';
1628 return $msg;
1629 }
1630 // print_debugger()
1631
1632 // --------------------------------------------------------------------
1633
1634 /**
1635 * Set Message
1636 *
1637 * @access public
1638 * @param string
1639 * @return string
1640 */
1641 function _set_error_message($msg, $val = '')
1642 {
1643 $obj =& get_instance();
1644 $obj->lang->load('email');
1645
1646 if (FALSE === ($line = $obj->lang->line($msg)))
1647 {
1648 $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
1649 }
1650 else
1651 {
1652 $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />";
1653 }
1654 }
1655 // END _set_error_message()
1656
1657 // --------------------------------------------------------------------
1658
1659 /**
1660 * Mime Types
1661 *
1662 * @access private
1663 * @param string
1664 * @return string
1665 */
1666 function _mime_types($ext = "")
1667 {
1668 $mimes = array( 'hqx' => 'application/mac-binhex40',
1669 'cpt' => 'application/mac-compactpro',
1670 'doc' => 'application/msword',
1671 'bin' => 'application/macbinary',
1672 'dms' => 'application/octet-stream',
1673 'lha' => 'application/octet-stream',
1674 'lzh' => 'application/octet-stream',
1675 'exe' => 'application/octet-stream',
1676 'class' => 'application/octet-stream',
1677 'psd' => 'application/octet-stream',
1678 'so' => 'application/octet-stream',
1679 'sea' => 'application/octet-stream',
1680 'dll' => 'application/octet-stream',
1681 'oda' => 'application/oda',
1682 'pdf' => 'application/pdf',
1683 'ai' => 'application/postscript',
1684 'eps' => 'application/postscript',
1685 'ps' => 'application/postscript',
1686 'smi' => 'application/smil',
1687 'smil' => 'application/smil',
1688 'mif' => 'application/vnd.mif',
1689 'xls' => 'application/vnd.ms-excel',
1690 'ppt' => 'application/vnd.ms-powerpoint',
1691 'wbxml' => 'application/vnd.wap.wbxml',
1692 'wmlc' => 'application/vnd.wap.wmlc',
1693 'dcr' => 'application/x-director',
1694 'dir' => 'application/x-director',
1695 'dxr' => 'application/x-director',
1696 'dvi' => 'application/x-dvi',
1697 'gtar' => 'application/x-gtar',
1698 'php' => 'application/x-httpd-php',
1699 'php4' => 'application/x-httpd-php',
1700 'php3' => 'application/x-httpd-php',
1701 'phtml' => 'application/x-httpd-php',
1702 'phps' => 'application/x-httpd-php-source',
1703 'js' => 'application/x-javascript',
1704 'swf' => 'application/x-shockwave-flash',
1705 'sit' => 'application/x-stuffit',
1706 'tar' => 'application/x-tar',
1707 'tgz' => 'application/x-tar',
1708 'xhtml' => 'application/xhtml+xml',
1709 'xht' => 'application/xhtml+xml',
1710 'zip' => 'application/zip',
1711 'mid' => 'audio/midi',
1712 'midi' => 'audio/midi',
1713 'mpga' => 'audio/mpeg',
1714 'mp2' => 'audio/mpeg',
1715 'mp3' => 'audio/mpeg',
1716 'aif' => 'audio/x-aiff',
1717 'aiff' => 'audio/x-aiff',
1718 'aifc' => 'audio/x-aiff',
1719 'ram' => 'audio/x-pn-realaudio',
1720 'rm' => 'audio/x-pn-realaudio',
1721 'rpm' => 'audio/x-pn-realaudio-plugin',
1722 'ra' => 'audio/x-realaudio',
1723 'rv' => 'video/vnd.rn-realvideo',
1724 'wav' => 'audio/x-wav',
1725 'bmp' => 'image/bmp',
1726 'gif' => 'image/gif',
1727 'jpeg' => 'image/jpeg',
1728 'jpg' => 'image/jpeg',
1729 'jpe' => 'image/jpeg',
1730 'png' => 'image/png',
1731 'tiff' => 'image/tiff',
1732 'tif' => 'image/tiff',
1733 'css' => 'text/css',
1734 'html' => 'text/html',
1735 'htm' => 'text/html',
1736 'shtml' => 'text/html',
1737 'txt' => 'text/plain',
1738 'text' => 'text/plain',
1739 'log' => 'text/plain',
1740 'rtx' => 'text/richtext',
1741 'rtf' => 'text/rtf',
1742 'xml' => 'text/xml',
1743 'xsl' => 'text/xml',
1744 'mpeg' => 'video/mpeg',
1745 'mpg' => 'video/mpeg',
1746 'mpe' => 'video/mpeg',
1747 'qt' => 'video/quicktime',
1748 'mov' => 'video/quicktime',
1749 'avi' => 'video/x-msvideo',
1750 'movie' => 'video/x-sgi-movie',
1751 'doc' => 'application/msword',
1752 'word' => 'application/msword',
1753 'xl' => 'application/excel',
1754 'eml' => 'message/rfc822'
1755 );
1756
1757 return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
1758 }
1759 // END _mime_types()
1760
1761}
1762// END CI_Email class
1763?>