PageRenderTime 56ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/applicationv2/libraries/v2/phpmailer/class.phpmailer.php

https://bitbucket.org/cschuette/grand-prix-tickets-gmbh-staging
PHP | 3391 lines | 2092 code | 216 blank | 1083 comment | 316 complexity | 65776ff39c853ac7bc0e80eb02cc0abf MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * PHPMailer - PHP email creation and transport class.
  4. * PHP Version 5.0.0
  5. * Version 5.2.7
  6. * @package PHPMailer
  7. * @link https://github.com/PHPMailer/PHPMailer/
  8. * @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
  9. * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
  10. * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
  11. * @author Brent R. Matzelle (original founder)
  12. * @copyright 2013 Marcus Bointon
  13. * @copyright 2010 - 2012 Jim Jagielski
  14. * @copyright 2004 - 2009 Andy Prevost
  15. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  16. * @note This program is distributed in the hope that it will be useful - WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE.
  19. */
  20. if (version_compare(PHP_VERSION, '5.0.0', '<')) {
  21. exit("Sorry, PHPMailer will only run on PHP version 5 or greater!\n");
  22. }
  23. /**
  24. * PHPMailer - PHP email creation and transport class.
  25. * PHP Version 5.0.0
  26. * @package PHPMailer
  27. * @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
  28. * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
  29. * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
  30. * @author Brent R. Matzelle (original founder)
  31. * @copyright 2013 Marcus Bointon
  32. * @copyright 2010 - 2012 Jim Jagielski
  33. * @copyright 2004 - 2009 Andy Prevost
  34. */
  35. class PHPMailer
  36. {
  37. /**
  38. * The PHPMailer Version number.
  39. * @type string
  40. */
  41. public $Version = '5.2.7';
  42. /**
  43. * Email priority.
  44. * Options: 1 = High, 3 = Normal, 5 = low.
  45. * @type int
  46. */
  47. public $Priority = 3;
  48. /**
  49. * The character set of the message.
  50. * @type string
  51. */
  52. public $CharSet = 'utf-8';
  53. /**
  54. * The MIME Content-type of the message.
  55. * @type string
  56. */
  57. public $ContentType = 'text/plain';
  58. /**
  59. * The message encoding.
  60. * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
  61. * @type string
  62. */
  63. public $Encoding = '8bit';
  64. /**
  65. * Holds the most recent mailer error message.
  66. * @type string
  67. */
  68. public $ErrorInfo = '';
  69. /**
  70. * The From email address for the message.
  71. * @type string
  72. */
  73. public $From = 'root@localhost';
  74. /**
  75. * The From name of the message.
  76. * @type string
  77. */
  78. public $FromName = 'Root User';
  79. /**
  80. * The Sender email (Return-Path) of the message.
  81. * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  82. * @type string
  83. */
  84. public $Sender = '';
  85. /**
  86. * The Return-Path of the message.
  87. * If empty, it will be set to either From or Sender.
  88. * @type string
  89. */
  90. public $ReturnPath = '';
  91. /**
  92. * The Subject of the message.
  93. * @type string
  94. */
  95. public $Subject = '';
  96. /**
  97. * An HTML or plain text message body.
  98. * If HTML then call isHTML(true).
  99. * @type string
  100. */
  101. public $Body = '';
  102. /**
  103. * The plain-text message body.
  104. * This body can be read by mail clients that do not have HTML email
  105. * capability such as mutt & Eudora.
  106. * Clients that can read HTML will view the normal Body.
  107. * @type string
  108. */
  109. public $AltBody = '';
  110. /**
  111. * An iCal message part body.
  112. * Only supported in simple alt or alt_inline message types
  113. * To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
  114. * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
  115. * @link http://kigkonsult.se/iCalcreator/
  116. * @type string
  117. */
  118. public $Ical = '';
  119. /**
  120. * The complete compiled MIME message body.
  121. * @access protected
  122. * @type string
  123. */
  124. protected $MIMEBody = '';
  125. /**
  126. * The complete compiled MIME message headers.
  127. * @type string
  128. * @access protected
  129. */
  130. protected $MIMEHeader = '';
  131. /**
  132. * Extra headers that createHeader() doesn't fold in.
  133. * @type string
  134. * @access protected
  135. */
  136. protected $mailHeader = '';
  137. /**
  138. * Word-wrap the message body to this number of chars.
  139. * @type int
  140. */
  141. public $WordWrap = 0;
  142. /**
  143. * Which method to use to send mail.
  144. * Options: "mail", "sendmail", or "smtp".
  145. * @type string
  146. */
  147. public $Mailer = 'mail';
  148. /**
  149. * The path to the sendmail program.
  150. * @type string
  151. */
  152. public $Sendmail = '/usr/sbin/sendmail';
  153. /**
  154. * Whether mail() uses a fully sendmail-compatible MTA.
  155. * One which supports sendmail's "-oi -f" options.
  156. * @type bool
  157. */
  158. public $UseSendmailOptions = true;
  159. /**
  160. * Path to PHPMailer plugins.
  161. * Useful if the SMTP class is not in the PHP include path.
  162. * @type string
  163. * @deprecated Should not be needed now there is an autoloader.
  164. */
  165. public $PluginDir = '';
  166. /**
  167. * The email address that a reading confirmation should be sent to.
  168. * @type string
  169. */
  170. public $ConfirmReadingTo = '';
  171. /**
  172. * The hostname to use in Message-Id and Received headers
  173. * and as default HELO string.
  174. * If empty, the value returned
  175. * by SERVER_NAME is used or 'localhost.localdomain'.
  176. * @type string
  177. */
  178. public $Hostname = '';
  179. /**
  180. * An ID to be used in the Message-Id header.
  181. * If empty, a unique id will be generated.
  182. * @type string
  183. */
  184. public $MessageID = '';
  185. /**
  186. * The message Date to be used in the Date header.
  187. * If empty, the current date will be added.
  188. * @type string
  189. */
  190. public $MessageDate = '';
  191. /**
  192. * SMTP hosts.
  193. * Either a single hostname or multiple semicolon-delimited hostnames.
  194. * You can also specify a different port
  195. * for each host by using this format: [hostname:port]
  196. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  197. * Hosts will be tried in order.
  198. * @type string
  199. */
  200. public $Host = 'localhost';
  201. /**
  202. * The default SMTP server port.
  203. * @type int
  204. * @Todo Why is this needed when the SMTP class takes care of it?
  205. */
  206. public $Port = 25;
  207. /**
  208. * The SMTP HELO of the message.
  209. * Default is $Hostname.
  210. * @type string
  211. * @see PHPMailer::$Hostname
  212. */
  213. public $Helo = '';
  214. /**
  215. * The secure connection prefix.
  216. * Options: "", "ssl" or "tls"
  217. * @type string
  218. */
  219. public $SMTPSecure = '';
  220. /**
  221. * Whether to use SMTP authentication.
  222. * Uses the Username and Password properties.
  223. * @type bool
  224. * @see PHPMailer::$Username
  225. * @see PHPMailer::$Password
  226. */
  227. public $SMTPAuth = false;
  228. /**
  229. * SMTP username.
  230. * @type string
  231. */
  232. public $Username = '';
  233. /**
  234. * SMTP password.
  235. * @type string
  236. */
  237. public $Password = '';
  238. /**
  239. * SMTP auth type.
  240. * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5
  241. * @type string
  242. */
  243. public $AuthType = '';
  244. /**
  245. * SMTP realm.
  246. * Used for NTLM auth
  247. * @type string
  248. */
  249. public $Realm = '';
  250. /**
  251. * SMTP workstation.
  252. * Used for NTLM auth
  253. * @type string
  254. */
  255. public $Workstation = '';
  256. /**
  257. * The SMTP server timeout in seconds.
  258. * @type int
  259. */
  260. public $Timeout = 10;
  261. /**
  262. * SMTP class debug output mode.
  263. * Options: 0 = off, 1 = commands, 2 = commands and data
  264. * @type int
  265. * @see SMTP::$do_debug
  266. */
  267. public $SMTPDebug = 0;
  268. /**
  269. * The function/method to use for debugging output.
  270. * Options: "echo" or "error_log"
  271. * @type string
  272. * @see SMTP::$Debugoutput
  273. */
  274. public $Debugoutput = "echo";
  275. /**
  276. * Whether to keep SMTP connection open after each message.
  277. * If this is set to true then to close the connection
  278. * requires an explicit call to smtpClose().
  279. * @type bool
  280. */
  281. public $SMTPKeepAlive = false;
  282. /**
  283. * Whether to split multiple to addresses into multiple messages
  284. * or send them all in one message.
  285. * @type bool
  286. */
  287. public $SingleTo = false;
  288. /**
  289. * Storage for addresses when SingleTo is enabled.
  290. * @type array
  291. * @todo This should really not be public
  292. */
  293. public $SingleToArray = array();
  294. /**
  295. * Whether to generate VERP addresses on send.
  296. * Only applicable when sending via SMTP.
  297. * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
  298. * @type bool
  299. */
  300. public $do_verp = false;
  301. /**
  302. * Whether to allow sending messages with an empty body.
  303. * @type bool
  304. */
  305. public $AllowEmpty = false;
  306. /**
  307. * The default line ending.
  308. * @note The default remains "\n". We force CRLF where we know
  309. * it must be used via self::CRLF.
  310. * @type string
  311. */
  312. public $LE = "\n";
  313. /**
  314. * DKIM selector.
  315. * @type string
  316. */
  317. public $DKIM_selector = '';
  318. /**
  319. * DKIM Identity.
  320. * Usually the email address used as the source of the email
  321. * @type string
  322. */
  323. public $DKIM_identity = '';
  324. /**
  325. * DKIM passphrase.
  326. * Used if your key is encrypted.
  327. * @type string
  328. */
  329. public $DKIM_passphrase = '';
  330. /**
  331. * DKIM signing domain name.
  332. * @example 'example.com'
  333. * @type string
  334. */
  335. public $DKIM_domain = '';
  336. /**
  337. * DKIM private key file path.
  338. * @type string
  339. */
  340. public $DKIM_private = '';
  341. /**
  342. * Callback Action function name.
  343. *
  344. * The function that handles the result of the send email action.
  345. * It is called out by send() for each email sent.
  346. *
  347. * Value can be any php callable: http://www.php.net/is_callable
  348. *
  349. * Parameters:
  350. * bool $result result of the send action
  351. * string $to email address of the recipient
  352. * string $cc cc email addresses
  353. * string $bcc bcc email addresses
  354. * string $subject the subject
  355. * string $body the email body
  356. * string $from email address of sender
  357. * @type string
  358. */
  359. public $action_function = '';
  360. /**
  361. * What to use in the X-Mailer header.
  362. * Options: null for default, whitespace for none, or a string to use
  363. * @type string
  364. */
  365. public $XMailer = '';
  366. /**
  367. * An instance of the SMTP sender class.
  368. * @type SMTP
  369. * @access protected
  370. */
  371. protected $smtp = null;
  372. /**
  373. * The array of 'to' addresses.
  374. * @type array
  375. * @access protected
  376. */
  377. protected $to = array();
  378. /**
  379. * The array of 'cc' addresses.
  380. * @type array
  381. * @access protected
  382. */
  383. protected $cc = array();
  384. /**
  385. * The array of 'bcc' addresses.
  386. * @type array
  387. * @access protected
  388. */
  389. protected $bcc = array();
  390. /**
  391. * The array of reply-to names and addresses.
  392. * @type array
  393. * @access protected
  394. */
  395. protected $ReplyTo = array();
  396. /**
  397. * An array of all kinds of addresses.
  398. * Includes all of $to, $cc, $bcc, $replyto
  399. * @type array
  400. * @access protected
  401. */
  402. protected $all_recipients = array();
  403. /**
  404. * The array of attachments.
  405. * @type array
  406. * @access protected
  407. */
  408. protected $attachment = array();
  409. /**
  410. * The array of custom headers.
  411. * @type array
  412. * @access protected
  413. */
  414. protected $CustomHeader = array();
  415. /**
  416. * The most recent Message-ID (including angular brackets).
  417. * @type string
  418. * @access protected
  419. */
  420. protected $lastMessageID = '';
  421. /**
  422. * The message's MIME type.
  423. * @type string
  424. * @access protected
  425. */
  426. protected $message_type = '';
  427. /**
  428. * The array of MIME boundary strings.
  429. * @type array
  430. * @access protected
  431. */
  432. protected $boundary = array();
  433. /**
  434. * The array of available languages.
  435. * @type array
  436. * @access protected
  437. */
  438. protected $language = array();
  439. /**
  440. * The number of errors encountered.
  441. * @type integer
  442. * @access protected
  443. */
  444. protected $error_count = 0;
  445. /**
  446. * The S/MIME certificate file path.
  447. * @type string
  448. * @access protected
  449. */
  450. protected $sign_cert_file = '';
  451. /**
  452. * The S/MIME key file path.
  453. * @type string
  454. * @access protected
  455. */
  456. protected $sign_key_file = '';
  457. /**
  458. * The S/MIME password for the key.
  459. * Used only if the key is encrypted.
  460. * @type string
  461. * @access protected
  462. */
  463. protected $sign_key_pass = '';
  464. /**
  465. * Whether to throw exceptions for errors.
  466. * @type bool
  467. * @access protected
  468. */
  469. protected $exceptions = false;
  470. /**
  471. * Error severity: message only, continue processing
  472. */
  473. const STOP_MESSAGE = 0;
  474. /**
  475. * Error severity: message, likely ok to continue processing
  476. */
  477. const STOP_CONTINUE = 1;
  478. /**
  479. * Error severity: message, plus full stop, critical error reached
  480. */
  481. const STOP_CRITICAL = 2;
  482. /**
  483. * SMTP RFC standard line ending
  484. */
  485. const CRLF = "\r\n";
  486. /**
  487. * Constructor
  488. * @param bool $exceptions Should we throw external exceptions?
  489. */
  490. public function __construct($exceptions = false)
  491. {
  492. $this->exceptions = ($exceptions == true);
  493. //Make sure our autoloader is loaded
  494. if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
  495. $al = spl_autoload_functions();
  496. if ($al === false or !in_array('PHPMailerAutoload', $al)) {
  497. require 'PHPMailerAutoload.php';
  498. }
  499. }
  500. }
  501. /**
  502. * Destructor.
  503. */
  504. public function __destruct()
  505. {
  506. if ($this->Mailer == 'smtp') { //close any open SMTP connection nicely
  507. $this->smtpClose();
  508. }
  509. }
  510. /**
  511. * Call mail() in a safe_mode-aware fashion.
  512. * Also, unless sendmail_path points to sendmail (or something that
  513. * claims to be sendmail), don't pass params (not a perfect fix,
  514. * but it will do)
  515. * @param string $to To
  516. * @param string $subject Subject
  517. * @param string $body Message Body
  518. * @param string $header Additional Header(s)
  519. * @param string $params Params
  520. * @access private
  521. * @return bool
  522. */
  523. private function mailPassthru($to, $subject, $body, $header, $params)
  524. {
  525. //Check overloading of mail function to avoid double-encoding
  526. if (ini_get('mbstring.func_overload') & 1) {
  527. $subject = $this->secureHeader($subject);
  528. } else {
  529. $subject = $this->encodeHeader($this->secureHeader($subject));
  530. }
  531. if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  532. $rt = @mail($to, $subject, $body, $header);
  533. } else {
  534. $rt = @mail($to, $subject, $body, $header, $params);
  535. }
  536. return $rt;
  537. }
  538. /**
  539. * Output debugging info via user-defined method.
  540. * Only if debug output is enabled.
  541. * @see PHPMailer::$Debugoutput
  542. * @see PHPMailer::$SMTPDebug
  543. * @param string $str
  544. */
  545. protected function edebug($str)
  546. {
  547. if (!$this->SMTPDebug) {
  548. return;
  549. }
  550. switch ($this->Debugoutput) {
  551. case 'error_log':
  552. error_log($str);
  553. break;
  554. case 'html':
  555. //Cleans up output a bit for a better looking display that's HTML-safe
  556. echo htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, $this->CharSet) . "<br>\n";
  557. break;
  558. case 'echo':
  559. default:
  560. echo $str."\n";
  561. }
  562. }
  563. /**
  564. * Sets message type to HTML or plain.
  565. * @param bool $ishtml True for HTML mode.
  566. * @return void
  567. */
  568. public function isHTML($ishtml = true)
  569. {
  570. if ($ishtml) {
  571. $this->ContentType = 'text/html';
  572. } else {
  573. $this->ContentType = 'text/plain';
  574. }
  575. }
  576. /**
  577. * Send messages using SMTP.
  578. * @return void
  579. */
  580. public function isSMTP()
  581. {
  582. $this->Mailer = 'smtp';
  583. }
  584. /**
  585. * Send messages using PHP's mail() function.
  586. * @return void
  587. */
  588. public function isMail()
  589. {
  590. $this->Mailer = 'mail';
  591. }
  592. /**
  593. * Send messages using $Sendmail.
  594. * @return void
  595. */
  596. public function isSendmail()
  597. {
  598. if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
  599. $this->Sendmail = '/usr/sbin/sendmail';
  600. }
  601. $this->Mailer = 'sendmail';
  602. }
  603. /**
  604. * Send messages using qmail.
  605. * @return void
  606. */
  607. public function isQmail()
  608. {
  609. if (!stristr(ini_get('sendmail_path'), 'qmail')) {
  610. $this->Sendmail = '/var/qmail/bin/qmail-inject';
  611. }
  612. $this->Mailer = 'qmail';
  613. }
  614. /**
  615. * Add a "To" address.
  616. * @param string $address
  617. * @param string $name
  618. * @return bool true on success, false if address already used
  619. */
  620. public function addAddress($address, $name = '')
  621. {
  622. return $this->addAnAddress('to', $address, $name);
  623. }
  624. /**
  625. * Add a "CC" address.
  626. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  627. * @param string $address
  628. * @param string $name
  629. * @return bool true on success, false if address already used
  630. */
  631. public function addCC($address, $name = '')
  632. {
  633. return $this->addAnAddress('cc', $address, $name);
  634. }
  635. /**
  636. * Add a "BCC" address.
  637. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  638. * @param string $address
  639. * @param string $name
  640. * @return bool true on success, false if address already used
  641. */
  642. public function addBCC($address, $name = '')
  643. {
  644. return $this->addAnAddress('bcc', $address, $name);
  645. }
  646. /**
  647. * Add a "Reply-to" address.
  648. * @param string $address
  649. * @param string $name
  650. * @return bool
  651. */
  652. public function addReplyTo($address, $name = '')
  653. {
  654. return $this->addAnAddress('Reply-To', $address, $name);
  655. }
  656. /**
  657. * Add an address to one of the recipient arrays.
  658. * Addresses that have been added already return false, but do not throw exceptions
  659. * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
  660. * @param string $address The email address to send to
  661. * @param string $name
  662. * @throws phpmailerException
  663. * @return bool true on success, false if address already used or invalid in some way
  664. * @access protected
  665. */
  666. protected function addAnAddress($kind, $address, $name = '')
  667. {
  668. if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
  669. $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
  670. $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
  671. if ($this->exceptions) {
  672. throw new phpmailerException('Invalid recipient array: ' . $kind);
  673. }
  674. return false;
  675. }
  676. $address = trim($address);
  677. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  678. if (!$this->validateAddress($address)) {
  679. $this->setError($this->lang('invalid_address') . ': ' . $address);
  680. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  681. if ($this->exceptions) {
  682. throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  683. }
  684. return false;
  685. }
  686. if ($kind != 'Reply-To') {
  687. if (!isset($this->all_recipients[strtolower($address)])) {
  688. array_push($this->$kind, array($address, $name));
  689. $this->all_recipients[strtolower($address)] = true;
  690. return true;
  691. }
  692. } else {
  693. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  694. $this->ReplyTo[strtolower($address)] = array($address, $name);
  695. return true;
  696. }
  697. }
  698. return false;
  699. }
  700. /**
  701. * Set the From and FromName properties.
  702. * @param string $address
  703. * @param string $name
  704. * @param bool $auto Whether to also set the Sender address, defaults to true
  705. * @throws phpmailerException
  706. * @return bool
  707. */
  708. public function setFrom($address, $name = '', $auto = true)
  709. {
  710. $address = trim($address);
  711. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  712. if (!$this->validateAddress($address)) {
  713. $this->setError($this->lang('invalid_address') . ': ' . $address);
  714. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  715. if ($this->exceptions) {
  716. throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  717. }
  718. return false;
  719. }
  720. $this->From = $address;
  721. $this->FromName = $name;
  722. if ($auto) {
  723. if (empty($this->Sender)) {
  724. $this->Sender = $address;
  725. }
  726. }
  727. return true;
  728. }
  729. /**
  730. * Return the Message-ID header of the last email.
  731. * Technically this is the value from the last time the headers were created,
  732. * but it's also the message ID of the last sent message except in
  733. * pathological cases.
  734. * @return string
  735. */
  736. public function getLastMessageID()
  737. {
  738. return $this->lastMessageID;
  739. }
  740. /**
  741. * Check that a string looks like an email address.
  742. * @param string $address The email address to check
  743. * @param string $patternselect A selector for the validation pattern to use :
  744. * 'auto' - pick best one automatically;
  745. * 'pcre8' - use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  746. * 'pcre' - use old PCRE implementation;
  747. * 'php' - use PHP built-in FILTER_VALIDATE_EMAIL; faster, less thorough;
  748. * 'noregex' - super fast, really dumb.
  749. * @return bool
  750. * @static
  751. * @access public
  752. */
  753. public static function validateAddress($address, $patternselect = 'auto')
  754. {
  755. if ($patternselect == 'auto') {
  756. if (defined(
  757. 'PCRE_VERSION'
  758. )
  759. ) { //Check this instead of extension_loaded so it works when that function is disabled
  760. if (version_compare(PCRE_VERSION, '8.0') >= 0) {
  761. $patternselect = 'pcre8';
  762. } else {
  763. $patternselect = 'pcre';
  764. }
  765. } else {
  766. //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  767. if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  768. $patternselect = 'php';
  769. } else {
  770. $patternselect = 'noregex';
  771. }
  772. }
  773. }
  774. switch ($patternselect) {
  775. case 'pcre8':
  776. /**
  777. * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is
  778. * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to
  779. * not allow a@b type valid addresses :(
  780. * @link http://squiloople.com/2009/12/20/email-address-validation/
  781. * @copyright 2009-2010 Michael Rushton
  782. * Feel free to use and redistribute this code. But please keep this copyright notice.
  783. */
  784. return (bool)preg_match(
  785. '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  786. '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  787. '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  788. '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  789. '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  790. '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  791. '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  792. '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  793. '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  794. $address
  795. );
  796. break;
  797. case 'pcre':
  798. //An older regex that doesn't need a recent PCRE
  799. return (bool)preg_match(
  800. '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  801. '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  802. '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  803. '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  804. '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  805. '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  806. '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  807. '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  808. '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  809. '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  810. $address
  811. );
  812. break;
  813. case 'php':
  814. default:
  815. return (bool)filter_var($address, FILTER_VALIDATE_EMAIL);
  816. break;
  817. case 'noregex':
  818. //No PCRE! Do something _very_ approximate!
  819. //Check the address is 3 chars or longer and contains an @ that's not the first or last char
  820. return (strlen($address) >= 3
  821. and strpos($address, '@') >= 1
  822. and strpos($address, '@') != strlen($address) - 1);
  823. break;
  824. }
  825. }
  826. /**
  827. * Create a message and send it.
  828. * Uses the sending method specified by $Mailer.
  829. * @throws phpmailerException
  830. * @return bool false on error - See the ErrorInfo property for details of the error.
  831. */
  832. public function send()
  833. {
  834. try {
  835. if (!$this->preSend()) {
  836. return false;
  837. }
  838. return $this->postSend();
  839. } catch (phpmailerException $e) {
  840. $this->mailHeader = '';
  841. $this->setError($e->getMessage());
  842. if ($this->exceptions) {
  843. throw $e;
  844. }
  845. return false;
  846. }
  847. }
  848. /**
  849. * Prepare a message for sending.
  850. * @throws phpmailerException
  851. * @return bool
  852. */
  853. public function preSend()
  854. {
  855. try {
  856. $this->mailHeader = "";
  857. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  858. throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  859. }
  860. // Set whether the message is multipart/alternative
  861. if (!empty($this->AltBody)) {
  862. $this->ContentType = 'multipart/alternative';
  863. }
  864. $this->error_count = 0; // reset errors
  865. $this->setMessageType();
  866. // Refuse to send an empty message unless we are specifically allowing it
  867. if (!$this->AllowEmpty and empty($this->Body)) {
  868. throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  869. }
  870. $this->MIMEHeader = $this->createHeader();
  871. $this->MIMEBody = $this->createBody();
  872. // To capture the complete message when using mail(), create
  873. // an extra header list which createHeader() doesn't fold in
  874. if ($this->Mailer == 'mail') {
  875. if (count($this->to) > 0) {
  876. $this->mailHeader .= $this->addrAppend("To", $this->to);
  877. } else {
  878. $this->mailHeader .= $this->headerLine("To", "undisclosed-recipients:;");
  879. }
  880. $this->mailHeader .= $this->headerLine(
  881. 'Subject',
  882. $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  883. );
  884. }
  885. // Sign with DKIM if enabled
  886. if (!empty($this->DKIM_domain)
  887. && !empty($this->DKIM_private)
  888. && !empty($this->DKIM_selector)
  889. && !empty($this->DKIM_domain)
  890. && file_exists($this->DKIM_private)) {
  891. $header_dkim = $this->DKIM_Add(
  892. $this->MIMEHeader . $this->mailHeader,
  893. $this->encodeHeader($this->secureHeader($this->Subject)),
  894. $this->MIMEBody
  895. );
  896. $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  897. str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  898. }
  899. return true;
  900. } catch (phpmailerException $e) {
  901. $this->setError($e->getMessage());
  902. if ($this->exceptions) {
  903. throw $e;
  904. }
  905. return false;
  906. }
  907. }
  908. /**
  909. * Actually send a message.
  910. * Send the email via the selected mechanism
  911. * @throws phpmailerException
  912. * @return bool
  913. */
  914. public function postSend()
  915. {
  916. try {
  917. // Choose the mailer and send through it
  918. switch ($this->Mailer) {
  919. case 'sendmail':
  920. case 'qmail':
  921. return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  922. case 'smtp':
  923. return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
  924. case 'mail':
  925. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  926. default:
  927. if (method_exists($this, $this->Mailer.'Send')) {
  928. $sendMethod = $this->Mailer.'Send';
  929. return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  930. } else {
  931. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  932. }
  933. }
  934. } catch (phpmailerException $e) {
  935. $this->setError($e->getMessage());
  936. $this->edebug($e->getMessage());
  937. if ($this->exceptions) {
  938. throw $e;
  939. }
  940. }
  941. return false;
  942. }
  943. /**
  944. * Send mail using the $Sendmail program.
  945. * @param string $header The message headers
  946. * @param string $body The message body
  947. * @see PHPMailer::$Sendmail
  948. * @throws phpmailerException
  949. * @access protected
  950. * @return bool
  951. */
  952. protected function sendmailSend($header, $body)
  953. {
  954. if ($this->Sender != '') {
  955. if ($this->Mailer == 'qmail') {
  956. $sendmail = sprintf("%s -f%s", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  957. } else {
  958. $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  959. }
  960. } else {
  961. if ($this->Mailer == 'qmail') {
  962. $sendmail = sprintf("%s", escapeshellcmd($this->Sendmail));
  963. } else {
  964. $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  965. }
  966. }
  967. if ($this->SingleTo === true) {
  968. foreach ($this->SingleToArray as $val) {
  969. if (!@$mail = popen($sendmail, 'w')) {
  970. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  971. }
  972. fputs($mail, "To: " . $val . "\n");
  973. fputs($mail, $header);
  974. fputs($mail, $body);
  975. $result = pclose($mail);
  976. // implement call back function if it exists
  977. $isSent = ($result == 0) ? 1 : 0;
  978. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  979. if ($result != 0) {
  980. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  981. }
  982. }
  983. } else {
  984. if (!@$mail = popen($sendmail, 'w')) {
  985. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  986. }
  987. fputs($mail, $header);
  988. fputs($mail, $body);
  989. $result = pclose($mail);
  990. // implement call back function if it exists
  991. $isSent = ($result == 0) ? 1 : 0;
  992. $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  993. if ($result != 0) {
  994. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  995. }
  996. }
  997. return true;
  998. }
  999. /**
  1000. * Send mail using the PHP mail() function.
  1001. * @param string $header The message headers
  1002. * @param string $body The message body
  1003. * @link http://www.php.net/manual/en/book.mail.php
  1004. * @throws phpmailerException
  1005. * @access protected
  1006. * @return bool
  1007. */
  1008. protected function mailSend($header, $body)
  1009. {
  1010. $toArr = array();
  1011. foreach ($this->to as $t) {
  1012. $toArr[] = $this->addrFormat($t);
  1013. }
  1014. $to = implode(', ', $toArr);
  1015. if (empty($this->Sender)) {
  1016. $params = " ";
  1017. } else {
  1018. $params = sprintf("-f%s", $this->Sender);
  1019. }
  1020. if ($this->Sender != '' and !ini_get('safe_mode')) {
  1021. $old_from = ini_get('sendmail_from');
  1022. ini_set('sendmail_from', $this->Sender);
  1023. }
  1024. $rt = false;
  1025. if ($this->SingleTo === true && count($toArr) > 1) {
  1026. foreach ($toArr as $val) {
  1027. $rt = $this->mailPassthru($val, $this->Subject, $body, $header, $params);
  1028. // implement call back function if it exists
  1029. $isSent = ($rt == 1) ? 1 : 0;
  1030. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1031. }
  1032. } else {
  1033. $rt = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  1034. // implement call back function if it exists
  1035. $isSent = ($rt == 1) ? 1 : 0;
  1036. $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1037. }
  1038. if (isset($old_from)) {
  1039. ini_set('sendmail_from', $old_from);
  1040. }
  1041. if (!$rt) {
  1042. throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  1043. }
  1044. return true;
  1045. }
  1046. /**
  1047. * Get an instance to use for SMTP operations.
  1048. * Override this function to load your own SMTP implementation
  1049. * @return SMTP
  1050. */
  1051. public function getSMTPInstance()
  1052. {
  1053. if (!is_object($this->smtp)) {
  1054. $this->smtp = new SMTP;
  1055. }
  1056. return $this->smtp;
  1057. }
  1058. /**
  1059. * Send mail via SMTP.
  1060. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  1061. * Uses the PHPMailerSMTP class by default.
  1062. * @see PHPMailer::getSMTPInstance() to use a different class.
  1063. * @param string $header The message headers
  1064. * @param string $body The message body
  1065. * @throws phpmailerException
  1066. * @uses SMTP
  1067. * @access protected
  1068. * @return bool
  1069. */
  1070. protected function smtpSend($header, $body)
  1071. {
  1072. $bad_rcpt = array();
  1073. if (!$this->smtpConnect()) {
  1074. throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  1075. }
  1076. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  1077. if (!$this->smtp->mail($smtp_from)) {
  1078. $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  1079. throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  1080. }
  1081. // Attempt to send to all recipients
  1082. foreach ($this->to as $to) {
  1083. if (!$this->smtp->recipient($to[0])) {
  1084. $bad_rcpt[] = $to[0];
  1085. $isSent = 0;
  1086. } else {
  1087. $isSent = 1;
  1088. }
  1089. $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body, $this->From);
  1090. }
  1091. foreach ($this->cc as $cc) {
  1092. if (!$this->smtp->recipient($cc[0])) {
  1093. $bad_rcpt[] = $cc[0];
  1094. $isSent = 0;
  1095. } else {
  1096. $isSent = 1;
  1097. }
  1098. $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body, $this->From);
  1099. }
  1100. foreach ($this->bcc as $bcc) {
  1101. if (!$this->smtp->recipient($bcc[0])) {
  1102. $bad_rcpt[] = $bcc[0];
  1103. $isSent = 0;
  1104. } else {
  1105. $isSent = 1;
  1106. }
  1107. $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body, $this->From);
  1108. }
  1109. //Only send the DATA command if we have viable recipients
  1110. if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  1111. throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  1112. }
  1113. if ($this->SMTPKeepAlive == true) {
  1114. $this->smtp->reset();
  1115. } else {
  1116. $this->smtp->quit();
  1117. $this->smtp->close();
  1118. }
  1119. if (count($bad_rcpt) > 0) { //Create error message for any bad addresses
  1120. throw new phpmailerException(
  1121. $this->lang('recipients_failed') . implode(', ', $bad_rcpt),
  1122. self::STOP_CONTINUE
  1123. );
  1124. }
  1125. return true;
  1126. }
  1127. /**
  1128. * Initiate a connection to an SMTP server.
  1129. * Returns false if the operation failed.
  1130. * @param array $options An array of options compatible with stream_context_create()
  1131. * @uses SMTP
  1132. * @access public
  1133. * @throws phpmailerException
  1134. * @return bool
  1135. */
  1136. public function smtpConnect($options = array())
  1137. {
  1138. if (is_null($this->smtp)) {
  1139. $this->smtp = $this->getSMTPInstance();
  1140. }
  1141. //Already connected?
  1142. if ($this->smtp->connected()) {
  1143. return true;
  1144. }
  1145. $this->smtp->setTimeout($this->Timeout);
  1146. $this->smtp->setDebugLevel($this->SMTPDebug);
  1147. $this->smtp->setDebugOutput($this->Debugoutput);
  1148. $this->smtp->setVerp($this->do_verp);
  1149. $hosts = explode(';', $this->Host);
  1150. $lastexception = null;
  1151. foreach ($hosts as $hostentry) {
  1152. $hostinfo = array();
  1153. if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  1154. //Not a valid host entry
  1155. continue;
  1156. }
  1157. //$hostinfo[2]: optional ssl or tls prefix
  1158. //$hostinfo[3]: the hostname
  1159. //$hostinfo[4]: optional port number
  1160. //The host string prefix can temporarily override the current setting for SMTPSecure
  1161. //If it's not specified, the default value is used
  1162. $prefix = '';
  1163. $tls = ($this->SMTPSecure == 'tls');
  1164. if ($hostinfo[2] == 'ssl' or ($hostinfo[2] == '' and $this->SMTPSecure == 'ssl')) {
  1165. $prefix = 'ssl://';
  1166. $tls = false; //Can't have SSL and TLS at once
  1167. } elseif ($hostinfo[2] == 'tls') {
  1168. $tls = true;
  1169. //tls doesn't use a prefix
  1170. }
  1171. $host = $hostinfo[3];
  1172. $port = $this->Port;
  1173. $tport = (integer)$hostinfo[4];
  1174. if ($tport > 0 and $tport < 65536) {
  1175. $port = $tport;
  1176. }
  1177. if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  1178. try {
  1179. if ($this->Helo) {
  1180. $hello = $this->Helo;
  1181. } else {
  1182. $hello = $this->serverHostname();
  1183. }
  1184. $this->smtp->hello($hello);
  1185. if ($tls) {
  1186. if (!$this->smtp->startTLS()) {
  1187. throw new phpmailerException($this->lang('connect_host'));
  1188. }
  1189. //We must resend HELO after tls negotiation
  1190. $this->smtp->hello($hello);
  1191. }
  1192. if ($this->SMTPAuth) {
  1193. if (!$this->smtp->authenticate(
  1194. $this->Username,
  1195. $this->Password,
  1196. $this->AuthType,
  1197. $this->Realm,
  1198. $this->Workstation
  1199. )
  1200. ) {
  1201. throw new phpmailerException($this->lang('authenticate'));
  1202. }
  1203. }
  1204. return true;
  1205. } catch (phpmailerException $e) {
  1206. $lastexception = $e;
  1207. //We must have connected, but then failed TLS or Auth, so close connection nicely
  1208. $this->smtp->quit();
  1209. }
  1210. }
  1211. }
  1212. //If we get here, all connection attempts have failed, so close connection hard
  1213. $this->smtp->close();
  1214. //As we've caught all exceptions, just report whatever the last one was
  1215. if ($this->exceptions and !is_null($lastexception)) {
  1216. throw $lastexception;
  1217. }
  1218. return false;
  1219. }
  1220. /**
  1221. * Close the active SMTP session if one exists.
  1222. * @return void
  1223. */
  1224. public function smtpClose()
  1225. {
  1226. if ($this->smtp !== null) {
  1227. if ($this->smtp->connected()) {
  1228. $this->smtp->quit();
  1229. $this->smtp->close();
  1230. }
  1231. }
  1232. }
  1233. /**
  1234. * Set the language for error messages.
  1235. * Returns false if it cannot load the language file.
  1236. * The default language is English.
  1237. * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
  1238. * @param string $lang_path Path to the language file directory, with trailing separator (slash)
  1239. * @return bool
  1240. * @access public
  1241. */
  1242. public function setLanguage($langcode = 'en', $lang_path = 'language/')
  1243. {
  1244. //Define full set of translatable strings
  1245. $PHPMAILER_LANG = array(
  1246. 'authenticate' => 'SMTP Error: Could not authenticate.',
  1247. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  1248. 'data_not_accepted' => 'SMTP Error: data not accepted.',
  1249. 'empty_message' => 'Message body empty',
  1250. 'encoding' => 'Unknown encoding: ',
  1251. 'execute' => 'Could not execute: ',
  1252. 'file_access' => 'Could not access file: ',
  1253. 'file_open' => 'File Error: Could not open file: ',
  1254. 'from_failed' => 'The following From address failed: ',
  1255. 'instantiate' => 'Could not instantiate mail function.',
  1256. 'invalid_address' => 'Invalid address',
  1257. 'mailer_not_supported' => ' mailer is not supported.',
  1258. 'provide_address' => 'You must provide at least one recipient email address.',
  1259. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  1260. 'signing' => 'Signing Error: ',
  1261. 'smtp_connect_failed' => 'SMTP connect() failed.',
  1262. 'smtp_error' => 'SMTP server error: ',
  1263. 'variable_set' => 'Cannot set or reset variable: '
  1264. );
  1265. //Overwrite language-specific strings.
  1266. //This way we'll never have missing translations - no more "language string failed to load"!
  1267. $l = true;
  1268. $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  1269. if ($langcode != 'en') { //There is no English translation file
  1270. //Make sure language file path is readable
  1271. if (!is_readable($lang_file)) {
  1272. $l = false;
  1273. } else {
  1274. $l = include $lang_file;
  1275. }
  1276. }
  1277. $this->language = $PHPMAILER_LANG;
  1278. return ($l == true); //Returns false if language not found
  1279. }
  1280. /**
  1281. * Get the array of strings for the current language.
  1282. * @return array
  1283. */
  1284. public function getTranslations()
  1285. {
  1286. return $this->language;
  1287. }
  1288. /**
  1289. * Create recipient headers.
  1290. * @access public
  1291. * @param string $type
  1292. * @param array $addr An array of recipient,
  1293. * where each recipient is a 2-element indexed array with element 0 containing an address
  1294. * and element 1 containing a name, like:
  1295. * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
  1296. * @return string
  1297. */
  1298. public function addrAppend($type, $addr)
  1299. {
  1300. $addresses = array();
  1301. foreach ($addr as $a) {
  1302. $addresses[] = $this->addrFormat($a);
  1303. }
  1304. return $type . ': ' . implode(', ', $addresses) . $this->LE;
  1305. }
  1306. /**
  1307. * Format an address for use in a message header.
  1308. * @access public
  1309. * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
  1310. * like array('joe@example.com', 'Joe User')
  1311. * @return string
  1312. */
  1313. public function addrFormat($addr)
  1314. {
  1315. if (empty($addr[1])) { // No name provided
  1316. return $this->secureHeader($addr[0]);
  1317. } else {
  1318. return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . " <" . $this->secureHeader(
  1319. $addr[0]
  1320. ) . ">";
  1321. }
  1322. }
  1323. /**
  1324. * Word-wrap message.
  1325. * For use with mailers that do not automatically perform wrapping
  1326. * and for quoted-printable encoded messages.
  1327. * Original written by philippe.
  1328. * @param string $message The message to wrap
  1329. * @param integer $length The line length to wrap to
  1330. * @param bool $qp_mode Whether to run in Quoted-Printable mode
  1331. * @access public
  1332. * @return string
  1333. */
  1334. public function wrapText($message, $length, $qp_mode = false)
  1335. {
  1336. $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  1337. // If utf-8 encoding is used, we will need to make sure we don't
  1338. // split multibyte characters when we wrap
  1339. $is_utf8 = (strtolower($this->CharSet) == "utf-8");
  1340. $lelen = strlen($this->LE);
  1341. $crlflen = strlen(self::CRLF);
  1342. $message = $this->fixEOL($message);
  1343. if (substr($message, -$lelen) == $this->LE) {
  1344. $message = substr($message, 0, -$lelen);
  1345. }
  1346. $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
  1347. $message = '';
  1348. for ($i = 0; $i < count($line); $i++) {
  1349. $line_part = explode(' ', $line[$i]);
  1350. $buf = '';
  1351. for ($e = 0; $e < count($line_part); $e++) {
  1352. $word = $line_part[$e];
  1353. if ($qp_mode and (strlen($word) > $length)) {
  1354. $space_left = $length - strlen($buf) - $crlflen;
  1355. if ($e != 0) {
  1356. if ($space_left > 20) {
  1357. $len = $space_left;
  1358. if ($is_utf8) {
  1359. $len = $this->utf8CharBoundary($word, $len);
  1360. } elseif (substr($word, $len - 1, 1) == "=") {
  1361. $len--;
  1362. } elseif (substr($word, $len - 2, 1) == "=") {
  1363. $len -= 2;
  1364. }
  1365. $part = substr($word, 0, $len);
  1366. $word = substr($word, $len);
  1367. $buf .= ' ' . $part;
  1368. $message .= $buf . sprintf("=%s", self::CRLF);
  1369. } else {
  1370. $message .= $buf . $soft_break;
  1371. }
  1372. $buf = '';
  1373. }
  1374. while (strlen($word) > 0) {
  1375. if ($length <= 0) {
  1376. break;
  1377. }
  1378. $len = $length;
  1379. if ($is_utf8) {
  1380. $len = $this->utf8CharBoundary($word, $len);
  1381. } elseif (substr($word, $len - 1, 1) == "=") {
  1382. $len--;
  1383. } elseif (substr($word, $len - 2, 1) == "=") {
  1384. $len -= 2;
  1385. }
  1386. $part = substr($word, 0, $len);
  1387. $word = substr($word, $len);
  1388. if (strlen($word) > 0) {
  1389. $message .= $part . sprintf("=%s", self::CRLF);
  1390. } else {
  1391. $buf = $part;
  1392. }
  1393. }
  1394. } else {
  1395. $buf_o = $buf;
  1396. $buf .= ($e == 0) ? $word : (' ' . $word);
  1397. if (strlen($buf) > $length and $buf_o != '') {
  1398. $message .= $buf_o . $soft_break;
  1399. $buf = $word;
  1400. }

Large files files are truncated, but you can click here to view the full file