Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?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
|
| 8 | * @author Rick Ellis
|
| 9 | * @copyright Copyright (c) 2006, EllisLab, 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 |
|
| 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
|
| 26 | * @author Rick Ellis
|
| 27 | * @link http://www.codeigniter.com/user_guide/libraries/email.html
|
| 28 | */
|
| 29 | class 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)
|
Derek Jones | 2d2437e | 2007-07-12 11:32:37 +0000 | [diff] [blame] | 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 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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 = (@ini_get("safe_mode") == 0) ? 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 | {
|
Rick Ellis | 8d127c7 | 2007-06-11 04:47:58 +0000 | [diff] [blame] | 492 | if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r")
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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 = ($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();
|
| 687 |
|
| 688 | for ($i=0; $i < count($email); $i++)
|
| 689 | {
|
| 690 | if (preg_match( '/\<(.*)\>/', $email[$i], $match))
|
| 691 | $clean_email[] = $match['1'];
|
| 692 | else
|
| 693 | $clean_email[] = $email[$i];
|
| 694 | }
|
| 695 |
|
| 696 | return $clean_email;
|
| 697 | }
|
| 698 |
|
| 699 | // --------------------------------------------------------------------
|
| 700 |
|
| 701 | /**
|
| 702 | * Build alternative plain text message
|
| 703 | *
|
| 704 | * This function provides the raw message for use
|
| 705 | * in plain-text headers of HTML-formatted emails.
|
| 706 | * If the user hasn't specified his own alternative message
|
| 707 | * it creates one by stripping the HTML
|
| 708 | *
|
| 709 | * @access private
|
| 710 | * @return string
|
| 711 | */
|
| 712 | function _get_alt_message()
|
| 713 | {
|
| 714 | if ($this->alt_message != "")
|
| 715 | {
|
| 716 | return $this->word_wrap($this->alt_message, '76');
|
| 717 | }
|
| 718 |
|
| 719 | if (eregi( '\<body(.*)\</body\>', $this->_body, $match))
|
| 720 | {
|
| 721 | $body = $match['1'];
|
| 722 | $body = substr($body, strpos($body, ">") + 1);
|
| 723 | }
|
| 724 | else
|
| 725 | {
|
| 726 | $body = $this->_body;
|
| 727 | }
|
| 728 |
|
| 729 | $body = trim(strip_tags($body));
|
| 730 | $body = preg_replace( '#<!--(.*)--\>#', "", $body);
|
| 731 | $body = str_replace("\t", "", $body);
|
| 732 |
|
| 733 | for ($i = 20; $i >= 3; $i--)
|
| 734 | {
|
| 735 | $n = "";
|
| 736 |
|
| 737 | for ($x = 1; $x <= $i; $x ++)
|
| 738 | $n .= "\n";
|
| 739 |
|
| 740 | $body = str_replace($n, "\n\n", $body);
|
| 741 | }
|
| 742 |
|
| 743 | return $this->word_wrap($body, '76');
|
| 744 | }
|
| 745 |
|
| 746 | // --------------------------------------------------------------------
|
| 747 |
|
| 748 | /**
|
| 749 | * Word Wrap
|
| 750 | *
|
| 751 | * @access public
|
| 752 | * @param string
|
| 753 | * @param integer
|
| 754 | * @return string
|
| 755 | */
|
| 756 | function word_wrap($str, $charlim = '')
|
| 757 | {
|
| 758 | // Se the character limit
|
| 759 | if ($charlim == '')
|
| 760 | {
|
| 761 | $charlim = ($this->wrapchars == "") ? "76" : $this->wrapchars;
|
| 762 | }
|
| 763 |
|
| 764 | // Reduce multiple spaces
|
| 765 | $str = preg_replace("| +|", " ", $str);
|
| 766 |
|
| 767 | // Standardize newlines
|
| 768 | $str = preg_replace("/\r\n|\r/", "\n", $str);
|
| 769 |
|
| 770 | // If the current word is surrounded by {unwrap} tags we'll
|
| 771 | // strip the entire chunk and replace it with a marker.
|
| 772 | $unwrap = array();
|
| 773 | if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
|
| 774 | {
|
| 775 | for ($i = 0; $i < count($matches['0']); $i++)
|
| 776 | {
|
| 777 | $unwrap[] = $matches['1'][$i];
|
| 778 | $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
|
| 779 | }
|
| 780 | }
|
| 781 |
|
| 782 | // Use PHP's native function to do the initial wordwrap.
|
| 783 | // We set the cut flag to FALSE so that any individual words that are
|
| 784 | // too long get left alone. In the next step we'll deal with them.
|
| 785 | $str = wordwrap($str, $charlim, "\n", FALSE);
|
| 786 |
|
| 787 | // Split the string into individual lines of text and cycle through them
|
| 788 | $output = "";
|
| 789 | foreach (explode("\n", $str) as $line)
|
| 790 | {
|
| 791 | // Is the line within the allowed character count?
|
| 792 | // If so we'll join it to the output and continue
|
| 793 | if (strlen($line) <= $charlim)
|
| 794 | {
|
| 795 | $output .= $line.$this->newline;
|
| 796 | continue;
|
| 797 | }
|
| 798 |
|
| 799 | $temp = '';
|
| 800 | while((strlen($line)) > $charlim)
|
| 801 | {
|
| 802 | // If the over-length word is a URL we won't wrap it
|
| 803 | if (preg_match("!\[url.+\]|://|wwww.!", $line))
|
| 804 | {
|
| 805 | break;
|
| 806 | }
|
| 807 |
|
| 808 | // Trim the word down
|
| 809 | $temp .= substr($line, 0, $charlim-1);
|
| 810 | $line = substr($line, $charlim-1);
|
| 811 | }
|
| 812 |
|
| 813 | // If $temp contains data it means we had to split up an over-length
|
| 814 | // word into smaller chunks so we'll add it back to our current line
|
| 815 | if ($temp != '')
|
| 816 | {
|
| 817 | $output .= $temp.$this->newline.$line;
|
| 818 | }
|
| 819 | else
|
| 820 | {
|
| 821 | $output .= $line;
|
| 822 | }
|
| 823 |
|
| 824 | $output .= $this->newline;
|
| 825 | }
|
| 826 |
|
| 827 | // Put our markers back
|
| 828 | if (count($unwrap) > 0)
|
| 829 | {
|
| 830 | foreach ($unwrap as $key => $val)
|
| 831 | {
|
| 832 | $output = str_replace("{{unwrapped".$key."}}", $val, $output);
|
| 833 | }
|
| 834 | }
|
| 835 |
|
| 836 | return $output;
|
| 837 | }
|
| 838 |
|
| 839 | // --------------------------------------------------------------------
|
| 840 |
|
| 841 | /**
|
| 842 | * Build final headers
|
| 843 | *
|
| 844 | * @access public
|
| 845 | * @param string
|
| 846 | * @return string
|
| 847 | */
|
| 848 | function _build_headers()
|
| 849 | {
|
| 850 | $this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
|
| 851 | $this->_set_header('X-Mailer', $this->useragent);
|
| 852 | $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]);
|
| 853 | $this->_set_header('Message-ID', $this->_get_message_id());
|
| 854 | $this->_set_header('Mime-Version', '1.0');
|
| 855 | }
|
| 856 |
|
| 857 | // --------------------------------------------------------------------
|
| 858 |
|
| 859 | /**
|
| 860 | * Write Headers as a string
|
| 861 | *
|
| 862 | * @access public
|
| 863 | * @return void
|
| 864 | */
|
| 865 | function _write_headers()
|
| 866 | {
|
| 867 | if ($this->protocol == 'mail')
|
| 868 | {
|
| 869 | $this->_subject = $this->_headers['Subject'];
|
| 870 | unset($this->_headers['Subject']);
|
| 871 | }
|
| 872 |
|
| 873 | reset($this->_headers);
|
| 874 | $this->_header_str = "";
|
| 875 |
|
| 876 | foreach($this->_headers as $key => $val)
|
| 877 | {
|
| 878 | $val = trim($val);
|
| 879 |
|
| 880 | if ($val != "")
|
| 881 | {
|
| 882 | $this->_header_str .= $key.": ".$val.$this->newline;
|
| 883 | }
|
| 884 | }
|
| 885 |
|
| 886 | if ($this->_get_protocol() == 'mail')
|
| 887 | $this->_header_str = substr($this->_header_str, 0, -1);
|
| 888 | }
|
| 889 |
|
| 890 | // --------------------------------------------------------------------
|
| 891 |
|
| 892 | /**
|
| 893 | * Build Final Body and attachments
|
| 894 | *
|
| 895 | * @access public
|
| 896 | * @return void
|
| 897 | */
|
| 898 | function _build_message()
|
| 899 | {
|
| 900 | if ($this->wordwrap === TRUE AND $this->mailtype != 'html')
|
| 901 | {
|
| 902 | $this->_body = $this->word_wrap($this->_body);
|
| 903 | }
|
| 904 |
|
| 905 | $this->_set_boundaries();
|
| 906 | $this->_write_headers();
|
| 907 |
|
| 908 | $hdr = ($this->_get_protocol() == 'mail') ? $this->newline : '';
|
| 909 |
|
| 910 | switch ($this->_get_content_type())
|
| 911 | {
|
| 912 | case 'plain' :
|
| 913 |
|
| 914 | $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
|
| 915 | $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding();
|
| 916 |
|
| 917 | if ($this->_get_protocol() == 'mail')
|
| 918 | {
|
| 919 | $this->_header_str .= $hdr;
|
| 920 | $this->_finalbody = $this->_body;
|
| 921 |
|
| 922 | return;
|
| 923 | }
|
| 924 |
|
| 925 | $hdr .= $this->newline . $this->newline . $this->_body;
|
| 926 |
|
| 927 | $this->_finalbody = $hdr;
|
| 928 | return;
|
| 929 |
|
| 930 | break;
|
| 931 | case 'html' :
|
Derek Jones | 2d2437e | 2007-07-12 11:32:37 +0000 | [diff] [blame] | 932 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 933 | $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline;
|
| 934 | $hdr .= $this->_get_mime_message() . $this->newline . $this->newline;
|
| 935 | $hdr .= "--" . $this->_alt_boundary . $this->newline;
|
| 936 |
|
| 937 | $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
|
| 938 | $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline;
|
| 939 | $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline;
|
| 940 |
|
| 941 | $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
|
Derek Jones | 2d2437e | 2007-07-12 11:32:37 +0000 | [diff] [blame] | 942 | $hdr .= "Content-Transfer-Encoding: quoted-printable";
|
| 943 |
|
| 944 | $this->_body = $this->_prep_quoted_printable($this->_body);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 945 |
|
| 946 | if ($this->_get_protocol() == 'mail')
|
| 947 | {
|
| 948 | $this->_header_str .= $hdr;
|
| 949 | $this->_finalbody = $this->_body . $this->newline . $this->newline . "--" . $this->_alt_boundary . "--";
|
| 950 |
|
| 951 | return;
|
| 952 | }
|
| 953 |
|
| 954 | $hdr .= $this->newline . $this->newline;
|
| 955 | $hdr .= $this->_body . $this->newline . $this->newline . "--" . $this->_alt_boundary . "--";
|
| 956 |
|
| 957 | $this->_finalbody = $hdr;
|
| 958 | return;
|
| 959 |
|
| 960 | break;
|
| 961 | case 'plain-attach' :
|
| 962 |
|
| 963 | $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline;
|
| 964 | $hdr .= $this->_get_mime_message() . $this->newline . $this->newline;
|
| 965 | $hdr .= "--" . $this->_atc_boundary . $this->newline;
|
| 966 |
|
| 967 | $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
|
| 968 | $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding();
|
| 969 |
|
| 970 | if ($this->_get_protocol() == 'mail')
|
| 971 | {
|
| 972 | $this->_header_str .= $hdr;
|
| 973 |
|
| 974 | $body = $this->_body . $this->newline . $this->newline;
|
| 975 | }
|
| 976 |
|
| 977 | $hdr .= $this->newline . $this->newline;
|
| 978 | $hdr .= $this->_body . $this->newline . $this->newline;
|
| 979 |
|
| 980 | break;
|
| 981 | case 'html-attach' :
|
| 982 |
|
| 983 | $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline;
|
| 984 | $hdr .= $this->_get_mime_message() . $this->newline . $this->newline;
|
| 985 | $hdr .= "--" . $this->_atc_boundary . $this->newline;
|
| 986 |
|
| 987 | $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline;
|
| 988 | $hdr .= "--" . $this->_alt_boundary . $this->newline;
|
| 989 |
|
| 990 | $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
|
| 991 | $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline;
|
| 992 | $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline;
|
| 993 |
|
| 994 | $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
|
Derek Jones | 2d2437e | 2007-07-12 11:32:37 +0000 | [diff] [blame] | 995 | $hdr .= "Content-Transfer-Encoding: quoted-printable";
|
| 996 |
|
| 997 | $this->_body = $this->_prep_quoted_printable($this->_body);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 998 |
|
| 999 | if ($this->_get_protocol() == 'mail')
|
| 1000 | {
|
| 1001 | $this->_header_str .= $hdr;
|
| 1002 |
|
| 1003 | $body = $this->_body . $this->newline . $this->newline;
|
| 1004 | $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
|
| 1005 | }
|
| 1006 |
|
| 1007 | $hdr .= $this->newline . $this->newline;
|
| 1008 | $hdr .= $this->_body . $this->newline . $this->newline;
|
| 1009 | $hdr .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline;
|
| 1010 |
|
| 1011 | break;
|
| 1012 | }
|
| 1013 |
|
| 1014 | $attachment = array();
|
| 1015 |
|
| 1016 | $z = 0;
|
| 1017 |
|
| 1018 | for ($i=0; $i < count($this->_attach_name); $i++)
|
| 1019 | {
|
| 1020 | $filename = $this->_attach_name[$i];
|
| 1021 | $basename = basename($filename);
|
| 1022 | $ctype = $this->_attach_type[$i];
|
| 1023 |
|
| 1024 | if ( ! file_exists($filename))
|
| 1025 | {
|
| 1026 | $this->_set_error_message('email_attachment_missing', $filename);
|
| 1027 | return FALSE;
|
| 1028 | }
|
| 1029 |
|
| 1030 | $h = "--".$this->_atc_boundary.$this->newline;
|
| 1031 | $h .= "Content-type: ".$ctype."; ";
|
| 1032 | $h .= "name=\"".$basename."\"".$this->newline;
|
| 1033 | $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline;
|
| 1034 | $h .= "Content-Transfer-Encoding: base64".$this->newline;
|
| 1035 |
|
| 1036 | $attachment[$z++] = $h;
|
| 1037 | $file = filesize($filename) +1;
|
| 1038 |
|
| 1039 | if ( ! $fp = fopen($filename, 'r'))
|
| 1040 | {
|
| 1041 | $this->_set_error_message('email_attachment_unredable', $filename);
|
| 1042 | return FALSE;
|
| 1043 | }
|
| 1044 |
|
| 1045 | $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file)));
|
| 1046 | fclose($fp);
|
| 1047 | }
|
| 1048 |
|
| 1049 | if ($this->_get_protocol() == 'mail')
|
| 1050 | {
|
| 1051 | $this->_finalbody = $body . implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
|
| 1052 |
|
| 1053 | return;
|
| 1054 | }
|
| 1055 |
|
| 1056 | $this->_finalbody = $hdr.implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";
|
| 1057 |
|
| 1058 | return;
|
| 1059 | }
|
| 1060 |
|
| 1061 | // --------------------------------------------------------------------
|
Derek Jones | 2d2437e | 2007-07-12 11:32:37 +0000 | [diff] [blame] | 1062 |
|
| 1063 | /**
|
| 1064 | * Prep Quoted Printable
|
| 1065 | *
|
| 1066 | * Prepares string for Quoted-Printable Content-Transfer-Encoding
|
| 1067 | * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt
|
| 1068 | *
|
| 1069 | * @access public
|
| 1070 | * @param string
|
| 1071 | * @param integer
|
| 1072 | * @return string
|
| 1073 | */
|
| 1074 | function _prep_quoted_printable($str, $charlim = '')
|
| 1075 | {
|
| 1076 | // Set the character limit
|
| 1077 | // Don't allow over 76, as that will make servers and MUAs barf
|
| 1078 | // all over quoted-printable data
|
| 1079 | if ($charlim == '' OR $charlim > '76')
|
| 1080 | {
|
| 1081 | $charlim = '76';
|
| 1082 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1083 |
|
Derek Jones | 2d2437e | 2007-07-12 11:32:37 +0000 | [diff] [blame] | 1084 | // Reduce multiple spaces
|
| 1085 | $str = preg_replace("| +|", " ", $str);
|
| 1086 |
|
| 1087 | // Standardize newlines
|
| 1088 | $str = preg_replace("/\r\n|\r/", "\n", $str);
|
| 1089 |
|
| 1090 | // We are intentionally wrapping so mail servers will encode characters
|
| 1091 | // properly and MUAs will behave, so {unwrap} must go!
|
| 1092 | $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);
|
| 1093 |
|
| 1094 | // Break into an array of lines
|
| 1095 | $lines = preg_split("/\n/", $str);
|
| 1096 |
|
| 1097 | $escape = '=';
|
| 1098 | $output = '';
|
| 1099 |
|
| 1100 | foreach ($lines as $line)
|
| 1101 | {
|
| 1102 | $length = strlen($line);
|
| 1103 | $temp = '';
|
| 1104 |
|
| 1105 | // Loop through each character in the line to add soft-wrap
|
| 1106 | // characters at the end of a line " =\r\n" and add the newly
|
| 1107 | // processed line(s) to the output (see comment on $crlf class property)
|
| 1108 | for ($i = 0; $i < $length; $i++)
|
| 1109 | {
|
| 1110 | // Grab the next character
|
| 1111 | $char = substr($line, $i, 1);
|
| 1112 | $ascii = ord($char);
|
| 1113 |
|
| 1114 | // Convert spaces and tabs but only if it's the end of the line
|
| 1115 | if ($i == ($length - 1))
|
| 1116 | {
|
| 1117 | $char = ($ascii == '32' OR $ascii == '9') ? $escape.sprintf('%02s', dechex($char)) : $char;
|
| 1118 | }
|
| 1119 |
|
| 1120 | // encode = signs
|
| 1121 | if ($ascii == '61')
|
| 1122 | {
|
| 1123 | $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D
|
| 1124 | }
|
| 1125 |
|
| 1126 | // If we're at the character limit, add the line to the output,
|
| 1127 | // reset our temp variable, and keep on chuggin'
|
| 1128 | if ((strlen($temp) + strlen($char)) >= $charlim)
|
| 1129 | {
|
| 1130 | $output .= $temp.$escape.$this->crlf;
|
| 1131 | $temp = '';
|
| 1132 | }
|
| 1133 |
|
| 1134 | // Add the character to our temporary line
|
| 1135 | $temp .= $char;
|
| 1136 | }
|
| 1137 |
|
| 1138 | // Add our completed line to the output
|
| 1139 | $output .= $temp.$this->crlf;
|
| 1140 | }
|
| 1141 |
|
| 1142 | // get rid of extra CRLF tacked onto the end
|
| 1143 | $output = substr($output, 0, strlen($this->crlf) * -1);
|
| 1144 |
|
| 1145 | return $output;
|
| 1146 | }
|
| 1147 |
|
| 1148 | // --------------------------------------------------------------------
|
| 1149 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1150 | /**
|
| 1151 | * Send Email
|
| 1152 | *
|
| 1153 | * @access public
|
| 1154 | * @return bool
|
| 1155 | */
|
| 1156 | function send()
|
| 1157 | {
|
| 1158 | if ($this->_replyto_flag == FALSE)
|
| 1159 | {
|
| 1160 | $this->reply_to($this->_headers['From']);
|
| 1161 | }
|
| 1162 |
|
| 1163 | if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND
|
| 1164 | ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
|
| 1165 | ( ! isset($this->_headers['Cc'])))
|
| 1166 | {
|
| 1167 | $this->_set_error_message('email_no_recipients');
|
| 1168 | return FALSE;
|
| 1169 | }
|
| 1170 |
|
| 1171 | $this->_build_headers();
|
| 1172 |
|
| 1173 | if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0)
|
| 1174 | {
|
| 1175 | if (count($this->_bcc_array) > $this->bcc_batch_size)
|
| 1176 | return $this->batch_bcc_send();
|
| 1177 | }
|
| 1178 |
|
| 1179 | $this->_build_message();
|
| 1180 |
|
| 1181 | if ( ! $this->_spool_email())
|
| 1182 | return FALSE;
|
| 1183 | else
|
| 1184 | return TRUE;
|
| 1185 | }
|
| 1186 |
|
| 1187 | // --------------------------------------------------------------------
|
| 1188 |
|
| 1189 | /**
|
| 1190 | * Batch Bcc Send. Sends groups of BCCs in batches
|
| 1191 | *
|
| 1192 | * @access public
|
| 1193 | * @return bool
|
| 1194 | */
|
| 1195 | function batch_bcc_send()
|
| 1196 | {
|
| 1197 | $float = $this->bcc_batch_size -1;
|
| 1198 |
|
| 1199 | $flag = 0;
|
| 1200 | $set = "";
|
| 1201 |
|
| 1202 | $chunk = array();
|
| 1203 |
|
| 1204 | for ($i = 0; $i < count($this->_bcc_array); $i++)
|
| 1205 | {
|
| 1206 | if (isset($this->_bcc_array[$i]))
|
| 1207 | $set .= ", ".$this->_bcc_array[$i];
|
| 1208 |
|
| 1209 | if ($i == $float)
|
| 1210 | {
|
| 1211 | $chunk[] = substr($set, 1);
|
| 1212 | $float = $float + $this->bcc_batch_size;
|
| 1213 | $set = "";
|
| 1214 | }
|
| 1215 |
|
| 1216 | if ($i == count($this->_bcc_array)-1)
|
| 1217 | $chunk[] = substr($set, 1);
|
| 1218 | }
|
| 1219 |
|
| 1220 | for ($i = 0; $i < count($chunk); $i++)
|
| 1221 | {
|
| 1222 | unset($this->_headers['Bcc']);
|
| 1223 | unset($bcc);
|
| 1224 |
|
| 1225 | $bcc = $this->_str_to_array($chunk[$i]);
|
| 1226 | $bcc = $this->clean_email($bcc);
|
| 1227 |
|
| 1228 | if ($this->protocol != 'smtp')
|
| 1229 | $this->_set_header('Bcc', implode(", ", $bcc));
|
| 1230 | else
|
| 1231 | $this->_bcc_array = $bcc;
|
| 1232 |
|
| 1233 | $this->_build_message();
|
| 1234 | $this->_spool_email();
|
| 1235 | }
|
| 1236 | }
|
| 1237 |
|
| 1238 | // --------------------------------------------------------------------
|
| 1239 |
|
| 1240 | /**
|
| 1241 | * Unwrap special elements
|
| 1242 | *
|
| 1243 | * @access private
|
| 1244 | * @return void
|
| 1245 | */
|
| 1246 | function _unwrap_specials()
|
| 1247 | {
|
| 1248 | $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody);
|
| 1249 | }
|
| 1250 |
|
| 1251 | // --------------------------------------------------------------------
|
| 1252 |
|
| 1253 | /**
|
| 1254 | * Strip line-breaks via callback
|
| 1255 | *
|
| 1256 | * @access private
|
| 1257 | * @return string
|
| 1258 | */
|
| 1259 | function _remove_nl_callback($matches)
|
| 1260 | {
|
| 1261 | return preg_replace("/(\r\n)|(\r)|(\n)/", "", $matches['1']);
|
| 1262 | }
|
| 1263 |
|
| 1264 | // --------------------------------------------------------------------
|
| 1265 |
|
| 1266 | /**
|
| 1267 | * Spool mail to the mail server
|
| 1268 | *
|
| 1269 | * @access private
|
| 1270 | * @return bool
|
| 1271 | */
|
| 1272 | function _spool_email()
|
| 1273 | {
|
| 1274 | $this->_unwrap_specials();
|
| 1275 |
|
| 1276 | switch ($this->_get_protocol())
|
| 1277 | {
|
| 1278 | case 'mail' :
|
| 1279 |
|
| 1280 | if ( ! $this->_send_with_mail())
|
| 1281 | {
|
| 1282 | $this->_set_error_message('email_send_failure_phpmail');
|
| 1283 | return FALSE;
|
| 1284 | }
|
| 1285 | break;
|
| 1286 | case 'sendmail' :
|
| 1287 |
|
| 1288 | if ( ! $this->_send_with_sendmail())
|
| 1289 | {
|
| 1290 | $this->_set_error_message('email_send_failure_sendmail');
|
| 1291 | return FALSE;
|
| 1292 | }
|
| 1293 | break;
|
| 1294 | case 'smtp' :
|
| 1295 |
|
| 1296 | if ( ! $this->_send_with_smtp())
|
| 1297 | {
|
| 1298 | $this->_set_error_message('email_send_failure_smtp');
|
| 1299 | return FALSE;
|
| 1300 | }
|
| 1301 | break;
|
| 1302 |
|
| 1303 | }
|
| 1304 |
|
| 1305 | $this->_set_error_message('email_sent', $this->_get_protocol());
|
| 1306 | return true;
|
| 1307 | }
|
| 1308 |
|
| 1309 | // --------------------------------------------------------------------
|
| 1310 |
|
| 1311 | /**
|
| 1312 | * Send using mail()
|
| 1313 | *
|
| 1314 | * @access private
|
| 1315 | * @return bool
|
| 1316 | */
|
| 1317 | function _send_with_mail()
|
| 1318 | {
|
| 1319 | if ($this->_safe_mode == TRUE)
|
| 1320 | {
|
| 1321 | if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
|
| 1322 | return FALSE;
|
| 1323 | else
|
| 1324 | return TRUE;
|
| 1325 | }
|
| 1326 | else
|
| 1327 | {
|
| 1328 | if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f".$this->clean_email($this->_headers['From'])))
|
| 1329 | return FALSE;
|
| 1330 | else
|
| 1331 | return TRUE;
|
| 1332 | }
|
| 1333 | }
|
| 1334 |
|
| 1335 | // --------------------------------------------------------------------
|
| 1336 |
|
| 1337 | /**
|
| 1338 | * Send using Sendmail
|
| 1339 | *
|
| 1340 | * @access private
|
| 1341 | * @return bool
|
| 1342 | */
|
| 1343 | function _send_with_sendmail()
|
| 1344 | {
|
| 1345 | $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
|
| 1346 |
|
| 1347 | if ( ! is_resource($fp))
|
| 1348 | {
|
| 1349 | $this->_set_error_message('email_no_socket');
|
| 1350 | return FALSE;
|
| 1351 | }
|
| 1352 |
|
| 1353 | fputs($fp, $this->_header_str);
|
| 1354 | fputs($fp, $this->_finalbody);
|
| 1355 | pclose($fp) >> 8 & 0xFF;
|
| 1356 |
|
| 1357 | return TRUE;
|
| 1358 | }
|
| 1359 |
|
| 1360 | // --------------------------------------------------------------------
|
| 1361 |
|
| 1362 | /**
|
| 1363 | * Send using SMTP
|
| 1364 | *
|
| 1365 | * @access private
|
| 1366 | * @return bool
|
| 1367 | */
|
| 1368 | function _send_with_smtp()
|
| 1369 | {
|
| 1370 | if ($this->smtp_host == '')
|
| 1371 | {
|
| 1372 | $this->_set_error_message('email_no_hostname');
|
| 1373 | return FALSE;
|
| 1374 | }
|
| 1375 |
|
| 1376 | $this->_smtp_connect();
|
| 1377 | $this->_smtp_authenticate();
|
| 1378 |
|
| 1379 | $this->_send_command('from', $this->clean_email($this->_headers['From']));
|
| 1380 |
|
| 1381 | foreach($this->_recipients as $val)
|
| 1382 | $this->_send_command('to', $val);
|
| 1383 |
|
| 1384 | if (count($this->_cc_array) > 0)
|
| 1385 | {
|
| 1386 | foreach($this->_cc_array as $val)
|
| 1387 | {
|
| 1388 | if ($val != "")
|
| 1389 | $this->_send_command('to', $val);
|
| 1390 | }
|
| 1391 | }
|
| 1392 |
|
| 1393 | if (count($this->_bcc_array) > 0)
|
| 1394 | {
|
| 1395 | foreach($this->_bcc_array as $val)
|
| 1396 | {
|
| 1397 | if ($val != "")
|
| 1398 | $this->_send_command('to', $val);
|
| 1399 | }
|
| 1400 | }
|
| 1401 |
|
| 1402 | $this->_send_command('data');
|
| 1403 |
|
| 1404 | $this->_send_data($this->_header_str . $this->_finalbody);
|
| 1405 |
|
| 1406 | $this->_send_data('.');
|
| 1407 |
|
| 1408 | $reply = $this->_get_smtp_data();
|
| 1409 |
|
| 1410 | $this->_set_error_message($reply);
|
| 1411 |
|
| 1412 | if (substr($reply, 0, 3) != '250')
|
| 1413 | {
|
| 1414 | $this->_set_error_message('email_smtp_error', $reply);
|
| 1415 | return FALSE;
|
| 1416 | }
|
| 1417 |
|
| 1418 | $this->_send_command('quit');
|
| 1419 | return true;
|
| 1420 | }
|
| 1421 |
|
| 1422 | // --------------------------------------------------------------------
|
| 1423 |
|
| 1424 | /**
|
| 1425 | * SMTP Connect
|
| 1426 | *
|
| 1427 | * @access public
|
| 1428 | * @param string
|
| 1429 | * @return string
|
| 1430 | */
|
| 1431 | function _smtp_connect()
|
| 1432 | {
|
| 1433 |
|
| 1434 | $this->_smtp_connect = fsockopen($this->smtp_host,
|
| 1435 | $this->smtp_port,
|
| 1436 | $errno,
|
| 1437 | $errstr,
|
| 1438 | $this->smtp_timeout);
|
| 1439 |
|
| 1440 | if( ! is_resource($this->_smtp_connect))
|
| 1441 | {
|
| 1442 | $this->_set_error_message('email_smtp_error', $errno." ".$errstr);
|
| 1443 | return FALSE;
|
| 1444 | }
|
| 1445 |
|
| 1446 | $this->_set_error_message($this->_get_smtp_data());
|
| 1447 | return $this->_send_command('hello');
|
| 1448 | }
|
| 1449 |
|
| 1450 | // --------------------------------------------------------------------
|
| 1451 |
|
| 1452 | /**
|
| 1453 | * Send SMTP command
|
| 1454 | *
|
| 1455 | * @access private
|
| 1456 | * @param string
|
| 1457 | * @param string
|
| 1458 | * @return string
|
| 1459 | */
|
| 1460 | function _send_command($cmd, $data = '')
|
| 1461 | {
|
| 1462 | switch ($cmd)
|
| 1463 | {
|
| 1464 | case 'hello' :
|
| 1465 |
|
| 1466 | if ($this->_smtp_auth OR $this->_get_encoding() == '8bit')
|
| 1467 | $this->_send_data('EHLO '.$this->_get_hostname());
|
| 1468 | else
|
| 1469 | $this->_send_data('HELO '.$this->_get_hostname());
|
| 1470 |
|
| 1471 | $resp = 250;
|
| 1472 | break;
|
| 1473 | case 'from' :
|
| 1474 |
|
| 1475 | $this->_send_data('MAIL FROM:<'.$data.'>');
|
| 1476 |
|
| 1477 | $resp = 250;
|
| 1478 | break;
|
| 1479 | case 'to' :
|
| 1480 |
|
| 1481 | $this->_send_data('RCPT TO:<'.$data.'>');
|
| 1482 |
|
| 1483 | $resp = 250;
|
| 1484 | break;
|
| 1485 | case 'data' :
|
| 1486 |
|
| 1487 | $this->_send_data('DATA');
|
| 1488 |
|
| 1489 | $resp = 354;
|
| 1490 | break;
|
| 1491 | case 'quit' :
|
| 1492 |
|
| 1493 | $this->_send_data('QUIT');
|
| 1494 |
|
| 1495 | $resp = 221;
|
| 1496 | break;
|
| 1497 | }
|
| 1498 |
|
| 1499 | $reply = $this->_get_smtp_data();
|
| 1500 |
|
| 1501 | $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>";
|
| 1502 |
|
| 1503 | if (substr($reply, 0, 3) != $resp)
|
| 1504 | {
|
| 1505 | $this->_set_error_message('email_smtp_error', $reply);
|
| 1506 | return FALSE;
|
| 1507 | }
|
| 1508 |
|
| 1509 | if ($cmd == 'quit')
|
| 1510 | fclose($this->_smtp_connect);
|
| 1511 |
|
| 1512 | return true;
|
| 1513 | }
|
| 1514 |
|
| 1515 | // --------------------------------------------------------------------
|
| 1516 |
|
| 1517 | /**
|
| 1518 | * SMTP Authenticate
|
| 1519 | *
|
| 1520 | * @access private
|
| 1521 | * @return bool
|
| 1522 | */
|
| 1523 | function _smtp_authenticate()
|
| 1524 | {
|
| 1525 | if ( ! $this->_smtp_auth)
|
| 1526 | return true;
|
| 1527 |
|
| 1528 | if ($this->smtp_user == "" AND $this->smtp_pass == "")
|
| 1529 | {
|
| 1530 | $this->_set_error_message('email_no_smtp_unpw');
|
| 1531 | return FALSE;
|
| 1532 | }
|
| 1533 |
|
| 1534 | $this->_send_data('AUTH LOGIN');
|
| 1535 |
|
| 1536 | $reply = $this->_get_smtp_data();
|
| 1537 |
|
| 1538 | if (substr($reply, 0, 3) != '334')
|
| 1539 | {
|
| 1540 | $this->_set_error_message('email_filed_smtp_login', $reply);
|
| 1541 | return FALSE;
|
| 1542 | }
|
| 1543 |
|
| 1544 | $this->_send_data(base64_encode($this->smtp_user));
|
| 1545 |
|
| 1546 | $reply = $this->_get_smtp_data();
|
| 1547 |
|
| 1548 | if (substr($reply, 0, 3) != '334')
|
| 1549 | {
|
| 1550 | $this->_set_error_message('email_smtp_auth_un', $reply);
|
| 1551 | return FALSE;
|
| 1552 | }
|
| 1553 |
|
| 1554 | $this->_send_data(base64_encode($this->smtp_pass));
|
| 1555 |
|
| 1556 | $reply = $this->_get_smtp_data();
|
| 1557 |
|
| 1558 | if (substr($reply, 0, 3) != '235')
|
| 1559 | {
|
| 1560 | $this->_set_error_message('email_smtp_auth_pw', $reply);
|
| 1561 | return FALSE;
|
| 1562 | }
|
| 1563 |
|
| 1564 | return true;
|
| 1565 | }
|
| 1566 |
|
| 1567 | // --------------------------------------------------------------------
|
| 1568 |
|
| 1569 | /**
|
| 1570 | * Send SMTP data
|
| 1571 | *
|
| 1572 | * @access private
|
| 1573 | * @return bool
|
| 1574 | */
|
| 1575 | function _send_data($data)
|
| 1576 | {
|
| 1577 | if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
|
| 1578 | {
|
| 1579 | $this->_set_error_message('email_smtp_data_failure', $data);
|
| 1580 | return FALSE;
|
| 1581 | }
|
| 1582 | else
|
| 1583 | return true;
|
| 1584 | }
|
| 1585 |
|
| 1586 | // --------------------------------------------------------------------
|
| 1587 |
|
| 1588 | /**
|
| 1589 | * Get SMTP data
|
| 1590 | *
|
| 1591 | * @access private
|
| 1592 | * @return string
|
| 1593 | */
|
| 1594 | function _get_smtp_data()
|
| 1595 | {
|
| 1596 | $data = "";
|
| 1597 |
|
| 1598 | while ($str = fgets($this->_smtp_connect, 512))
|
| 1599 | {
|
| 1600 | $data .= $str;
|
| 1601 |
|
| 1602 | if (substr($str, 3, 1) == " ")
|
| 1603 | break;
|
| 1604 | }
|
| 1605 |
|
| 1606 | return $data;
|
| 1607 | }
|
| 1608 |
|
| 1609 | // --------------------------------------------------------------------
|
| 1610 |
|
| 1611 | /**
|
| 1612 | * Get Hostname
|
| 1613 | *
|
| 1614 | * @access private
|
| 1615 | * @return string
|
| 1616 | */
|
| 1617 | function _get_hostname()
|
| 1618 | {
|
| 1619 | return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain';
|
| 1620 | }
|
| 1621 |
|
| 1622 | // --------------------------------------------------------------------
|
| 1623 |
|
| 1624 | /**
|
| 1625 | * Get IP
|
| 1626 | *
|
| 1627 | * @access private
|
| 1628 | * @return string
|
| 1629 | */
|
| 1630 | function _get_ip()
|
| 1631 | {
|
| 1632 | if ($this->_IP !== FALSE)
|
| 1633 | {
|
| 1634 | return $this->_IP;
|
| 1635 | }
|
| 1636 |
|
| 1637 | $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
|
| 1638 | $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
|
| 1639 | $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
|
| 1640 |
|
| 1641 | if ($cip && $rip) $this->_IP = $cip;
|
| 1642 | elseif ($rip) $this->_IP = $rip;
|
| 1643 | elseif ($cip) $this->_IP = $cip;
|
| 1644 | elseif ($fip) $this->_IP = $fip;
|
| 1645 |
|
| 1646 | if (strstr($this->_IP, ','))
|
| 1647 | {
|
| 1648 | $x = explode(',', $this->_IP);
|
| 1649 | $this->_IP = end($x);
|
| 1650 | }
|
| 1651 |
|
| 1652 | if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
|
| 1653 | $this->_IP = '0.0.0.0';
|
| 1654 |
|
| 1655 | unset($cip);
|
| 1656 | unset($rip);
|
| 1657 | unset($fip);
|
| 1658 |
|
| 1659 | return $this->_IP;
|
| 1660 | }
|
| 1661 |
|
| 1662 | // --------------------------------------------------------------------
|
| 1663 |
|
| 1664 | /**
|
| 1665 | * Get Debug Message
|
| 1666 | *
|
| 1667 | * @access public
|
| 1668 | * @return string
|
| 1669 | */
|
| 1670 | function print_debugger()
|
| 1671 | {
|
| 1672 | $msg = '';
|
| 1673 |
|
| 1674 | if (count($this->_debug_msg) > 0)
|
| 1675 | {
|
| 1676 | foreach ($this->_debug_msg as $val)
|
| 1677 | {
|
| 1678 | $msg .= $val;
|
| 1679 | }
|
| 1680 | }
|
| 1681 |
|
Derek Jones | 2d2437e | 2007-07-12 11:32:37 +0000 | [diff] [blame] | 1682 | $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>';
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1683 | return $msg;
|
| 1684 | }
|
| 1685 |
|
| 1686 | // --------------------------------------------------------------------
|
| 1687 |
|
| 1688 | /**
|
| 1689 | * Set Message
|
| 1690 | *
|
| 1691 | * @access public
|
| 1692 | * @param string
|
| 1693 | * @return string
|
| 1694 | */
|
| 1695 | function _set_error_message($msg, $val = '')
|
| 1696 | {
|
| 1697 | $CI =& get_instance();
|
| 1698 | $CI->lang->load('email');
|
| 1699 |
|
| 1700 | if (FALSE === ($line = $CI->lang->line($msg)))
|
| 1701 | {
|
| 1702 | $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />";
|
| 1703 | }
|
| 1704 | else
|
| 1705 | {
|
| 1706 | $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />";
|
| 1707 | }
|
| 1708 | }
|
| 1709 |
|
| 1710 | // --------------------------------------------------------------------
|
| 1711 |
|
| 1712 | /**
|
| 1713 | * Mime Types
|
| 1714 | *
|
| 1715 | * @access private
|
| 1716 | * @param string
|
| 1717 | * @return string
|
| 1718 | */
|
| 1719 | function _mime_types($ext = "")
|
| 1720 | {
|
| 1721 | $mimes = array( 'hqx' => 'application/mac-binhex40',
|
| 1722 | 'cpt' => 'application/mac-compactpro',
|
| 1723 | 'doc' => 'application/msword',
|
| 1724 | 'bin' => 'application/macbinary',
|
| 1725 | 'dms' => 'application/octet-stream',
|
| 1726 | 'lha' => 'application/octet-stream',
|
| 1727 | 'lzh' => 'application/octet-stream',
|
| 1728 | 'exe' => 'application/octet-stream',
|
| 1729 | 'class' => 'application/octet-stream',
|
| 1730 | 'psd' => 'application/octet-stream',
|
| 1731 | 'so' => 'application/octet-stream',
|
| 1732 | 'sea' => 'application/octet-stream',
|
| 1733 | 'dll' => 'application/octet-stream',
|
| 1734 | 'oda' => 'application/oda',
|
| 1735 | 'pdf' => 'application/pdf',
|
| 1736 | 'ai' => 'application/postscript',
|
| 1737 | 'eps' => 'application/postscript',
|
| 1738 | 'ps' => 'application/postscript',
|
| 1739 | 'smi' => 'application/smil',
|
| 1740 | 'smil' => 'application/smil',
|
| 1741 | 'mif' => 'application/vnd.mif',
|
| 1742 | 'xls' => 'application/vnd.ms-excel',
|
| 1743 | 'ppt' => 'application/vnd.ms-powerpoint',
|
| 1744 | 'wbxml' => 'application/vnd.wap.wbxml',
|
| 1745 | 'wmlc' => 'application/vnd.wap.wmlc',
|
| 1746 | 'dcr' => 'application/x-director',
|
| 1747 | 'dir' => 'application/x-director',
|
| 1748 | 'dxr' => 'application/x-director',
|
| 1749 | 'dvi' => 'application/x-dvi',
|
| 1750 | 'gtar' => 'application/x-gtar',
|
| 1751 | 'php' => 'application/x-httpd-php',
|
| 1752 | 'php4' => 'application/x-httpd-php',
|
| 1753 | 'php3' => 'application/x-httpd-php',
|
| 1754 | 'phtml' => 'application/x-httpd-php',
|
| 1755 | 'phps' => 'application/x-httpd-php-source',
|
| 1756 | 'js' => 'application/x-javascript',
|
| 1757 | 'swf' => 'application/x-shockwave-flash',
|
| 1758 | 'sit' => 'application/x-stuffit',
|
| 1759 | 'tar' => 'application/x-tar',
|
| 1760 | 'tgz' => 'application/x-tar',
|
| 1761 | 'xhtml' => 'application/xhtml+xml',
|
| 1762 | 'xht' => 'application/xhtml+xml',
|
| 1763 | 'zip' => 'application/zip',
|
| 1764 | 'mid' => 'audio/midi',
|
| 1765 | 'midi' => 'audio/midi',
|
| 1766 | 'mpga' => 'audio/mpeg',
|
| 1767 | 'mp2' => 'audio/mpeg',
|
| 1768 | 'mp3' => 'audio/mpeg',
|
| 1769 | 'aif' => 'audio/x-aiff',
|
| 1770 | 'aiff' => 'audio/x-aiff',
|
| 1771 | 'aifc' => 'audio/x-aiff',
|
| 1772 | 'ram' => 'audio/x-pn-realaudio',
|
| 1773 | 'rm' => 'audio/x-pn-realaudio',
|
| 1774 | 'rpm' => 'audio/x-pn-realaudio-plugin',
|
| 1775 | 'ra' => 'audio/x-realaudio',
|
| 1776 | 'rv' => 'video/vnd.rn-realvideo',
|
| 1777 | 'wav' => 'audio/x-wav',
|
| 1778 | 'bmp' => 'image/bmp',
|
| 1779 | 'gif' => 'image/gif',
|
| 1780 | 'jpeg' => 'image/jpeg',
|
| 1781 | 'jpg' => 'image/jpeg',
|
| 1782 | 'jpe' => 'image/jpeg',
|
| 1783 | 'png' => 'image/png',
|
| 1784 | 'tiff' => 'image/tiff',
|
| 1785 | 'tif' => 'image/tiff',
|
| 1786 | 'css' => 'text/css',
|
| 1787 | 'html' => 'text/html',
|
| 1788 | 'htm' => 'text/html',
|
| 1789 | 'shtml' => 'text/html',
|
| 1790 | 'txt' => 'text/plain',
|
| 1791 | 'text' => 'text/plain',
|
| 1792 | 'log' => 'text/plain',
|
| 1793 | 'rtx' => 'text/richtext',
|
| 1794 | 'rtf' => 'text/rtf',
|
| 1795 | 'xml' => 'text/xml',
|
| 1796 | 'xsl' => 'text/xml',
|
| 1797 | 'mpeg' => 'video/mpeg',
|
| 1798 | 'mpg' => 'video/mpeg',
|
| 1799 | 'mpe' => 'video/mpeg',
|
| 1800 | 'qt' => 'video/quicktime',
|
| 1801 | 'mov' => 'video/quicktime',
|
| 1802 | 'avi' => 'video/x-msvideo',
|
| 1803 | 'movie' => 'video/x-sgi-movie',
|
| 1804 | 'doc' => 'application/msword',
|
| 1805 | 'word' => 'application/msword',
|
| 1806 | 'xl' => 'application/excel',
|
| 1807 | 'eml' => 'message/rfc822'
|
| 1808 | );
|
| 1809 |
|
| 1810 | return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
|
| 1811 | }
|
| 1812 |
|
| 1813 | }
|
| 1814 | // END CI_Email class
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1815 | ?> |