PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/PHPMailer/class.phpmailer.php

https://github.com/bobaz/formularioPHP
PHP | 3414 lines | 2001 code | 230 blank | 1183 comment | 342 complexity | f922ed6177949a00d180489bc9da21ec MD5 | raw file
Possible License(s): LGPL-2.1

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

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

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