PageRenderTime 48ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/webroot/lib/PHPMailer/class.phpmailer.php

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

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