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