PageRenderTime 74ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpmailer/phpmailer/class.phpmailer.php

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

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