PageRenderTime 86ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/mailer/class.phpmailer.php

https://bitbucket.org/svkem2/courseplanning
PHP | 3455 lines | 2027 code | 230 blank | 1198 comment | 344 complexity | eb35626641e227a9e6eaef1f1c66d52e MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.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 = ($exceptions == true);
  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. if (is_callable($this->Debugoutput)) {
  557. call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  558. return;
  559. }
  560. switch ($this->Debugoutput) {
  561. case 'error_log':
  562. //Don't output, just log
  563. error_log($str);
  564. break;
  565. case 'html':
  566. //Cleans up output a bit for a better looking, HTML-safe output
  567. echo htmlentities(
  568. preg_replace('/[\r\n]+/', '', $str),
  569. ENT_QUOTES,
  570. 'UTF-8'
  571. )
  572. . "<br>\n";
  573. break;
  574. case 'echo':
  575. default:
  576. //Normalize line breaks
  577. $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  578. echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  579. "\n",
  580. "\n \t ",
  581. trim($str)
  582. ) . "\n";
  583. }
  584. }
  585. /**
  586. * Sets message type to HTML or plain.
  587. * @param boolean $isHtml True for HTML mode.
  588. * @return void
  589. */
  590. public function isHTML($isHtml = true)
  591. {
  592. if ($isHtml) {
  593. $this->ContentType = 'text/html';
  594. } else {
  595. $this->ContentType = 'text/plain';
  596. }
  597. }
  598. /**
  599. * Send messages using SMTP.
  600. * @return void
  601. */
  602. public function isSMTP()
  603. {
  604. $this->Mailer = 'smtp';
  605. }
  606. /**
  607. * Send messages using PHP's mail() function.
  608. * @return void
  609. */
  610. public function isMail()
  611. {
  612. $this->Mailer = 'mail';
  613. }
  614. /**
  615. * Send messages using $Sendmail.
  616. * @return void
  617. */
  618. public function isSendmail()
  619. {
  620. $ini_sendmail_path = ini_get('sendmail_path');
  621. if (!stristr($ini_sendmail_path, 'sendmail')) {
  622. $this->Sendmail = '/usr/sbin/sendmail';
  623. } else {
  624. $this->Sendmail = $ini_sendmail_path;
  625. }
  626. $this->Mailer = 'sendmail';
  627. }
  628. /**
  629. * Send messages using qmail.
  630. * @return void
  631. */
  632. public function isQmail()
  633. {
  634. $ini_sendmail_path = ini_get('sendmail_path');
  635. if (!stristr($ini_sendmail_path, 'qmail')) {
  636. $this->Sendmail = '/var/qmail/bin/qmail-inject';
  637. } else {
  638. $this->Sendmail = $ini_sendmail_path;
  639. }
  640. $this->Mailer = 'qmail';
  641. }
  642. /**
  643. * Add a "To" address.
  644. * @param string $address
  645. * @param string $name
  646. * @return boolean true on success, false if address already used
  647. */
  648. public function addAddress($address, $name = '')
  649. {
  650. return $this->addAnAddress('to', $address, $name);
  651. }
  652. /**
  653. * Add a "CC" address.
  654. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  655. * @param string $address
  656. * @param string $name
  657. * @return boolean true on success, false if address already used
  658. */
  659. public function addCC($address, $name = '')
  660. {
  661. return $this->addAnAddress('cc', $address, $name);
  662. }
  663. /**
  664. * Add a "BCC" address.
  665. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  666. * @param string $address
  667. * @param string $name
  668. * @return boolean true on success, false if address already used
  669. */
  670. public function addBCC($address, $name = '')
  671. {
  672. return $this->addAnAddress('bcc', $address, $name);
  673. }
  674. /**
  675. * Add a "Reply-to" address.
  676. * @param string $address
  677. * @param string $name
  678. * @return boolean
  679. */
  680. public function addReplyTo($address, $name = '')
  681. {
  682. return $this->addAnAddress('Reply-To', $address, $name);
  683. }
  684. /**
  685. * Add an address to one of the recipient arrays.
  686. * Addresses that have been added already return false, but do not throw exceptions
  687. * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
  688. * @param string $address The email address to send to
  689. * @param string $name
  690. * @throws phpmailerException
  691. * @return boolean true on success, false if address already used or invalid in some way
  692. * @access protected
  693. */
  694. protected function addAnAddress($kind, $address, $name = '')
  695. {
  696. if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
  697. $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
  698. $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
  699. if ($this->exceptions) {
  700. throw new phpmailerException('Invalid recipient array: ' . $kind);
  701. }
  702. return false;
  703. }
  704. $address = trim($address);
  705. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  706. if (!$this->validateAddress($address)) {
  707. $this->setError($this->lang('invalid_address') . ': ' . $address);
  708. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  709. if ($this->exceptions) {
  710. throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  711. }
  712. return false;
  713. }
  714. if ($kind != 'Reply-To') {
  715. if (!isset($this->all_recipients[strtolower($address)])) {
  716. array_push($this->$kind, array($address, $name));
  717. $this->all_recipients[strtolower($address)] = true;
  718. return true;
  719. }
  720. } else {
  721. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  722. $this->ReplyTo[strtolower($address)] = array($address, $name);
  723. return true;
  724. }
  725. }
  726. return false;
  727. }
  728. /**
  729. * Set the From and FromName properties.
  730. * @param string $address
  731. * @param string $name
  732. * @param boolean $auto Whether to also set the Sender address, defaults to true
  733. * @throws phpmailerException
  734. * @return boolean
  735. */
  736. public function setFrom($address, $name = '', $auto = true)
  737. {
  738. $address = trim($address);
  739. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  740. if (!$this->validateAddress($address)) {
  741. $this->setError($this->lang('invalid_address') . ': ' . $address);
  742. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  743. if ($this->exceptions) {
  744. throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  745. }
  746. return false;
  747. }
  748. $this->From = $address;
  749. $this->FromName = $name;
  750. if ($auto) {
  751. if (empty($this->Sender)) {
  752. $this->Sender = $address;
  753. }
  754. }
  755. return true;
  756. }
  757. /**
  758. * Return the Message-ID header of the last email.
  759. * Technically this is the value from the last time the headers were created,
  760. * but it's also the message ID of the last sent message except in
  761. * pathological cases.
  762. * @return string
  763. */
  764. public function getLastMessageID()
  765. {
  766. return $this->lastMessageID;
  767. }
  768. /**
  769. * Check that a string looks like an email address.
  770. * @param string $address The email address to check
  771. * @param string $patternselect A selector for the validation pattern to use :
  772. * * `auto` Pick strictest one automatically;
  773. * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  774. * * `pcre` Use old PCRE implementation;
  775. * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;
  776. * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
  777. * * `noregex` Don't use a regex: super fast, really dumb.
  778. * @return boolean
  779. * @static
  780. * @access public
  781. */
  782. public static function validateAddress($address, $patternselect = 'auto')
  783. {
  784. if (!$patternselect or $patternselect == 'auto') {
  785. //Check this constant first so it works when extension_loaded() is disabled by safe mode
  786. //Constant was added in PHP 5.2.4
  787. if (defined('PCRE_VERSION')) {
  788. //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  789. if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
  790. $patternselect = 'pcre8';
  791. } else {
  792. $patternselect = 'pcre';
  793. }
  794. } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
  795. //Fall back to older PCRE
  796. $patternselect = 'pcre';
  797. } else {
  798. //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  799. if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  800. $patternselect = 'php';
  801. } else {
  802. $patternselect = 'noregex';
  803. }
  804. }
  805. }
  806. switch ($patternselect) {
  807. case 'pcre8':
  808. /**
  809. * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
  810. * @link http://squiloople.com/2009/12/20/email-address-validation/
  811. * @copyright 2009-2010 Michael Rushton
  812. * Feel free to use and redistribute this code. But please keep this copyright notice.
  813. */
  814. return (boolean)preg_match(
  815. '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  816. '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  817. '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  818. '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  819. '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  820. '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  821. '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  822. '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  823. '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  824. $address
  825. );
  826. case 'pcre':
  827. //An older regex that doesn't need a recent PCRE
  828. return (boolean)preg_match(
  829. '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  830. '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  831. '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  832. '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  833. '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  834. '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  835. '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  836. '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  837. '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  838. '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  839. $address
  840. );
  841. case 'html5':
  842. /**
  843. * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
  844. * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
  845. */
  846. return (boolean)preg_match(
  847. '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  848. '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  849. $address
  850. );
  851. case 'noregex':
  852. //No PCRE! Do something _very_ approximate!
  853. //Check the address is 3 chars or longer and contains an @ that's not the first or last char
  854. return (strlen($address) >= 3
  855. and strpos($address, '@') >= 1
  856. and strpos($address, '@') != strlen($address) - 1);
  857. case 'php':
  858. default:
  859. return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  860. }
  861. }
  862. /**
  863. * Create a message and send it.
  864. * Uses the sending method specified by $Mailer.
  865. * @throws phpmailerException
  866. * @return boolean false on error - See the ErrorInfo property for details of the error.
  867. */
  868. public function send()
  869. {
  870. try {
  871. if (!$this->preSend()) {
  872. return false;
  873. }
  874. return $this->postSend();
  875. } catch (phpmailerException $exc) {
  876. $this->mailHeader = '';
  877. $this->setError($exc->getMessage());
  878. if ($this->exceptions) {
  879. throw $exc;
  880. }
  881. return false;
  882. }
  883. }
  884. /**
  885. * Prepare a message for sending.
  886. * @throws phpmailerException
  887. * @return boolean
  888. */
  889. public function preSend()
  890. {
  891. try {
  892. $this->mailHeader = '';
  893. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  894. throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  895. }
  896. // Set whether the message is multipart/alternative
  897. if (!empty($this->AltBody)) {
  898. $this->ContentType = 'multipart/alternative';
  899. }
  900. $this->error_count = 0; // reset errors
  901. $this->setMessageType();
  902. // Refuse to send an empty message unless we are specifically allowing it
  903. if (!$this->AllowEmpty and empty($this->Body)) {
  904. throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  905. }
  906. $this->MIMEHeader = $this->createHeader();
  907. $this->MIMEBody = $this->createBody();
  908. // To capture the complete message when using mail(), create
  909. // an extra header list which createHeader() doesn't fold in
  910. if ($this->Mailer == 'mail') {
  911. if (count($this->to) > 0) {
  912. $this->mailHeader .= $this->addrAppend('To', $this->to);
  913. } else {
  914. $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  915. }
  916. $this->mailHeader .= $this->headerLine(
  917. 'Subject',
  918. $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  919. );
  920. }
  921. // Sign with DKIM if enabled
  922. if (!empty($this->DKIM_domain)
  923. && !empty($this->DKIM_private)
  924. && !empty($this->DKIM_selector)
  925. && !empty($this->DKIM_domain)
  926. && file_exists($this->DKIM_private)) {
  927. $header_dkim = $this->DKIM_Add(
  928. $this->MIMEHeader . $this->mailHeader,
  929. $this->encodeHeader($this->secureHeader($this->Subject)),
  930. $this->MIMEBody
  931. );
  932. $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  933. str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  934. }
  935. return true;
  936. } catch (phpmailerException $exc) {
  937. $this->setError($exc->getMessage());
  938. if ($this->exceptions) {
  939. throw $exc;
  940. }
  941. return false;
  942. }
  943. }
  944. /**
  945. * Actually send a message.
  946. * Send the email via the selected mechanism
  947. * @throws phpmailerException
  948. * @return boolean
  949. */
  950. public function postSend()
  951. {
  952. try {
  953. // Choose the mailer and send through it
  954. switch ($this->Mailer) {
  955. case 'sendmail':
  956. case 'qmail':
  957. return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  958. case 'smtp':
  959. return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
  960. case 'mail':
  961. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  962. default:
  963. $sendMethod = $this->Mailer.'Send';
  964. if (method_exists($this, $sendMethod)) {
  965. return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  966. }
  967. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  968. }
  969. } catch (phpmailerException $exc) {
  970. $this->setError($exc->getMessage());
  971. $this->edebug($exc->getMessage());
  972. if ($this->exceptions) {
  973. throw $exc;
  974. }
  975. }
  976. return false;
  977. }
  978. /**
  979. * Send mail using the $Sendmail program.
  980. * @param string $header The message headers
  981. * @param string $body The message body
  982. * @see PHPMailer::$Sendmail
  983. * @throws phpmailerException
  984. * @access protected
  985. * @return boolean
  986. */
  987. protected function sendmailSend($header, $body)
  988. {
  989. if ($this->Sender != '') {
  990. if ($this->Mailer == 'qmail') {
  991. $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  992. } else {
  993. $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  994. }
  995. } else {
  996. if ($this->Mailer == 'qmail') {
  997. $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  998. } else {
  999. $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  1000. }
  1001. }
  1002. if ($this->SingleTo === true) {
  1003. foreach ($this->SingleToArray as $toAddr) {
  1004. if (!@$mail = popen($sendmail, 'w')) {
  1005. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1006. }
  1007. fputs($mail, 'To: ' . $toAddr . "\n");
  1008. fputs($mail, $header);
  1009. fputs($mail, $body);
  1010. $result = pclose($mail);
  1011. $this->doCallback(
  1012. ($result == 0),
  1013. array($toAddr),
  1014. $this->cc,
  1015. $this->bcc,
  1016. $this->Subject,
  1017. $body,
  1018. $this->From
  1019. );
  1020. if ($result != 0) {
  1021. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1022. }
  1023. }
  1024. } else {
  1025. if (!@$mail = popen($sendmail, 'w')) {
  1026. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1027. }
  1028. fputs($mail, $header);
  1029. fputs($mail, $body);
  1030. $result = pclose($mail);
  1031. $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1032. if ($result != 0) {
  1033. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1034. }
  1035. }
  1036. return true;
  1037. }
  1038. /**
  1039. * Send mail using the PHP mail() function.
  1040. * @param string $header The message headers
  1041. * @param string $body The message body
  1042. * @link http://www.php.net/manual/en/book.mail.php
  1043. * @throws phpmailerException
  1044. * @access protected
  1045. * @return boolean
  1046. */
  1047. protected function mailSend($header, $body)
  1048. {
  1049. $toArr = array();
  1050. foreach ($this->to as $toaddr) {
  1051. $toArr[] = $this->addrFormat($toaddr);
  1052. }
  1053. $to = implode(', ', $toArr);
  1054. if (empty($this->Sender)) {
  1055. $params = ' ';
  1056. } else {
  1057. $params = sprintf('-f%s', $this->Sender);
  1058. }
  1059. if ($this->Sender != '' and !ini_get('safe_mode')) {
  1060. $old_from = ini_get('sendmail_from');
  1061. ini_set('sendmail_from', $this->Sender);
  1062. }
  1063. $result = false;
  1064. if ($this->SingleTo === true && count($toArr) > 1) {
  1065. foreach ($toArr as $toAddr) {
  1066. $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  1067. $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1068. }
  1069. } else {
  1070. $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  1071. $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1072. }
  1073. if (isset($old_from)) {
  1074. ini_set('sendmail_from', $old_from);
  1075. }
  1076. if (!$result) {
  1077. throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  1078. }
  1079. return true;
  1080. }
  1081. /**
  1082. * Get an instance to use for SMTP operations.
  1083. * Override this function to load your own SMTP implementation
  1084. * @return SMTP
  1085. */
  1086. public function getSMTPInstance()
  1087. {
  1088. if (!is_object($this->smtp)) {
  1089. $this->smtp = new SMTP;
  1090. }
  1091. return $this->smtp;
  1092. }
  1093. /**
  1094. * Send mail via SMTP.
  1095. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  1096. * Uses the PHPMailerSMTP class by default.
  1097. * @see PHPMailer::getSMTPInstance() to use a different class.
  1098. * @param string $header The message headers
  1099. * @param string $body The message body
  1100. * @throws phpmailerException
  1101. * @uses SMTP
  1102. * @access protected
  1103. * @return boolean
  1104. */
  1105. protected function smtpSend($header, $body)
  1106. {
  1107. $bad_rcpt = array();
  1108. if (!$this->smtpConnect()) {
  1109. throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  1110. }
  1111. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  1112. if (!$this->smtp->mail($smtp_from)) {
  1113. $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  1114. throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  1115. }
  1116. // Attempt to send to all recipients
  1117. foreach ($this->to as $to) {
  1118. if (!$this->smtp->recipient($to[0])) {
  1119. $bad_rcpt[] = $to[0];
  1120. $isSent = false;
  1121. } else {
  1122. $isSent = true;
  1123. }
  1124. $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  1125. }
  1126. foreach ($this->cc as $cc) {
  1127. if (!$this->smtp->recipient($cc[0])) {
  1128. $bad_rcpt[] = $cc[0];
  1129. $isSent = false;
  1130. } else {
  1131. $isSent = true;
  1132. }
  1133. $this->doCallback($isSent, array(), array($cc[0]), array(), $this->Subject, $body, $this->From);
  1134. }
  1135. foreach ($this->bcc as $bcc) {
  1136. if (!$this->smtp->recipient($bcc[0])) {
  1137. $bad_rcpt[] = $bcc[0];
  1138. $isSent = false;
  1139. } else {
  1140. $isSent = true;
  1141. }
  1142. $this->doCallback($isSent, array(), array(), array($bcc[0]), $this->Subject, $body, $this->From);
  1143. }
  1144. // Only send the DATA command if we have viable recipients
  1145. if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  1146. throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  1147. }
  1148. if ($this->SMTPKeepAlive == true) {
  1149. $this->smtp->reset();
  1150. } else {
  1151. $this->smtp->quit();
  1152. $this->smtp->close();
  1153. }
  1154. if (count($bad_rcpt) > 0) { // Create error message for any bad addresses
  1155. throw new phpmailerException(
  1156. $this->lang('recipients_failed') . implode(', ', $bad_rcpt),
  1157. self::STOP_CONTINUE
  1158. );
  1159. }
  1160. return true;
  1161. }
  1162. /**
  1163. * Initiate a connection to an SMTP server.
  1164. * Returns false if the operation failed.
  1165. * @param array $options An array of options compatible with stream_context_create()
  1166. * @uses SMTP
  1167. * @access public
  1168. * @throws phpmailerException
  1169. * @return boolean
  1170. */
  1171. public function smtpConnect($options = array())
  1172. {
  1173. if (is_null($this->smtp)) {
  1174. $this->smtp = $this->getSMTPInstance();
  1175. }
  1176. // Already connected?
  1177. if ($this->smtp->connected()) {
  1178. return true;
  1179. }
  1180. $this->smtp->setTimeout($this->Timeout);
  1181. $this->smtp->setDebugLevel($this->SMTPDebug);
  1182. $this->smtp->setDebugOutput($this->Debugoutput);
  1183. $this->smtp->setVerp($this->do_verp);
  1184. $hosts = explode(';', $this->Host);
  1185. $lastexception = null;
  1186. foreach ($hosts as $hostentry) {
  1187. $hostinfo = array();
  1188. if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  1189. // Not a valid host entry
  1190. continue;
  1191. }
  1192. // $hostinfo[2]: optional ssl or tls prefix
  1193. // $hostinfo[3]: the hostname
  1194. // $hostinfo[4]: optional port number
  1195. // The host string prefix can temporarily override the current setting for SMTPSecure
  1196. // If it's not specified, the default value is used
  1197. $prefix = '';
  1198. $tls = ($this->SMTPSecure == 'tls');
  1199. if ($hostinfo[2] == 'ssl' or ($hostinfo[2] == '' and $this->SMTPSecure == 'ssl')) {
  1200. $prefix = 'ssl://';
  1201. $tls = false; // Can't have SSL and TLS at once
  1202. } elseif ($hostinfo[2] == 'tls') {
  1203. $tls = true;
  1204. // tls doesn't use a prefix
  1205. }
  1206. $host = $hostinfo[3];
  1207. $port = $this->Port;
  1208. $tport = (integer)$hostinfo[4];
  1209. if ($tport > 0 and $tport < 65536) {
  1210. $port = $tport;
  1211. }
  1212. if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  1213. try {
  1214. if ($this->Helo) {
  1215. $hello = $this->Helo;
  1216. } else {
  1217. $hello = $this->serverHostname();
  1218. }
  1219. $this->smtp->hello($hello);
  1220. if ($tls) {
  1221. if (!$this->smtp->startTLS()) {
  1222. throw new phpmailerException($this->lang('connect_host'));
  1223. }
  1224. // We must resend HELO after tls negotiation
  1225. $this->smtp->hello($hello);
  1226. }
  1227. if ($this->SMTPAuth) {
  1228. if (!$this->smtp->authenticate(
  1229. $this->Username,
  1230. $this->Password,
  1231. $this->AuthType,
  1232. $this->Realm,
  1233. $this->Workstation
  1234. )
  1235. ) {
  1236. throw new phpmailerException($this->lang('authenticate'));
  1237. }
  1238. }
  1239. return true;
  1240. } catch (phpmailerException $exc) {
  1241. $lastexception = $exc;
  1242. // We must have connected, but then failed TLS or Auth, so close connection nicely
  1243. $this->smtp->quit();
  1244. }
  1245. }
  1246. }
  1247. // If we get here, all connection attempts have failed, so close connection hard
  1248. $this->smtp->close();
  1249. // As we've caught all exceptions, just report whatever the last one was
  1250. if ($this->exceptions and !is_null($lastexception)) {
  1251. throw $lastexception;
  1252. }
  1253. return false;
  1254. }
  1255. /**
  1256. * Close the active SMTP session if one exists.
  1257. * @return void
  1258. */
  1259. public function smtpClose()
  1260. {
  1261. if ($this->smtp !== null) {
  1262. if ($this->smtp->connected()) {
  1263. $this->smtp->quit();
  1264. $this->smtp->close();
  1265. }
  1266. }
  1267. }
  1268. /**
  1269. * Set the language for error messages.
  1270. * Returns false if it cannot load the language file.
  1271. * The default language is English.
  1272. * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
  1273. * @param string $lang_path Path to the language file directory, with trailing separator (slash)
  1274. * @return boolean
  1275. * @access public
  1276. */
  1277. public function setLanguage($langcode = 'en', $lang_path = '')
  1278. {
  1279. // Define full set of translatable strings in English
  1280. $PHPMAILER_LANG = array(
  1281. 'authenticate' => 'SMTP Error: Could not authenticate.',
  1282. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  1283. 'data_not_accepted' => 'SMTP Error: data not accepted.',
  1284. 'empty_message' => 'Message body empty',
  1285. 'encoding' => 'Unknown encoding: ',
  1286. 'execute' => 'Could not execute: ',
  1287. 'file_access' => 'Could not access file: ',
  1288. 'file_open' => 'File Error: Could not open file: ',
  1289. 'from_failed' => 'The following From address failed: ',
  1290. 'instantiate' => 'Could not instantiate mail function.',
  1291. 'invalid_address' => 'Invalid address',
  1292. 'mailer_not_supported' => ' mailer is not supported.',
  1293. 'provide_address' => 'You must provide at least one recipient email address.',
  1294. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  1295. 'signing' => 'Signing Error: ',
  1296. 'smtp_connect_failed' => 'SMTP connect() failed.',
  1297. 'smtp_error' => 'SMTP server error: ',
  1298. 'variable_set' => 'Cannot set or reset variable: '
  1299. );
  1300. if (empty($lang_path)) {
  1301. // Calculate an absolute path so it can work if CWD is not here
  1302. $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  1303. }
  1304. $foundlang = true;
  1305. $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  1306. if ($langcode != 'en') { // There is no English translation file
  1307. // Make sure language file path is readable
  1308. if (!is_readable($lang_file)) {
  1309. $foundlang = false;
  1310. } else {
  1311. // Overwrite language-specific strings.
  1312. // This way we'll never have missing translations.
  1313. $foundlang = include $lang_file;
  1314. }
  1315. }
  1316. $this->language = $PHPMAILER_LANG;
  1317. return ($foundlang == true); // Returns false if language not found
  1318. }
  1319. /**
  1320. * Get the array of strings for the current language.
  1321. * @return array
  1322. */
  1323. public function getTranslations()
  1324. {
  1325. return $this->language;
  1326. }
  1327. /**
  1328. * Create recipient headers.
  1329. * @access public
  1330. * @param string $type
  1331. * @param array $addr An array of recipient,
  1332. * where each recipient is a 2-element indexed array with element 0 containing an address
  1333. * and element 1 containing a name, like:
  1334. * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
  1335. * @return string
  1336. */
  1337. public function addrAppend($type, $addr)
  1338. {
  1339. $addresses = array();
  1340. foreach ($addr as $address) {
  1341. $addresses[] = $this->addrFormat($address);
  1342. }
  1343. return $type . ': ' . implode(', ', $addresses) . $this->LE;
  1344. }
  1345. /**
  1346. * Format an address for use in a message header.
  1347. * @access public
  1348. * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
  1349. * like array('joe@example.com', 'Joe User')
  1350. * @return string
  1351. */
  1352. public function addrFormat($addr)
  1353. {
  1354. if (empty($addr[1])) { // No name provided
  1355. return $this->secureHeader($addr[0]);
  1356. } else {
  1357. return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
  1358. $addr[0]
  1359. ) . '>';
  1360. }
  1361. }
  1362. /**
  1363. * Word-wrap message.
  1364. * For use with mailers that do not automatically perform wrapping
  1365. * and for quoted-printable encoded messages.
  1366. * Original written by philippe.
  1367. * @param string $message The message to wrap
  1368. * @param integer $length The line length to wrap to
  1369. * @param boolean $qp_mode Whether to run in Quoted-Printable mode
  1370. * @access public
  1371. * @return string
  1372. */
  1373. public function wrapText($message, $length, $qp_mode = false)
  1374. {
  1375. $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
  1376. // If utf-8 encoding is used, we will need to make sure we don't
  1377. // split multibyte characters when we wrap
  1378. $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  1379. $lelen = strlen($this->LE);
  1380. $crlflen = strlen(self::CRLF);
  1381. $message = $this->fixEOL($message);
  1382. if (substr($message, -$lelen) == $this->LE) {
  1383. $message = substr($message, 0, -$lelen);
  1384. }
  1385. $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
  1386. $message = '';
  1387. for ($i = 0; $i < count($line); $i++) {
  1388. $line_part

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