PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/phpmailer/class.phpmailer.php

https://bitbucket.org/jlkcz/shtroodle
PHP | 3458 lines | 2029 code | 230 blank | 1199 comment | 342 complexity | b5ad2dca43765b8215288d123214ec7d MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0

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. * @type integer
  135. */
  136. public $WordWrap = 0;
  137. /**
  138. * Which method to use to send mail.
  139. * Options: "mail", "sendmail", or "smtp".
  140. * @type string
  141. */
  142. public $Mailer = 'mail';
  143. /**
  144. * The path to the sendmail program.
  145. * @type string
  146. */
  147. public $Sendmail = '/usr/sbin/sendmail';
  148. /**
  149. * Whether mail() uses a fully sendmail-compatible MTA.
  150. * One which supports sendmail's "-oi -f" options.
  151. * @type boolean
  152. */
  153. public $UseSendmailOptions = true;
  154. /**
  155. * Path to PHPMailer plugins.
  156. * Useful if the SMTP class is not in the PHP include path.
  157. * @type string
  158. * @deprecated Should not be needed now there is an autoloader.
  159. */
  160. public $PluginDir = '';
  161. /**
  162. * The email address that a reading confirmation should be sent to.
  163. * @type string
  164. */
  165. public $ConfirmReadingTo = '';
  166. /**
  167. * The hostname to use in Message-Id and Received headers
  168. * and as default HELO string.
  169. * If empty, the value returned
  170. * by SERVER_NAME is used or 'localhost.localdomain'.
  171. * @type string
  172. */
  173. public $Hostname = '';
  174. /**
  175. * An ID to be used in the Message-Id header.
  176. * If empty, a unique id will be generated.
  177. * @type string
  178. */
  179. public $MessageID = '';
  180. /**
  181. * The message Date to be used in the Date header.
  182. * If empty, the current date will be added.
  183. * @type string
  184. */
  185. public $MessageDate = '';
  186. /**
  187. * SMTP hosts.
  188. * Either a single hostname or multiple semicolon-delimited hostnames.
  189. * You can also specify a different port
  190. * for each host by using this format: [hostname:port]
  191. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  192. * You can also specify encryption type, for example:
  193. * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
  194. * Hosts will be tried in order.
  195. * @type string
  196. */
  197. public $Host = 'localhost';
  198. /**
  199. * The default SMTP server port.
  200. * @type integer
  201. * @TODO Why is this needed when the SMTP class takes care of it?
  202. */
  203. public $Port = 25;
  204. /**
  205. * The SMTP HELO of the message.
  206. * Default is $Hostname.
  207. * @type string
  208. * @see PHPMailer::$Hostname
  209. */
  210. public $Helo = '';
  211. /**
  212. * The secure connection prefix.
  213. * Options: "", "ssl" or "tls"
  214. * @type string
  215. */
  216. public $SMTPSecure = '';
  217. /**
  218. * Whether to use SMTP authentication.
  219. * Uses the Username and Password properties.
  220. * @type boolean
  221. * @see PHPMailer::$Username
  222. * @see PHPMailer::$Password
  223. */
  224. public $SMTPAuth = false;
  225. /**
  226. * SMTP username.
  227. * @type string
  228. */
  229. public $Username = '';
  230. /**
  231. * SMTP password.
  232. * @type string
  233. */
  234. public $Password = '';
  235. /**
  236. * SMTP auth type.
  237. * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5
  238. * @type string
  239. */
  240. public $AuthType = '';
  241. /**
  242. * SMTP realm.
  243. * Used for NTLM auth
  244. * @type string
  245. */
  246. public $Realm = '';
  247. /**
  248. * SMTP workstation.
  249. * Used for NTLM auth
  250. * @type string
  251. */
  252. public $Workstation = '';
  253. /**
  254. * The SMTP server timeout in seconds.
  255. * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
  256. * @type integer
  257. */
  258. public $Timeout = 300;
  259. /**
  260. * SMTP class debug output mode.
  261. * Debug output level.
  262. * Options:
  263. * * `0` No output
  264. * * `1` Commands
  265. * * `2` Data and commands
  266. * * `3` As 2 plus connection status
  267. * * `4` Low-level data output
  268. * @type integer
  269. * @see SMTP::$do_debug
  270. */
  271. public $SMTPDebug = 0;
  272. /**
  273. * How to handle debug output.
  274. * Options:
  275. * * `echo` Output plain-text as-is, appropriate for CLI
  276. * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
  277. * * `error_log` Output to error log as configured in php.ini
  278. *
  279. * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
  280. * <code>
  281. * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
  282. * </code>
  283. * @type string|callable
  284. * @see SMTP::$Debugoutput
  285. */
  286. public $Debugoutput = 'echo';
  287. /**
  288. * Whether to keep SMTP connection open after each message.
  289. * If this is set to true then to close the connection
  290. * requires an explicit call to smtpClose().
  291. * @type boolean
  292. */
  293. public $SMTPKeepAlive = false;
  294. /**
  295. * Whether to split multiple to addresses into multiple messages
  296. * or send them all in one message.
  297. * @type boolean
  298. */
  299. public $SingleTo = false;
  300. /**
  301. * Storage for addresses when SingleTo is enabled.
  302. * @type array
  303. * @TODO This should really not be public
  304. */
  305. public $SingleToArray = array();
  306. /**
  307. * Whether to generate VERP addresses on send.
  308. * Only applicable when sending via SMTP.
  309. * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
  310. * @link http://www.postfix.org/VERP_README.html Postfix VERP info
  311. * @type boolean
  312. */
  313. public $do_verp = false;
  314. /**
  315. * Whether to allow sending messages with an empty body.
  316. * @type boolean
  317. */
  318. public $AllowEmpty = false;
  319. /**
  320. * The default line ending.
  321. * @note The default remains "\n". We force CRLF where we know
  322. * it must be used via self::CRLF.
  323. * @type string
  324. */
  325. public $LE = "\n";
  326. /**
  327. * DKIM selector.
  328. * @type string
  329. */
  330. public $DKIM_selector = '';
  331. /**
  332. * DKIM Identity.
  333. * Usually the email address used as the source of the email
  334. * @type string
  335. */
  336. public $DKIM_identity = '';
  337. /**
  338. * DKIM passphrase.
  339. * Used if your key is encrypted.
  340. * @type string
  341. */
  342. public $DKIM_passphrase = '';
  343. /**
  344. * DKIM signing domain name.
  345. * @example 'example.com'
  346. * @type string
  347. */
  348. public $DKIM_domain = '';
  349. /**
  350. * DKIM private key file path.
  351. * @type string
  352. */
  353. public $DKIM_private = '';
  354. /**
  355. * Callback Action function name.
  356. *
  357. * The function that handles the result of the send email action.
  358. * It is called out by send() for each email sent.
  359. *
  360. * Value can be any php callable: http://www.php.net/is_callable
  361. *
  362. * Parameters:
  363. * boolean $result result of the send action
  364. * string $to email address of the recipient
  365. * string $cc cc email addresses
  366. * string $bcc bcc email addresses
  367. * string $subject the subject
  368. * string $body the email body
  369. * string $from email address of sender
  370. * @type string
  371. */
  372. public $action_function = '';
  373. /**
  374. * What to use in the X-Mailer header.
  375. * Options: null for default, whitespace for none, or a string to use
  376. * @type string
  377. */
  378. public $XMailer = '';
  379. /**
  380. * An instance of the SMTP sender class.
  381. * @type SMTP
  382. * @access protected
  383. */
  384. protected $smtp = null;
  385. /**
  386. * The array of 'to' addresses.
  387. * @type array
  388. * @access protected
  389. */
  390. protected $to = array();
  391. /**
  392. * The array of 'cc' addresses.
  393. * @type array
  394. * @access protected
  395. */
  396. protected $cc = array();
  397. /**
  398. * The array of 'bcc' addresses.
  399. * @type array
  400. * @access protected
  401. */
  402. protected $bcc = array();
  403. /**
  404. * The array of reply-to names and addresses.
  405. * @type array
  406. * @access protected
  407. */
  408. protected $ReplyTo = array();
  409. /**
  410. * An array of all kinds of addresses.
  411. * Includes all of $to, $cc, $bcc, $replyto
  412. * @type array
  413. * @access protected
  414. */
  415. protected $all_recipients = array();
  416. /**
  417. * The array of attachments.
  418. * @type array
  419. * @access protected
  420. */
  421. protected $attachment = array();
  422. /**
  423. * The array of custom headers.
  424. * @type array
  425. * @access protected
  426. */
  427. protected $CustomHeader = array();
  428. /**
  429. * The most recent Message-ID (including angular brackets).
  430. * @type string
  431. * @access protected
  432. */
  433. protected $lastMessageID = '';
  434. /**
  435. * The message's MIME type.
  436. * @type string
  437. * @access protected
  438. */
  439. protected $message_type = '';
  440. /**
  441. * The array of MIME boundary strings.
  442. * @type array
  443. * @access protected
  444. */
  445. protected $boundary = array();
  446. /**
  447. * The array of available languages.
  448. * @type array
  449. * @access protected
  450. */
  451. protected $language = array();
  452. /**
  453. * The number of errors encountered.
  454. * @type integer
  455. * @access protected
  456. */
  457. protected $error_count = 0;
  458. /**
  459. * The S/MIME certificate file path.
  460. * @type string
  461. * @access protected
  462. */
  463. protected $sign_cert_file = '';
  464. /**
  465. * The S/MIME key file path.
  466. * @type string
  467. * @access protected
  468. */
  469. protected $sign_key_file = '';
  470. /**
  471. * The S/MIME password for the key.
  472. * Used only if the key is encrypted.
  473. * @type string
  474. * @access protected
  475. */
  476. protected $sign_key_pass = '';
  477. /**
  478. * Whether to throw exceptions for errors.
  479. * @type boolean
  480. * @access protected
  481. */
  482. protected $exceptions = false;
  483. /**
  484. * Error severity: message only, continue processing.
  485. */
  486. const STOP_MESSAGE = 0;
  487. /**
  488. * Error severity: message, likely ok to continue processing.
  489. */
  490. const STOP_CONTINUE = 1;
  491. /**
  492. * Error severity: message, plus full stop, critical error reached.
  493. */
  494. const STOP_CRITICAL = 2;
  495. /**
  496. * SMTP RFC standard line ending.
  497. */
  498. const CRLF = "\r\n";
  499. /**
  500. * Constructor.
  501. * @param boolean $exceptions Should we throw external exceptions?
  502. */
  503. public function __construct($exceptions = false)
  504. {
  505. $this->exceptions = (boolean)$exceptions;
  506. }
  507. /**
  508. * Destructor.
  509. */
  510. public function __destruct()
  511. {
  512. if ($this->Mailer == 'smtp') { //close any open SMTP connection nicely
  513. $this->smtpClose();
  514. }
  515. }
  516. /**
  517. * Call mail() in a safe_mode-aware fashion.
  518. * Also, unless sendmail_path points to sendmail (or something that
  519. * claims to be sendmail), don't pass params (not a perfect fix,
  520. * but it will do)
  521. * @param string $to To
  522. * @param string $subject Subject
  523. * @param string $body Message Body
  524. * @param string $header Additional Header(s)
  525. * @param string $params Params
  526. * @access private
  527. * @return boolean
  528. */
  529. private function mailPassthru($to, $subject, $body, $header, $params)
  530. {
  531. //Check overloading of mail function to avoid double-encoding
  532. if (ini_get('mbstring.func_overload') & 1) {
  533. $subject = $this->secureHeader($subject);
  534. } else {
  535. $subject = $this->encodeHeader($this->secureHeader($subject));
  536. }
  537. if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  538. $result = @mail($to, $subject, $body, $header);
  539. } else {
  540. $result = @mail($to, $subject, $body, $header, $params);
  541. }
  542. return $result;
  543. }
  544. /**
  545. * Output debugging info via user-defined method.
  546. * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
  547. * @see PHPMailer::$Debugoutput
  548. * @see PHPMailer::$SMTPDebug
  549. * @param string $str
  550. */
  551. protected function edebug($str)
  552. {
  553. if ($this->SMTPDebug <= 0) {
  554. return;
  555. }
  556. //Avoid clash with built-in function names
  557. if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  558. call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  559. return;
  560. }
  561. switch ($this->Debugoutput) {
  562. case 'error_log':
  563. //Don't output, just log
  564. error_log($str);
  565. break;
  566. case 'html':
  567. //Cleans up output a bit for a better looking, HTML-safe output
  568. echo htmlentities(
  569. preg_replace('/[\r\n]+/', '', $str),
  570. ENT_QUOTES,
  571. 'UTF-8'
  572. )
  573. . "<br>\n";
  574. break;
  575. case 'echo':
  576. default:
  577. //Normalize line breaks
  578. $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  579. echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  580. "\n",
  581. "\n \t ",
  582. trim($str)
  583. ) . "\n";
  584. }
  585. }
  586. /**
  587. * Sets message type to HTML or plain.
  588. * @param boolean $isHtml True for HTML mode.
  589. * @return void
  590. */
  591. public function isHTML($isHtml = true)
  592. {
  593. if ($isHtml) {
  594. $this->ContentType = 'text/html';
  595. } else {
  596. $this->ContentType = 'text/plain';
  597. }
  598. }
  599. /**
  600. * Send messages using SMTP.
  601. * @return void
  602. */
  603. public function isSMTP()
  604. {
  605. $this->Mailer = 'smtp';
  606. }
  607. /**
  608. * Send messages using PHP's mail() function.
  609. * @return void
  610. */
  611. public function isMail()
  612. {
  613. $this->Mailer = 'mail';
  614. }
  615. /**
  616. * Send messages using $Sendmail.
  617. * @return void
  618. */
  619. public function isSendmail()
  620. {
  621. $ini_sendmail_path = ini_get('sendmail_path');
  622. if (!stristr($ini_sendmail_path, 'sendmail')) {
  623. $this->Sendmail = '/usr/sbin/sendmail';
  624. } else {
  625. $this->Sendmail = $ini_sendmail_path;
  626. }
  627. $this->Mailer = 'sendmail';
  628. }
  629. /**
  630. * Send messages using qmail.
  631. * @return void
  632. */
  633. public function isQmail()
  634. {
  635. $ini_sendmail_path = ini_get('sendmail_path');
  636. if (!stristr($ini_sendmail_path, 'qmail')) {
  637. $this->Sendmail = '/var/qmail/bin/qmail-inject';
  638. } else {
  639. $this->Sendmail = $ini_sendmail_path;
  640. }
  641. $this->Mailer = 'qmail';
  642. }
  643. /**
  644. * Add a "To" address.
  645. * @param string $address
  646. * @param string $name
  647. * @return boolean true on success, false if address already used
  648. */
  649. public function addAddress($address, $name = '')
  650. {
  651. return $this->addAnAddress('to', $address, $name);
  652. }
  653. /**
  654. * Add a "CC" address.
  655. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  656. * @param string $address
  657. * @param string $name
  658. * @return boolean true on success, false if address already used
  659. */
  660. public function addCC($address, $name = '')
  661. {
  662. return $this->addAnAddress('cc', $address, $name);
  663. }
  664. /**
  665. * Add a "BCC" address.
  666. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  667. * @param string $address
  668. * @param string $name
  669. * @return boolean true on success, false if address already used
  670. */
  671. public function addBCC($address, $name = '')
  672. {
  673. return $this->addAnAddress('bcc', $address, $name);
  674. }
  675. /**
  676. * Add a "Reply-to" address.
  677. * @param string $address
  678. * @param string $name
  679. * @return boolean
  680. */
  681. public function addReplyTo($address, $name = '')
  682. {
  683. return $this->addAnAddress('Reply-To', $address, $name);
  684. }
  685. /**
  686. * Add an address to one of the recipient arrays.
  687. * Addresses that have been added already return false, but do not throw exceptions
  688. * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
  689. * @param string $address The email address to send to
  690. * @param string $name
  691. * @throws phpmailerException
  692. * @return boolean true on success, false if address already used or invalid in some way
  693. * @access protected
  694. */
  695. protected function addAnAddress($kind, $address, $name = '')
  696. {
  697. if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
  698. $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
  699. $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
  700. if ($this->exceptions) {
  701. throw new phpmailerException('Invalid recipient array: ' . $kind);
  702. }
  703. return false;
  704. }
  705. $address = trim($address);
  706. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  707. if (!$this->validateAddress($address)) {
  708. $this->setError($this->lang('invalid_address') . ': ' . $address);
  709. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  710. if ($this->exceptions) {
  711. throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  712. }
  713. return false;
  714. }
  715. if ($kind != 'Reply-To') {
  716. if (!isset($this->all_recipients[strtolower($address)])) {
  717. array_push($this->$kind, array($address, $name));
  718. $this->all_recipients[strtolower($address)] = true;
  719. return true;
  720. }
  721. } else {
  722. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  723. $this->ReplyTo[strtolower($address)] = array($address, $name);
  724. return true;
  725. }
  726. }
  727. return false;
  728. }
  729. /**
  730. * Set the From and FromName properties.
  731. * @param string $address
  732. * @param string $name
  733. * @param boolean $auto Whether to also set the Sender address, defaults to true
  734. * @throws phpmailerException
  735. * @return boolean
  736. */
  737. public function setFrom($address, $name = '', $auto = true)
  738. {
  739. $address = trim($address);
  740. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  741. if (!$this->validateAddress($address)) {
  742. $this->setError($this->lang('invalid_address') . ': ' . $address);
  743. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  744. if ($this->exceptions) {
  745. throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  746. }
  747. return false;
  748. }
  749. $this->From = $address;
  750. $this->FromName = $name;
  751. if ($auto) {
  752. if (empty($this->Sender)) {
  753. $this->Sender = $address;
  754. }
  755. }
  756. return true;
  757. }
  758. /**
  759. * Return the Message-ID header of the last email.
  760. * Technically this is the value from the last time the headers were created,
  761. * but it's also the message ID of the last sent message except in
  762. * pathological cases.
  763. * @return string
  764. */
  765. public function getLastMessageID()
  766. {
  767. return $this->lastMessageID;
  768. }
  769. /**
  770. * Check that a string looks like an email address.
  771. * @param string $address The email address to check
  772. * @param string $patternselect A selector for the validation pattern to use :
  773. * * `auto` Pick strictest one automatically;
  774. * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  775. * * `pcre` Use old PCRE implementation;
  776. * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;
  777. * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
  778. * * `noregex` Don't use a regex: super fast, really dumb.
  779. * @return boolean
  780. * @static
  781. * @access public
  782. */
  783. public static function validateAddress($address, $patternselect = 'auto')
  784. {
  785. if (!$patternselect or $patternselect == 'auto') {
  786. //Check this constant first so it works when extension_loaded() is disabled by safe mode
  787. //Constant was added in PHP 5.2.4
  788. if (defined('PCRE_VERSION')) {
  789. //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  790. if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
  791. $patternselect = 'pcre8';
  792. } else {
  793. $patternselect = 'pcre';
  794. }
  795. } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
  796. //Fall back to older PCRE
  797. $patternselect = 'pcre';
  798. } else {
  799. //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  800. if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  801. $patternselect = 'php';
  802. } else {
  803. $patternselect = 'noregex';
  804. }
  805. }
  806. }
  807. switch ($patternselect) {
  808. case 'pcre8':
  809. /**
  810. * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
  811. * @link http://squiloople.com/2009/12/20/email-address-validation/
  812. * @copyright 2009-2010 Michael Rushton
  813. * Feel free to use and redistribute this code. But please keep this copyright notice.
  814. */
  815. return (boolean)preg_match(
  816. '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  817. '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  818. '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  819. '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  820. '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  821. '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  822. '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  823. '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  824. '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  825. $address
  826. );
  827. case 'pcre':
  828. //An older regex that doesn't need a recent PCRE
  829. return (boolean)preg_match(
  830. '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  831. '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  832. '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  833. '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  834. '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  835. '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  836. '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  837. '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  838. '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  839. '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  840. $address
  841. );
  842. case 'html5':
  843. /**
  844. * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
  845. * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
  846. */
  847. return (boolean)preg_match(
  848. '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  849. '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  850. $address
  851. );
  852. case 'noregex':
  853. //No PCRE! Do something _very_ approximate!
  854. //Check the address is 3 chars or longer and contains an @ that's not the first or last char
  855. return (strlen($address) >= 3
  856. and strpos($address, '@') >= 1
  857. and strpos($address, '@') != strlen($address) - 1);
  858. case 'php':
  859. default:
  860. return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  861. }
  862. }
  863. /**
  864. * Create a message and send it.
  865. * Uses the sending method specified by $Mailer.
  866. * @throws phpmailerException
  867. * @return boolean false on error - See the ErrorInfo property for details of the error.
  868. */
  869. public function send()
  870. {
  871. try {
  872. if (!$this->preSend()) {
  873. return false;
  874. }
  875. return $this->postSend();
  876. } catch (phpmailerException $exc) {
  877. $this->mailHeader = '';
  878. $this->setError($exc->getMessage());
  879. if ($this->exceptions) {
  880. throw $exc;
  881. }
  882. return false;
  883. }
  884. }
  885. /**
  886. * Prepare a message for sending.
  887. * @throws phpmailerException
  888. * @return boolean
  889. */
  890. public function preSend()
  891. {
  892. try {
  893. $this->mailHeader = '';
  894. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  895. throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  896. }
  897. // Set whether the message is multipart/alternative
  898. if (!empty($this->AltBody)) {
  899. $this->ContentType = 'multipart/alternative';
  900. }
  901. $this->error_count = 0; // reset errors
  902. $this->setMessageType();
  903. // Refuse to send an empty message unless we are specifically allowing it
  904. if (!$this->AllowEmpty and empty($this->Body)) {
  905. throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  906. }
  907. $this->MIMEHeader = $this->createHeader();
  908. $this->MIMEBody = $this->createBody();
  909. // To capture the complete message when using mail(), create
  910. // an extra header list which createHeader() doesn't fold in
  911. if ($this->Mailer == 'mail') {
  912. if (count($this->to) > 0) {
  913. $this->mailHeader .= $this->addrAppend('To', $this->to);
  914. } else {
  915. $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  916. }
  917. $this->mailHeader .= $this->headerLine(
  918. 'Subject',
  919. $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  920. );
  921. }
  922. // Sign with DKIM if enabled
  923. if (!empty($this->DKIM_domain)
  924. && !empty($this->DKIM_private)
  925. && !empty($this->DKIM_selector)
  926. && !empty($this->DKIM_domain)
  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. $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE

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