MasOne

Untitled

Dec 22nd, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.84 KB | None | 0 0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed.');
  2.  
  3. /**
  4. * CodeIgniter compatible email-library powered by PHPMailer.
  5. * Version: 1.1.2
  6. * @author Ivan Tcholakov <ivantcholakov@gmail.com>, 2012-2014.
  7. * @license The MIT License (MIT), http://opensource.org/licenses/MIT
  8. * @link https://github.com/ivantcholakov/codeigniter-phpmailer
  9. *
  10. * Tested on production sites with CodeIgniter 3.0-dev (February 12th, 2014) and
  11. * PHPMailer Version 5.2.7 (September 12th, 2013).
  12. */
  13.  
  14. class MY_Email extends CI_Email {
  15.  
  16. protected $mailer_engine = 'codeigniter';
  17. protected $phpmailer;
  18. protected $CI;
  19.  
  20. protected $_is_ci_3 = NULL;
  21.  
  22. protected static $protocols = array('mail', 'sendmail', 'smtp');
  23. protected static $mailtypes = array('html', 'text');
  24.  
  25. public function __construct($config = array()) {
  26.  
  27. $this->_is_ci_3 = (bool) ((int) CI_VERSION >= 3);
  28.  
  29. $this->CI = get_instance();
  30. $this->CI->load->helper('email');
  31. $this->CI->load->helper('html');
  32.  
  33. if (!is_array($config)) {
  34. $config = array();
  35. }
  36.  
  37. if (isset($config['useragent'])) {
  38.  
  39. $useragent = trim($config['useragent']);
  40. $mailer_engine = strtolower($useragent);
  41.  
  42. if (strpos($mailer_engine, 'phpmailer') !== false) {
  43. $this->mailer_engine = 'phpmailer';
  44. } elseif(strpos($mailer_engine, 'codeigniter') !== false) {
  45. $this->mailer_engine = 'codeigniter';
  46. } else {
  47. unset($config['useragent']); // An invalid setting;
  48. }
  49. }
  50.  
  51. if (isset($config['charset'])) {
  52.  
  53. $charset = trim($config['charset']);
  54.  
  55. if ($charset != '') {
  56. $this->charset = $charset;
  57. unset($config['charset']); // We don't need this anymore.
  58. }
  59.  
  60. } else {
  61.  
  62. $charset = trim(config_item('charset'));
  63.  
  64. if ($charset != '') {
  65. $this->charset = $charset;
  66. }
  67. }
  68.  
  69. $this->charset = strtoupper($this->charset);
  70.  
  71. if ($this->mailer_engine == 'phpmailer') {
  72.  
  73. // If your system uses class autoloading feature,
  74. // then the following require statement would not be needed.
  75. if (!class_exists('PHPMailer', false)) {
  76. require_once APPPATH.'third_party/phpmailer/PHPMailerAutoload.php';
  77. }
  78. //
  79.  
  80. $this->phpmailer = new PHPMailer();
  81. $this->phpmailer->PluginDir = APPPATH.'third_party/phpmailer/';
  82.  
  83. $this->_copy_property_to_phpmailer('charset');
  84. }
  85.  
  86. if (count($config) > 0) {
  87.  
  88. $this->initialize($config);
  89.  
  90. } else {
  91.  
  92. $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
  93.  
  94. if ($this->mailer_engine == 'phpmailer') {
  95. $this->_copy_property_to_phpmailer('_smtp_auth');
  96. }
  97. }
  98.  
  99. $this->_safe_mode = ( ! is_php('5.4') && (bool) @ini_get('safe_mode'));
  100.  
  101. log_message('debug', 'MY_Email Class Initialized (Engine: '.$this->mailer_engine.')');
  102. }
  103.  
  104. /**
  105. * Define these options within the $config array or
  106. * within the configuration file email.php:
  107. * useragent
  108. * protocol
  109. * mailpath
  110. * smtp_host
  111. * smtp_user
  112. * smtp_pass
  113. * smtp_port
  114. * smtp_timeout
  115. * smtp_crypto
  116. * set_wordwrap
  117. * wrapchars
  118. * mailtype
  119. * charset
  120. * validate
  121. * priority
  122. * crlf
  123. * newline
  124. * bcc_batch_mode
  125. * bcc_batch_size
  126. */
  127. public function initialize($config = array()) {
  128.  
  129. if (!is_array($config)) {
  130. $config = array();
  131. }
  132.  
  133. foreach ($config as $key => $val) {
  134.  
  135. $method = 'set_'.$key;
  136.  
  137. if (method_exists($this, $method)) {
  138.  
  139. $this->$method($val);
  140.  
  141. } elseif (isset($this->$key)) {
  142.  
  143. $this->$key = $val;
  144.  
  145. if ($this->mailer_engine == 'phpmailer') {
  146. $this->_copy_property_to_phpmailer($key);
  147. }
  148. }
  149. }
  150.  
  151. $this->clear();
  152.  
  153. $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
  154.  
  155. if ($this->mailer_engine == 'phpmailer') {
  156. $this->_copy_property_to_phpmailer('_smtp_auth');
  157. }
  158.  
  159. return $this;
  160. }
  161.  
  162. public function clear($clear_attachments = false) {
  163.  
  164. $clear_attachments = !empty($clear_attachments);
  165.  
  166. parent::clear($clear_attachments);
  167.  
  168. if ($this->mailer_engine == 'phpmailer') {
  169.  
  170. $this->phpmailer->clearAllRecipients();
  171. $this->phpmailer->clearReplyTos();
  172. if ($clear_attachments) {
  173. $this->phpmailer->clearAttachments();
  174. }
  175.  
  176. $this->phpmailer->clearCustomHeaders();
  177.  
  178. $this->phpmailer->Subject = '';
  179. $this->phpmailer->Body = '';
  180. $this->phpmailer->AltBody = '';
  181. }
  182.  
  183. return $this;
  184. }
  185.  
  186. public function set_protocol($protocol = 'mail') {
  187.  
  188. $protocol = trim(strtolower($protocol));
  189.  
  190. $this->protocol = in_array($protocol, self::$protocols) ? $protocol : 'mail';
  191.  
  192. if ($this->mailer_engine == 'phpmailer') {
  193.  
  194. switch ($this->protocol) {
  195.  
  196. case 'mail':
  197. $this->phpmailer->isMail();
  198. break;
  199.  
  200. case 'sendmail':
  201. $this->phpmailer->isSendmail();
  202. break;
  203.  
  204. case 'smtp':
  205. $this->phpmailer->isSMTP();
  206. break;
  207. }
  208. }
  209.  
  210. return $this;
  211. }
  212.  
  213. public function set_smtp_crypto($smtp_crypto = '') {
  214.  
  215. $smtp_crypto = trim(strtolower($smtp_crypto));
  216.  
  217. if ($smtp_crypto != 'tls' && $smtp_crypto != 'ssl') {
  218. $smtp_crypto = '';
  219. }
  220.  
  221. $this->smtp_crypto = $smtp_crypto;
  222.  
  223. if ($this->mailer_engine == 'phpmailer') {
  224. $this->phpmailer->set('SMTPSecure', $smtp_crypto);
  225. }
  226.  
  227. return $this;
  228. }
  229.  
  230. public function set_wordwrap($wordwrap = TRUE) {
  231.  
  232. $this->wordwrap = !empty($wordwrap);
  233.  
  234. if (!$this->wordwrap) {
  235.  
  236. if ($this->mailer_engine == 'phpmailer') {
  237. $this->phpmailer->set('WordWrap', 0);
  238. }
  239. }
  240.  
  241. return $this;
  242. }
  243.  
  244. public function set_mailtype($type = 'text') {
  245.  
  246. $type = trim(strtolower($type));
  247.  
  248. $this->mailtype = in_array($type, self::$mailtypes) ? $type : 'text';
  249.  
  250. if ($this->mailer_engine == 'phpmailer') {
  251. $this->phpmailer->isHTML($this->mailtype == 'html');
  252. }
  253.  
  254. return $this;
  255. }
  256.  
  257. public function set_priority($n = 3) {
  258.  
  259. $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3;
  260.  
  261. if ($this->mailer_engine == 'phpmailer') {
  262. $this->phpmailer->set('Priority', $this->priority);
  263. }
  264.  
  265. return $this;
  266. }
  267.  
  268. public function valid_email($email) {
  269.  
  270. return valid_email($email);
  271. }
  272.  
  273. public function from($from, $name = '', $return_path = NULL) {
  274.  
  275. $from = (string) $from;
  276. $name = (string) $name;
  277. $return_path = (string) $return_path;
  278.  
  279. if ($this->mailer_engine == 'phpmailer') {
  280.  
  281. if (preg_match( '/\<(.*)\>/', $from, $match)) {
  282. $from = $match['1'];
  283. }
  284.  
  285. if ($this->validate) {
  286.  
  287. $this->validate_email($this->_str_to_array($from));
  288.  
  289. if ($return_path) {
  290. $this->validate_email($this->_str_to_array($return_path));
  291. }
  292. }
  293.  
  294. $this->phpmailer->setFrom($from, $name, 0);
  295.  
  296. if (!$return_path) {
  297. $return_path = $from;
  298. }
  299.  
  300. $this->phpmailer->set('Sender', $return_path);
  301.  
  302. } else {
  303.  
  304. if ($this->_is_ci_3) {
  305. parent::from($from, $name, $return_path);
  306. } else {
  307. parent::from($from, $name);
  308. }
  309. }
  310.  
  311. return $this;
  312. }
  313.  
  314. public function reply_to($replyto, $name = '') {
  315.  
  316. $replyto = (string) $replyto;
  317. $name = (string) $name;
  318.  
  319. if ($this->mailer_engine == 'phpmailer') {
  320.  
  321. if (preg_match( '/\<(.*)\>/', $replyto, $match)) {
  322. $replyto = $match['1'];
  323. }
  324.  
  325. if ($this->validate) {
  326. $this->validate_email($this->_str_to_array($replyto));
  327. }
  328.  
  329. if ($name == '') {
  330. $name = $replyto;
  331. }
  332.  
  333. $this->phpmailer->addReplyTo($replyto, $name);
  334.  
  335. $this->_replyto_flag = TRUE;
  336.  
  337. } else {
  338.  
  339. parent::reply_to($replyto, $name);
  340. }
  341.  
  342. return $this;
  343. }
  344.  
  345. public function to($to) {
  346.  
  347. if ($this->mailer_engine == 'phpmailer') {
  348.  
  349. $to = $this->_str_to_array($to);
  350. $names = $this->_extract_name($to);
  351. $to = $this->clean_email($to);
  352.  
  353. if ($this->validate) {
  354. $this->validate_email($to);
  355. }
  356.  
  357. reset($names);
  358.  
  359. foreach ($to as $address) {
  360.  
  361. list($key, $name) = each($names);
  362. $this->phpmailer->addAddress($address, $name);
  363. }
  364.  
  365. } else {
  366.  
  367. parent::to($to);
  368. }
  369.  
  370. return $this;
  371. }
  372.  
  373. public function cc($cc) {
  374.  
  375. if ($this->mailer_engine == 'phpmailer') {
  376.  
  377. $cc = $this->_str_to_array($cc);
  378. $names = $this->_extract_name($cc);
  379. $cc = $this->clean_email($cc);
  380.  
  381. if ($this->validate) {
  382. $this->validate_email($cc);
  383. }
  384.  
  385. reset($names);
  386.  
  387. foreach ($cc as $address) {
  388.  
  389. list($key, $name) = each($names);
  390. $this->phpmailer->addCC($address, $name);
  391. }
  392.  
  393. } else {
  394.  
  395. parent::cc($cc);
  396. }
  397.  
  398. return $this;
  399. }
  400.  
  401. public function bcc($bcc, $limit = '') {
  402.  
  403. if ($this->mailer_engine == 'phpmailer') {
  404.  
  405. $bcc = $this->_str_to_array($bcc);
  406. $names = $this->_extract_name($bcc);
  407. $bcc = $this->clean_email($bcc);
  408.  
  409. if ($this->validate) {
  410. $this->validate_email($bcc);
  411. }
  412.  
  413. reset($names);
  414.  
  415. foreach ($bcc as $address) {
  416.  
  417. list($key, $name) = each($names);
  418. $this->phpmailer->addBCC($address, $name);
  419. }
  420.  
  421. } else {
  422.  
  423. parent::bcc($bcc, $limit);
  424. }
  425.  
  426. return $this;
  427. }
  428.  
  429. public function subject($subject) {
  430.  
  431. $subject = (string) $subject;
  432.  
  433. if ($this->mailer_engine == 'phpmailer') {
  434.  
  435. $this->phpmailer->Subject = (string) $subject;
  436.  
  437. } else {
  438.  
  439. parent::subject($subject);
  440. }
  441.  
  442. return $this;
  443. }
  444.  
  445. public function message($body) {
  446.  
  447. $body = (string) $body;
  448.  
  449. if ($this->mailer_engine == 'phpmailer') {
  450.  
  451. $this->phpmailer->Body = $body;
  452. }
  453.  
  454. parent::message($body);
  455.  
  456. return $this;
  457. }
  458.  
  459. // Modified by Ivan Tcholakov, 16-JAN-2014.
  460. //public function attach($file, $disposition = '', $newname = NULL, $mime = '') {
  461. public function attach($file, $disposition = '', $newname = NULL, $mime = '', $embedded_image = false) {
  462. //
  463.  
  464. $file = (string) $file;
  465.  
  466. $disposition = (string) $disposition;
  467.  
  468. if ($disposition == '') {
  469. $disposition ='attachment';
  470. }
  471.  
  472. if ($this->mailer_engine == 'phpmailer') {
  473.  
  474. $newname = (string) $newname;
  475. $mime = (string) $mime;
  476.  
  477. if ($mime == '') {
  478.  
  479. if (strpos($file, '://') === FALSE && ! file_exists($file)) {
  480.  
  481. $this->_set_error_message('lang:email_attachment_missing', $file);
  482. // Modified by Ivan Tcholakov, 14-JAN-2014.
  483. //return FALSE;
  484. return $this;
  485. //
  486. }
  487.  
  488. if (!$fp = @fopen($file, FOPEN_READ)) {
  489.  
  490. $this->_set_error_message('lang:email_attachment_unreadable', $file);
  491. // Modified by Ivan Tcholakov, 14-JAN-2014.
  492. //return FALSE;
  493. return $this;
  494. //
  495. }
  496.  
  497. $file_content = stream_get_contents($fp);
  498. $mime = $this->_mime_types(pathinfo($file, PATHINFO_EXTENSION));
  499. fclose($fp);
  500.  
  501. $newname = basename($file);
  502.  
  503. } else {
  504.  
  505. $file_content =& $file; // Buffered file.
  506. // Added by Ivan Tcholakov, 14-JAN-2014.
  507. $file = $newname;
  508. //
  509. }
  510.  
  511. $this->_attachments[] = array(
  512. 'name' => array($file, $newname),
  513. 'disposition' => $disposition,
  514. 'type' => $mime,
  515. );
  516.  
  517. if (empty($embedded_image)) {
  518.  
  519. $this->phpmailer->addStringAttachment($file_content, $newname, 'base64', $mime, $disposition);
  520.  
  521. } else {
  522.  
  523. $cid = $this->attachment_cid($file);
  524. $this->phpmailer->addStringEmbeddedImage($file_content, $cid, $newname, 'base64', $mime, $disposition);
  525. }
  526.  
  527. } else {
  528.  
  529. if ($this->_is_ci_3) {
  530. parent::attach($file, $disposition, $newname, $mime);
  531. } else {
  532. parent::attach($file, $disposition);
  533. }
  534. }
  535.  
  536. return $this;
  537. }
  538.  
  539. public function attachment_cid($filename) {
  540.  
  541. if ($this->mailer_engine == 'phpmailer') {
  542.  
  543. for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) {
  544.  
  545. if ($this->_attachments[$i]['name'][0] === $filename) {
  546.  
  547. $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@');
  548. return $this->_attachments[$i]['cid'];
  549. }
  550. }
  551.  
  552. } elseif ($this->_is_ci_3) {
  553.  
  554. return parent::attachment_cid($filename);
  555. }
  556.  
  557. return FALSE;
  558. }
  559.  
  560. // Added by Ivan Tcholakov, 16-JAN-2014.
  561. public function get_attachment_cid($filename) {
  562.  
  563. for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) {
  564.  
  565. if ($this->_attachments[$i]['name'][0] === $filename) {
  566. return empty($this->_attachments[$i]['cid']) ? FALSE : $this->_attachments[$i]['cid'];
  567. }
  568. }
  569.  
  570. return FALSE;
  571. }
  572. //
  573.  
  574. public function send($auto_clear = true) {
  575.  
  576. $auto_clear = !empty($auto_clear);
  577.  
  578. if ($this->mailer_engine == 'phpmailer') {
  579.  
  580. if ($this->mailtype == 'html') {
  581. $this->phpmailer->AltBody = $this->_get_alt_message();
  582. }
  583.  
  584. $result = (bool) $this->phpmailer->send();
  585.  
  586. if ($result) {
  587.  
  588. $this->_set_error_message('lang:email_sent', $this->_get_protocol());
  589.  
  590. if ($auto_clear) {
  591. $this->clear();
  592. }
  593.  
  594. } else {
  595.  
  596. $this->_set_error_message($this->phpmailer->ErrorInfo);
  597. }
  598.  
  599. } else {
  600.  
  601. if ($this->_is_ci_3) {
  602. $result = parent::send($auto_clear);
  603. } else {
  604. $result = parent::send();
  605. }
  606. }
  607.  
  608. return $result;
  609. }
  610.  
  611.  
  612. // Custom methods ----------------------------------------------------------
  613.  
  614. // PHPMailer's SMTP debug info level
  615. // 0 = off, 1 = commands, 2 = commands and data
  616. public function set_smtp_debug($level) {
  617.  
  618. $level = (int) $level;
  619.  
  620. if ($level < 0 || $level > 2) {
  621. $level = 0;
  622. }
  623.  
  624. if ($this->mailer_engine == 'phpmailer') {
  625. $this->phpmailer->SMTPDebug = $level;
  626. }
  627.  
  628. return $this;
  629. }
  630.  
  631. public function full_html($subject, $message) {
  632.  
  633. $full_html =
  634. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  635. <html xmlns="http://www.w3.org/1999/xhtml">
  636. <head>
  637. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  638. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  639. <title>'.htmlspecialchars($subject, ENT_QUOTES, $this->charset).'</title>
  640.  
  641. <style type="text/css">
  642.  
  643. /* See http://htmlemailboilerplate.com/ */
  644.  
  645. /* Based on The MailChimp Reset INLINE: Yes. */
  646. /* Client-specific Styles */
  647. #outlook a {padding:0;} /* Force Outlook to provide a "view in browser" menu link. */
  648. body {
  649. width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:40px;
  650. font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 16px;
  651. }
  652. /* End reset */
  653.  
  654. /* Some sensible defaults for images
  655. Bring inline: Yes. */
  656. img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;}
  657. a img {border:none;}
  658.  
  659. /* Yahoo paragraph fix
  660. Bring inline: Yes. */
  661. p {margin: 1em 0;}
  662.  
  663. /* Hotmail header color reset
  664. Bring inline: Yes. */
  665. h1, h2, h3, h4, h5, h6 {color: black !important;}
  666.  
  667. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}
  668.  
  669. h1 a:active, h2 a:active, h3 a:active, h4 a:active, h5 a:active, h6 a:active {
  670. color: red !important; /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */
  671. }
  672.  
  673. h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {
  674. color: purple !important; /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */
  675. }
  676.  
  677. /* Outlook 07, 10 Padding issue fix
  678. Bring inline: No.*/
  679. table td {border-collapse: collapse;}
  680.  
  681. /* Remove spacing around Outlook 07, 10 tables
  682. Bring inline: Yes */
  683. table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }
  684.  
  685. /* Styling your links has become much simpler with the new Yahoo. In fact, it falls in line with the main credo of styling in email and make sure to bring your styles inline. Your link colors will be uniform across clients when brought inline.
  686. Bring inline: Yes. */
  687. a {color: blue;}
  688.  
  689. </style>
  690.  
  691. </head>
  692.  
  693. <body>
  694.  
  695. '.$message.'
  696.  
  697. </body>
  698. </html>';
  699.  
  700. return $full_html;
  701. }
  702.  
  703.  
  704. // Protected methods -------------------------------------------------------
  705.  
  706. protected function _get_alt_message() {
  707.  
  708. if (!empty($this->alt_message)) {
  709.  
  710. return ($this->wordwrap)
  711. ? $this->word_wrap($this->alt_message, 76)
  712. : $this->alt_message;
  713. }
  714.  
  715. $body = $this->_plain_text($this->_body);
  716.  
  717. return ($this->wordwrap)
  718. ? $this->word_wrap($body, 76)
  719. : $body;
  720. }
  721.  
  722. protected function _plain_text($html) {
  723.  
  724. if (!function_exists('html_to_text')) {
  725.  
  726. $body = @ html_entity_decode($html, ENT_QUOTES, $this->charset); // Added by Ivan Tcholakov, 28-JUL-2013.
  727.  
  728. $body = preg_match('/\<body.*?\>(.*)\<\/body\>/si', $body, $match) ? $match[1] : $body;
  729. $body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
  730.  
  731. for ($i = 20; $i >= 3; $i--)
  732. {
  733. $body = str_replace(str_repeat("\n", $i), "\n\n", $body);
  734. }
  735.  
  736. // Reduce multiple spaces
  737. $body = preg_replace('| +|', ' ', $body);
  738.  
  739. return $body;
  740. }
  741.  
  742. // Also, a special helper function based on Markdown or Textile libraries may be used.
  743. //
  744. // An example of Markdown-based implementation, see http://milianw.de/projects/markdownify/
  745. //
  746. // Make sure the class Markdownify_Extra is autoloaded (or simply loaded somehow).
  747. // Place in MY_html_helper.php the following function.
  748. //
  749. // function html_to_text($html) {
  750. // static $parser;
  751. // if (!isset($parser)) {
  752. // $parser = new Markdownify_Extra();
  753. // $parser->keepHTML = false;
  754. // }
  755. // return @ $parser->parseString($html);
  756. // }
  757. //
  758.  
  759. return html_to_text($html);
  760. }
  761.  
  762. protected function _copy_property_to_phpmailer($key) {
  763.  
  764. static $properties = array(
  765. '_smtp_auth' => 'SMTPAuth',
  766. 'mailpath' => 'Sendmail',
  767. 'smtp_host' => 'Host',
  768. 'smtp_user' => 'Username',
  769. 'smtp_pass' => 'Password',
  770. 'smtp_port' => 'Port',
  771. 'smtp_timeout' => 'Timeout',
  772. 'wrapchars' => 'WordWrap',
  773. 'charset' => 'CharSet',
  774. );
  775.  
  776. if (isset($properties[$key])) {
  777. $this->phpmailer->set($properties[$key], $this->$key);
  778. }
  779.  
  780. if ($key == 'wrapchars') {
  781.  
  782. if (!$this->wordwrap) {
  783. $this->phpmailer->set('WordWrap', 0);
  784. }
  785. }
  786. }
  787.  
  788. protected function _extract_name($address) {
  789.  
  790. if (!is_array($address)) {
  791.  
  792. $address = trim($address);
  793.  
  794. if (preg_match('/(.*)\<(.*)\>/', $address, $match)) {
  795. return trim($match['1']);
  796. } else {
  797. return '';
  798. }
  799. }
  800.  
  801. $result = array();
  802.  
  803. foreach ($address as $addr) {
  804.  
  805. $addr = trim($addr);
  806.  
  807. if (preg_match('/(.*)\<(.*)\>/', $addr, $match)) {
  808. $result[] = trim($match['1']);
  809. } else {
  810. $result[] = '';
  811. }
  812. }
  813.  
  814. return $result;
  815. }
  816.  
  817. }
Add Comment
Please, Sign In to add comment