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