Email.php class for Frog CMS


/ Published in: PHP
Save to your folder(s)



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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.