willysec_id

NinjaMailer

Jul 2nd, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 216.68 KB | Cybersecurity | 0 0
  1. <?php
  2. /**
  3.  * TeamCC NinjaMailer
  4.  * @version : 1.3.3.7
  5. **/
  6.  
  7. $password = "thundercash"; // Password
  8.  
  9. session_start();
  10. ini_set( 'display_errors', 0 );
  11. error_reporting( 0 );
  12. set_time_limit(0);
  13. ini_set("memory_limit",-1);
  14.  
  15. $ninjax['version']="1.3.3.7";
  16. $ninjax['website']="TEAM.CC";
  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. error_reporting(0);
  31. set_time_limit(0);
  32. function randString($consonants) {
  33.     $length=rand(12,25);
  34.     $password = '';
  35.     for ($i = 0; $i < $length; $i++) {
  36.             $password .= $consonants[(rand() % strlen($consonants))];
  37.     }
  38.     return $password;
  39. }
  40. function lufClear($text,$email){
  41.     $e = explode('@', $email);
  42.     $emailuser=$e[0];
  43.     $emaildomain=$e[1];
  44.     $text = str_replace("[-time-]", date("d/m/Y h:i:s a", time()), $text);
  45.     $text = str_replace("[-email-]", $email, $text);
  46.     $text = str_replace("[-emailuser-]", $emailuser, $text);
  47.     $text = str_replace("[-emaildomain-]", $emaildomain, $text);
  48.     $text = str_replace("[-randomletters-]", randString('abcdefghijklmnopqrstuvwxyz'), $text);
  49.     $text = str_replace("[-randomstring-]", randString('abcdefghijklmnopqrstuvwxyz0123456789'), $text);
  50.     $text = str_replace("[-randomnumber-]", randString('0123456789'), $text);
  51.     $text = str_replace("[-randommd5-]", md5(randString('abcdefghijklmnopqrstuvwxyz0123456789')), $text);
  52.     return $text;  
  53. }
  54. $message_base="Message Here";$action="";$message="ilpasha";$emaillist="your_email@yahoo.com";$from="";$reconnect="0";$epriority="";$my_smtp="";$ssl_port="587";$encodety="";$replyto="";$subject="Yes";$realname="Yes Man";$subject_base="Subject Here";$realname_base="Support";$contenttype="";$isbcc="";$nbcc="50";$default_system="";$from_base="";$debg="0";$pause=0;$pemails=0;$nm=0;$nopose=true;$nrotat=0;$curentsmtp=0;$canrotat=false;$allsmtps="";$lase="";$reading=false;$repaslog=false;$uploadfile="";
  55. if(!empty($_POST))
  56. {    
  57.     $debg=lrtrim($_POST['dbg']);
  58.     if(!empty($_POST['from']))
  59.     {
  60.         $from=lrtrim($_POST['from']);
  61.         $from_base =$from;
  62.     }
  63.     $action=lrtrim($_POST['action']);
  64.     $message=lrtrim($_POST['message']);
  65.     $message_base=lrtrim($_POST['message']);
  66.     $emaillist=lrtrim($_POST['emaillist']);
  67.     $reconnect=lrtrim($_POST['reconnect']);
  68.     $epriority=lrtrim($_POST['epriority']);
  69.     $my_smtp=lrtrim($_POST['my_smtp']);
  70.     $subject=lrtrim($_POST['subject']);
  71.     $realname=lrtrim($_POST['realname']);
  72.     $subject_base=lrtrim($_POST['subject']);
  73.     $realname_base=lrtrim($_POST['realname']);
  74.     $contenttype=lrtrim($_POST['contenttype']);
  75.     $encodety=$_POST['encodety'];
  76.     if(!empty($_POST['pause']))
  77.     $pause=$_POST['pause'];
  78.     if(!empty($_POST['replyto']))
  79.     $replyto=lrtrim($_POST['replyto']);
  80.     if(!empty($_POST['nrotat']))
  81.     $nrotat=$_POST['nrotat'];
  82.     if(!empty($_POST['pemails']))
  83.     $pemails=$_POST['pemails'];
  84.     if(!empty($_POST['lase']))
  85.     $lase=true;
  86.     if(!empty($_POST['nbcc']))
  87.     $nbcc=lrtrim($_POST['nbcc']);
  88.     $allsmtps =  preg_split("/\\r\\n|\\r|\\n/", $my_smtp);
  89.     if(!empty($_POST['readingconf']))
  90.     $reading=true;
  91.     if(!empty($_POST['repaslog']))
  92.     $repaslog=true;
  93. }
  94. ?>
  95. <html>
  96.  
  97. <head>
  98. <title>PHP Mailer</title>
  99. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  100. <script
  101.               src="https://code.jquery.com/jquery-3.1.1.min.js"
  102.               integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  103.               crossorigin="anonymous"></script>
  104. <style type="text/css">
  105. #more {display: none;}
  106. <!--
  107. .style1 {
  108.         font-family: Geneva, Arial, Helvetica, sans-serif;
  109.         font-size: 12px;
  110. }
  111. -->
  112. </style>
  113. <style type="text/css">
  114. <!--
  115. .style1 {
  116.         font-size: 10px;
  117.         font-family: Geneva, Arial, Helvetica, sans-serif;
  118. }
  119. -->
  120. .td1 {
  121.     width:150px;
  122. }
  123. </style>
  124. </head>
  125. <body text="#000000">
  126. <script>
  127. function readmore() {
  128.   var dots = document.getElementById("dots");
  129.   var moreText = document.getElementById("more");
  130.   var btnText = document.getElementById("readmorebtn");
  131.  
  132.   if (dots.style.display === "none") {
  133.     dots.style.display = "inline";
  134.     btnText.innerHTML = "Read more";
  135.     moreText.style.display = "none";
  136.   } else {
  137.     dots.style.display = "none";
  138.     btnText.innerHTML = "Read less";
  139.     moreText.style.display = "inline";
  140.   }
  141. }
  142. $(document).ready(function(){
  143.     $("#patb").click(function(){
  144.         if($("#az").prop( "checked" ) || $("#AZ").prop( "checked" ) || $("#09").prop( "checked" ) && $("#len").val() != "")
  145.         {
  146.             $("#patval").val("");
  147.             $("#patval").val($("#patval").val() + "##");
  148.             if($("#az").prop( "checked" ))
  149.             {
  150.                 $("#patval").val($("#patval").val() + "az-");
  151.             }
  152.              if($("#AZ").prop( "checked" ))
  153.             {
  154.                 $("#patval").val($("#patval").val() + "AZ-");
  155.             }
  156.              if($("#09").prop( "checked" ))
  157.             {
  158.                 $("#patval").val($("#patval").val() + "09-");
  159.             }
  160.             if($("#len").val() != "")
  161.             {
  162.                 $("#patval").val($("#patval").val() + "{"+$("#len").val()+ "}");
  163.             }
  164.             $("#patval").val($("#patval").val() + "##");
  165.            
  166.         }
  167.         else $("#patval").val("");
  168.     });
  169.     $("#add").click(function(){
  170.         if($('#my_smtp').html()=="")
  171.             $('#my_smtp').html($('#ip').val()+':'+$('#ssl_port').val()+':'+$('#user').val()+':'+$('#pass').val()+":"+$('input[name=SSLTLS]:checked').val());
  172.         else
  173.             $('#my_smtp').html($('#my_smtp').html()+$('#ip').val()+':'+$('#ssl_port').val()+':'+$('#user').val()+':'+$('#pass').val()+":"+$('input[name=SSLTLS]:checked').val());
  174.         if($('input[name=isbcc]').prop('checked')) $('#my_smtp').html($('#my_smtp').html()+':BCC');
  175.         else $('#my_smtp').html($('#my_smtp').html()+':NOBCC');
  176.         $('#my_smtp').html($('#my_smtp').html()+'\n');
  177.         $('#user').val("");
  178.         $('#pass').val("");
  179.         $('input[name=SSLTLS]').prop('checked', false);
  180.     });
  181.     $("#reset").click(function(){
  182.         $('#my_smtp').html('');
  183.     });
  184.     $("input[name=lase]").click(function(){
  185.         if($('input[name=lase]').prop('checked'))
  186.         {
  187.             $('input[name=from]').attr('disabled','disabled');
  188.             $('input[name=from]').val('');
  189.         }
  190.         else
  191.             $('input[name=from]').removeAttr('disabled');
  192.     });
  193.     $("input[name=repaslog]").click(function(){
  194.         if($('input[name=repaslog]').prop('checked'))
  195.         {
  196.             $('input[name=replyto]').attr('disabled','disabled');
  197.             $('input[name=replyto]').val('');
  198.         }
  199.         else
  200.             $('input[name=replyto]').removeAttr('disabled');
  201.     });
  202. });
  203. </script>
  204. <p align="center"><font size="5" face="Bauhaus 93">MAILER INBOX SENDING</font><font color="#FFFFFF" size="5" face="Bauhaus 93">LFX</font></p>
  205. <form name="form1" method="post" action="" enctype="multipart/form-data">
  206.  
  207.   <br>
  208.  
  209.   <table width="100%" border="0" height="407">
  210.  
  211.     <tr>
  212.  
  213.       <td width="100%" colspan="4" bgcolor="#2079cd" height="36">
  214.  
  215.         <b>
  216.  
  217.         <font face="Arial" size="2" color="#FFFFFF">&nbsp;SERVER SETUP</font>&nbsp;&nbsp;&nbsp;&nbsp;<font face="Arial" size="2" color="red">DEBUG LVL</font>&nbsp;&nbsp;
  218.         <select name="dbg">
  219.             <option value="0" <?php echo ($debg == "0") ? 'selected=selected':''; ?>>OFF</option>
  220.             <option value="1" <?php echo ($debg == "1") ? 'selected=selected':''; ?>>1</option>
  221.             <option value="2" <?php echo ($debg == "2") ? 'selected=selected':''; ?>>2</option>
  222.             <option value="3" <?php echo ($debg == "3") ? 'selected=selected':''; ?>>3</option>
  223.             <option value="4" <?php echo ($debg == "4") ? 'selected=selected':''; ?>>4</option>
  224.         </select></b></td>
  225.  
  226.       </tr>
  227.  
  228.     <tr>
  229.  
  230.       <td  height="22" bgcolor="#E8E8E8" class="td1">
  231.  
  232.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  233.             SMTP Host:</font></div>
  234.  
  235.       </td>
  236.  
  237.       <td  height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  238.  
  239.         <input type="text" id="ip" name="ip" value="" size="30">
  240.  
  241.         </font></td>
  242.  
  243.       <td  height="22" bgcolor="#E8E8E8" rowspan="2">
  244.  
  245.         <div align="right">
  246.           <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP CONFIG:</font></div>
  247.       </td>
  248.  
  249.       <td  height="22" bgcolor="#E8E8E8" rowspan="2">
  250.  
  251.         <textarea readonly type="text" id="my_smtp" name="my_smtp"  cols="49D2SNGzC9GHcrUUaqinbv3Z2PLFKvxxmFNNsY6aQG72DmWbGET77srS3bd7S1wwYLTnyPqURASpx15UMac6uZKxFzSmgvJ, Arial, Helvetica, sans-serif"><SPAN style="display:block;float:left;">&nbsp;&nbsp;Every&nbsp;&nbsp;</span><input name="nrotat" type="text" style="width:50px;float:left;" value="<?php echo $nrotat;?>">&nbsp;&nbsp;EMAIL'S
  252.  
  253.         </font><br><br><br><input type="button" name="reset" id="reset" value="reset"></td>
  254.  
  255.     </tr>
  256.     <tr>
  257.  
  258.       <td class="td1" height="22" bgcolor="#E8E8E8">
  259.  
  260.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  261.             SMTP LOGIN:</font></div>
  262.  
  263.       </td>
  264.  
  265.       <td  height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  266.  
  267.         <input type="text" id="user" name="user" value="" size="30"><br>
  268.         <input type="password" id="pass" name="pass" value="" size="30"><BR>
  269.        
  270.  
  271.         </font></td>
  272.         <td  height="22" bgcolor="#E8E8E8">
  273.  
  274.         </td>
  275.  
  276.     </tr>
  277.     <tr>
  278.  
  279.       <td class="td1"  height="22" bgcolor="#E8E8E8">
  280.  
  281.         <div align="right">
  282.           <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div>
  283.  
  284.       </td>
  285.  
  286.       <td  height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  287.  
  288.         <input type="text" name="ssl_port" id="ssl_port" value="<?php echo $ssl_port;?>" size="5"> <input type="button" name="add" id="add" value="add smtp"></font></td>
  289.  
  290.       <td  height="22" bgcolor="#E8E8E8">
  291.  
  292.         <div align="right">
  293.           <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SEND PAUSE:</font></div>
  294.  
  295.       </td>
  296.       <td width="49D2SNGzC9GHcrUUaqinbv3Z2PLFKvxxmFNNsY6aQG72DmWbGET77srS3bd7S1wwYLTnyPqURASpx15UMac6uZKxFzSmgvJ">
  297.  
  298.         <input type="text" name="pause"  value="<?php echo $pause;?>" style="width:50px;"/>&nbsp;sec evrey&nbsp;<input type="text" name="pemails"  value="<?php echo $pemails;?>" style="width:50px;"/>&nbsp;email's <span style="color:red;">(1 bcc = 1 email)<span>
  299.  
  300.         </font></td>
  301.  
  302.     </tr>
  303.     <tr>
  304.  
  305.       <td class="td1" height="22" bgcolor="#E8E8E8">
  306.  
  307.         <p align="right">
  308.         <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td>
  309.  
  310.       <td  height="22" bgcolor="#E8E8E8">
  311.       <input type="radio" name="SSLTLS" value="SSL"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(SSL)</font>
  312.       <input type="radio" name="SSLTLS" value="TLS"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(TLS)</font>
  313.       <input type="radio" name="SSLTLS" value="NON"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(NON)</font>
  314.       </td>
  315.  
  316.       <td height="22" bgcolor="#E8E8E8">
  317.  
  318.         <p align="right">
  319.         <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">RECONNECT
  320.         AFTER:</font></td>
  321.  
  322.       <td  height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  323.  
  324.         <input type="text" name="reconnect" value="<?php echo $reconnect;?>" size="5">
  325.       EMAILS</font></td>
  326.  
  327.     </tr>
  328.     <tr>
  329.  
  330.       <td class="td1" height="22" bgcolor="#E8E8E8">
  331.  
  332.         <p align="right">
  333.         <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">IS BCC:</font>
  334.     </td>
  335.  
  336.       <td  height="22" bgcolor="#E8E8E8">
  337.       <input type="checkbox" name="isbcc" value="true" <?php if($isbcc=="true") echo "checked"; ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
  338.  
  339.       <td  height="22" bgcolor="#E8E8E8">
  340.  
  341.         <p align="right">
  342.         <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">NUM OF EMAIL IN BCC :</font></td>
  343.  
  344.       <td  height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  345.  
  346.         <input type="text" name="nbcc" value="<?php echo $nbcc;?>" size="5">
  347.       EMAIL'S</font></td>
  348.  
  349.     </tr>
  350.     <tr>
  351.  
  352.       <td width="100%" height="39" bgcolor="#E8E8E8" colspan="4">
  353.  
  354.         <p align="center">
  355.         <font face="Arial" style="font-size: 9pt" color="#800000"><b>&quot;</b> IF
  356.         YOU DON'T HAVE SMTP LOGIN INFORMATION'S, LEAVE BLANK TO SEND WITH LOCALHOST <b>&quot;</b></font></td>
  357.  
  358.       </tr>
  359.  
  360.     <tr>
  361.  
  362.       <td class="td1" height="19">
  363.  
  364.         &nbsp;</td>
  365.  
  366.       <td  height="19">&nbsp;</td>
  367.  
  368.       <td width="31%" height="19">
  369.  
  370.         &nbsp;</td>
  371.  
  372.       <td width="41%" height="19">&nbsp;</td>
  373.  
  374.     </tr>
  375.  
  376.     <tr>
  377.  
  378.       <td width="100%" colspan="4" bgcolor="#2079cd" height="36">
  379.  
  380.         <b>
  381.  
  382.         <font face="Arial" size="2" color="#FFFFFF">&nbsp;MESSAGE SETUP</font></b></td>
  383.  
  384.       </tr>
  385.  
  386.     <tr>
  387.  
  388.       <td class="td1"  height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  389.  
  390.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  391.             Your Email:</font></div>
  392.  
  393.       </td>
  394.  
  395.       <td  height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  396.  
  397.         <input type="text" name="from" value="<?php if(!$lase) echo $from_base;?>" size="30" <?php if($lase) echo "disabled"?> >
  398.         <input type="checkbox" name="lase" value="true" <?php if($lase) echo "checked"; ?> >EMAIL as LOGIN
  399.         </font></td>
  400.  
  401.       <td width="31%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  402.  
  403.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  404.             Your Name:</font></div>
  405.  
  406.       </td>
  407.  
  408.       <td width="49D2SNGzC9GHcrUUaqinbv3Z2PLFKvxxmFNNsY6aQG72DmWbGET77srS3bd7S1wwYLTnyPqURASpx15UMac6uZKxFzSmgvJHelvetica, sans-serif">
  409.  
  410.         <input type="text" name="realname" value="<?php echo $realname_base;?>" size="30">
  411.  
  412.         </font></td>
  413.  
  414.     </tr>
  415.     <tr>
  416.  
  417.       <td class="td1" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
  418.  
  419.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  420.             Reply-To:</font></div>
  421.  
  422.       </td>
  423.  
  424.       <td  height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  425.  
  426.         <input type="text" name="replyto" value="<?php if(!$repaslog) echo $replyto;?>" size="30" <?php if($repaslog) echo "disabled";?>><input type="checkbox" name="repaslog" value="true" <?php if($repaslog) echo "checked"; ?> >REPLY as LOGIN
  427.         <input type="checkbox" name="readingconf" value="true" <?php if($reading) echo "checked"; ?> >CONFIRM READING
  428.         </font></td>
  429.  
  430.       <td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
  431.  
  432.         <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  433.         Email Priority:</font></td>
  434.  
  435.       <td width="49D2SNGzC9GHcrUUaqinbv3Z2PLFKvxxmFNNsY6aQG72DmWbGET77srS3bd7S1wwYLTnyPqURASpx15UMac6uZKxFzSmgvJHelvetica, sans-serif">
  436.  
  437.         &nbsp;</font><select name="epriority" id="listMethod" onchange="showHideListConfig()">
  438.         <option value="" <?php if(strlen($epriority)< 1){print "selected";} ?> >
  439.         NO PRIORITY</option>
  440.         <option value="1" <?php if($epriority == "1"){print "selected";} ?> >HIGH</option>
  441.         <option value="3" <?php if($epriority == "3"){print "selected";} ?> >NORMAL</option>
  442.         <option value="5" <?php if($epriority == "5"){print "selected";} ?> >LOW</option>
  443.         </select></td>
  444.  
  445.     </tr>
  446.  
  447.     <tr>
  448.  
  449.       <td class="td1" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  450.  
  451.         <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  452.             Subject:</font></div>
  453.  
  454.       </td>
  455.  
  456.       <td  height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  457.  
  458.         <input type="text" name="subject" value="<?php echo $subject_base;?>" size="90">
  459.  
  460.         </font></td><td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
  461.  
  462.         <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  463.         <font size="-3" face="Verdana, Arial, Helvetica, sans-serif" color="#FF0000">
  464.         ENCODE SENDING </font>/ CHARSET :</font></td><td width="49D2SNGzC9GHcrUUaqinbv3Z2PLFKvxxmFNNsY6aQG72DmWbGET77srS3bd7S1wwYLTnyPqURASpx15UMac6uZKxFzSmgvJHelvetica, sans-serif">
  465.  
  466.         &nbsp;</font><select size="1" name="encodety">
  467.         <option value="no" <?php if($encodety == "no"){print "selected";} ?>>NO</option>
  468.         <option value="8bit" <?php if($encodety == "8bit"){print "selected";} ?>>8bit</option>
  469.         <option value="7bit" <?php if($encodety == "7bit"){print "selected";} ?>>7bit</option>
  470.         <option value="binary" <?php if($encodety == "binary"){print "selected";} ?>>binary</option>
  471.         <option value="base64" <?php if($encodety == "base64"){print "selected";} ?>>base64</option>
  472.         <option value="quoted-printable" <?php if($encodety == "quoted-printable"){print "selected";} ?>>quoted-printable</option>
  473.         </select><select name="epriority" id="listMethod" onchange="showHideListConfig()">
  474.         <option value="" selected="">NO CHARSET</option>
  475.                 <option value="us-ascii">Unicode -> us-ascii</option>
  476.         <option value="utf-7">Unicode -> utf-7</option>
  477.         <option value="utf-8">Unicode -> utf-8</option>
  478.         <option value="iso-10646-ucs-2">Unicode -> iso-10646-ucs-2</option>
  479.         <option value="iso-8859-6">Arabic -> iso-8859-6</option>
  480.         <option value="x-mac-arabic">Arabic -> x-mac-arabic</option>
  481.         <option value="windows-1256">Arabic -> windows-1256</option>
  482.         <option value="iso-8859-4">Baltic -> iso-8859-4</option>
  483.         <option value="windows-1257">Baltic -> windows-1257</option>
  484.         <option value="iso-8859-2">Central European -> iso-8859-2</option>
  485.         <option value="x-mac-ce">Central European -> x-mac-ce</option>
  486.         <option value="windows-1250">Central European -> windows-1250</option>
  487.         <option value="euc-cn">Chinese -> euc-cn</option>
  488.         <option value="gb2312">Chinese -> gb2312</option>
  489.         <option value="hz-gb-2312">Chinese -> hz-gb-2312    </option>
  490.         <option value="x-mac-chinesesimp">Chinese -> x-mac-chinesesimp</option>
  491.         <option value="cp-936">Chinese -> cp-936</option>
  492.         <option value="big5">Chinese -> big5</option>
  493.         <option value="x-mac-chinesetrad">Chinese -> x-mac-chinesetrad</option>
  494.         <option value="cp-950">Chinese -> cp-950</option>
  495.         <option value="cp-932">Chinese -> cp-932</option>
  496.         <option value="euc-tw">Chinese -> euc-tw</option>
  497.         </select></td>
  498.  
  499.     </tr>
  500.  
  501.     <tr>
  502.  
  503.       <td class="td1" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  504.  
  505.             <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  506.             Generateur:</font></div></td>
  507.  
  508.       <td width="35%" colspan="" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  509.       (a-z)<input type="checkbox" name="az" id="az">
  510.       (A-Z)<input type="checkbox" name="AZ" id="AZ">
  511.       (0-9)<input type="checkbox" name="09" id="09">
  512.       (LENHGT)<input type="text" maxlength=2 size=1 name="len" id="len">
  513.       (#PATTERN)<input type="text" name="patval" id="patval">
  514.       <input type="button" value="GET PATTERN" id="patb" name="patb">
  515.       </td>
  516.       <td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
  517.  
  518.         <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  519.         <font size="-3" face="Verdana, Arial, Helvetica, sans-serif" >
  520.         ATTACH :</font>
  521.         </td>
  522.         <td width="41%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"></font><input name="userfile" type="file"></td>
  523.     </tr>
  524.  
  525.     <tr valign="top">
  526.  
  527. <td colspan="3" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
  528.  
  529.         <textarea name="message" value=""cols="60" rows="10"><?php echo $message_base;?></textarea>
  530.  
  531.         <br>
  532.  
  533.         <input type="radio" name="contenttype" value="plain" >
  534.  
  535.         TEXT
  536.  
  537.         <input type="radio" name="contenttype" value="html" checked>
  538.  
  539.         HTML
  540.  
  541.         <input type="hidden" name="action" value="send">
  542.  
  543.         <input type="submit" value="Send Message">
  544.  
  545.         </font></td>
  546.  
  547.       <td width="41%" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  548.  
  549.         <textarea name="emaillist" value="" cols="30" rows="10"><?php echo $emaillist;?></textarea>
  550.  
  551.         </font></td>
  552.  
  553.     </tr>
  554.  
  555.   </table>
  556.  
  557. </form>
  558. <div id="well" class="well well">
  559.     <h4>HELP<span id="dots">...</span></h4>
  560.     <button onclick="readmore()" id="readmorebtn">Read more</button>
  561.     <span id="more">
  562.         <ul>
  563.             <li>[-email-] : <b>Reciver Email</b> (emailuser@emaildomain.com)</li>
  564.             <ul>
  565.                 <li>[-emailuser-] : <b>Email User</b> (emailuser) </li>
  566.                 <li>[-emaildomain-] : <b>Email User</b> (emaildomain.com) </li>
  567.             </ul>
  568.             <li>[-time-] : <b>Date and Time</b> (03/04/2021 02:41:23 pm)</li>
  569.            
  570.             <li>[-randomstring-] : <b>Random string (0-9,a-z)</b></li>
  571.             <li>[-randomnumber-] : <b>Random number (0-9) </b></li>
  572.             <li>[-randomletters-] : <b>Random Letters(a-z) </b></li>
  573.             <li>[-randommd5-] : <b>Random MD5 </b></li>
  574.         </ul>
  575.         <h4>example</h4>
  576.         Receiver Email = <b>user@domain.com</b><br>
  577.         <ul>
  578.             <li>hello <b>[-emailuser-]</b> = hello <b>user</b></li>
  579.             <li>your domain is <b>[-emaildomain-]</b> = Your Domain is <b>domain.com</b></li>
  580.             <li>your code is  <b>[-randommd5-]</b> = your code is <b>e10adc3949ba59abbe56e057f20f883e</b></li>
  581.         </ul>
  582.     </span>
  583. </div>
  584. <?php print "<p class=\"style1\">PHP Mailer &copy ".date("Y").", <b><font color=\"#800000\">BY LuFix.to</font><span style=\"color:red\">&nbsp;&nbsp;Site: LuFix.to<br></span></b></p>"; ?>
  585.     </body>
  586. </html>
  587.  
  588.  
  589. <?php
  590.  
  591.  
  592.  
  593. class SMTP
  594. {
  595.     /**
  596.      * The PHPMailer SMTP version number.
  597.      * @var string
  598.      */
  599.     const VERSION = '5.2.17';
  600.     /**
  601.      * SMTP line break constant.
  602.      * @var string
  603.      */
  604.     const CRLF = "\r\n";
  605.     /**
  606.      * The SMTP port to use if one is not specified.
  607.      * @var integer
  608.      */
  609.     const DEFAULT_SMTP_PORT = 25;
  610.     /**
  611.      * The maximum line length allowed by RFC 2822 section 2.1.1
  612.      * @var integer
  613.      */
  614.     const MAX_LINE_LENGTH = 998;
  615.     /**
  616.      * Debug level for no output
  617.      */
  618.     const DEBUG_OFF = 0;
  619.     /**
  620.      * Debug level to show client -> server messages
  621.      */
  622.     const DEBUG_CLIENT = 1;
  623.     /**
  624.      * Debug level to show client -> server and server -> client messages
  625.      */
  626.     const DEBUG_SERVER = 2;
  627.     /**
  628.      * Debug level to show connection status, client -> server and server -> client messages
  629.      */
  630.     const DEBUG_CONNECTION = 3;
  631.     /**
  632.      * Debug level to show all messages
  633.      */
  634.     const DEBUG_LOWLEVEL = 4;
  635.     /**
  636.      * The PHPMailer SMTP Version number.
  637.      * @var string
  638.      * @deprecated Use the `VERSION` constant instead
  639.      * @see SMTP::VERSION
  640.      */
  641.     public $Version = '5.2.17';
  642.     /**
  643.      * SMTP server port number.
  644.      * @var integer
  645.      * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead
  646.      * @see SMTP::DEFAULT_SMTP_PORT
  647.      */
  648.     public $SMTP_PORT = 25;
  649.     /**
  650.      * SMTP reply line ending.
  651.      * @var string
  652.      * @deprecated Use the `CRLF` constant instead
  653.      * @see SMTP::CRLF
  654.      */
  655.     public $CRLF = "\r\n";
  656.     /**
  657.      * Debug output level.
  658.      * Options:
  659.      * * self::DEBUG_OFF (`0`) No debug output, default
  660.      * * self::DEBUG_CLIENT (`1`) Client commands
  661.      * * self::DEBUG_SERVER (`2`) Client commands and server responses
  662.      * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status
  663.      * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages
  664.      * @var integer
  665.      */
  666.     public $do_debug = self::DEBUG_OFF;
  667.     /**
  668.      * How to handle debug output.
  669.      * Options:
  670.      * * `echo` Output plain-text as-is, appropriate for CLI
  671.      * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
  672.      * * `error_log` Output to error log as configured in php.ini
  673.      *
  674.      * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
  675.      * <code>
  676.      * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
  677.      * </code>
  678.      * @var string|callable
  679.      */
  680.     public $Debugoutput = 'echo';
  681.     /**
  682.      * Whether to use VERP.
  683.      * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
  684.      * @link http://www.postfix.org/VERP_README.html Info on VERP
  685.      * @var boolean
  686.      */
  687.     public $do_verp = false;
  688.     /**
  689.      * The timeout value for connection, in seconds.
  690.      * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
  691.      * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
  692.      * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2
  693.      * @var integer
  694.      */
  695.     public $Timeout = 300;
  696.     /**
  697.      * How long to wait for commands to complete, in seconds.
  698.      * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
  699.      * @var integer
  700.      */
  701.     public $Timelimit = 300;
  702.     /**
  703.      * @var array patterns to extract smtp transaction id from smtp reply
  704.      * Only first capture group will be use, use non-capturing group to deal with it
  705.      * Extend this class to override this property to fulfil your needs.
  706.      */
  707.     protected $smtp_transaction_id_patterns = array(
  708.         'exim' => '/[0-9]{3} OK id=(.*)/',
  709.         'sendmail' => '/[0-9]{3} 2.0.0 (.*) Message/',
  710.         'postfix' => '/[0-9]{3} 2.0.0 Ok: queued as (.*)/'
  711.     );
  712.     /**
  713.      * The socket for the server connection.
  714.      * @var resource
  715.      */
  716.     protected $smtp_conn;
  717.     /**
  718.      * Error information, if any, for the last SMTP command.
  719.      * @var array
  720.      */
  721.     protected $error = array(
  722.         'error' => '',
  723.         'detail' => '',
  724.         'smtp_code' => '',
  725.         'smtp_code_ex' => ''
  726.     );
  727.     /**
  728.      * The reply the server sent to us for HELO.
  729.      * If null, no HELO string has yet been received.
  730.      * @var string|null
  731.      */
  732.     protected $helo_rply = null;
  733.     /**
  734.      * The set of SMTP extensions sent in reply to EHLO command.
  735.      * Indexes of the array are extension names.
  736.      * Value at index 'HELO' or 'EHLO' (according to command that was sent)
  737.      * represents the server name. In case of HELO it is the only element of the array.
  738.      * Other values can be boolean TRUE or an array containing extension options.
  739.      * If null, no HELO/EHLO string has yet been received.
  740.      * @var array|null
  741.      */
  742.     protected $server_caps = null;
  743.     /**
  744.      * The most recent reply received from the server.
  745.      * @var string
  746.      */
  747.     protected $last_reply = '';
  748.     /**
  749.      * Output debugging info via a user-selected method.
  750.      * @see SMTP::$Debugoutput
  751.      * @see SMTP::$do_debug
  752.      * @param string $str Debug string to output
  753.      * @param integer $level The debug level of this message; see DEBUG_* constants
  754.      * @return void
  755.      */
  756.     protected function edebug($str, $level = 0)
  757.     {
  758.         if ($level > $this->do_debug) {
  759.             return;
  760.         }
  761.         //Avoid clash with built-in function names
  762.         if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  763.             call_user_func($this->Debugoutput, $str, $level);
  764.             return;
  765.         }
  766.         switch ($this->Debugoutput) {
  767.             case 'error_log':
  768.                 //Don't output, just log
  769.                 error_log($str);
  770.                 break;
  771.             case 'html':
  772.                 //Cleans up output a bit for a better looking, HTML-safe output
  773.                 echo htmlentities(
  774.                     preg_replace('/[\r\n]+/', '', $str),
  775.                     ENT_QUOTES,
  776.                     'UTF-8'
  777.                 )
  778.                 . "<br>\n";
  779.                 break;
  780.             case 'echo':
  781.             default:
  782.                 //Normalize line breaks
  783.                 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  784.                 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  785.                     "\n",
  786.                     "\n                   \t                  ",
  787.                     trim($str)
  788.                 )."\n";
  789.         }
  790.     }
  791.     /**
  792.      * Connect to an SMTP server.
  793.      * @param string $host SMTP server IP or host name
  794.      * @param integer $port The port number to connect to
  795.      * @param integer $timeout How long to wait for the connection to open
  796.      * @param array $options An array of options for stream_context_create()
  797.      * @access public
  798.      * @return boolean
  799.      */
  800.     public function connect($host, $port = null, $timeout = 30, $options = array())
  801.     {
  802.         if(count($options)==0)
  803.         {
  804.             $options["ssl"]=array("verify_peer"=>false,"verify_peer_name"=>false,"allow_self_signed"=>true);
  805.         }
  806.         static $streamok;
  807.         //This is enabled by default since 5.0.0 but some providers disable it
  808.         //Check this once and cache the result
  809.         if (is_null($streamok)) {
  810.             $streamok = function_exists('stream_socket_client');
  811.         }
  812.         // Clear errors to avoid confusion
  813.         $this->setError('');
  814.         // Make sure we are __not__ connected
  815.         if ($this->connected()) {
  816.             // Already connected, generate error
  817.             $this->setError('Already connected to a server');
  818.             return false;
  819.         }
  820.         if (empty($port)) {
  821.             $port = self::DEFAULT_SMTP_PORT;
  822.         }
  823.         // Connect to the SMTP server
  824.         $this->edebug(
  825.             "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
  826.             self::DEBUG_CONNECTION
  827.         );
  828.         $errno = 0;
  829.         $errstr = '';
  830.         if ($streamok) {
  831.             $socket_context = stream_context_create($options);
  832.             set_error_handler(array($this, 'errorHandler'));
  833.             $this->smtp_conn = stream_socket_client(
  834.                 $host . ":" . $port,
  835.                 $errno,
  836.                 $errstr,
  837.                 $timeout,
  838.                 STREAM_CLIENT_CONNECT,
  839.                 $socket_context
  840.             );
  841.             restore_error_handler();
  842.         } else {
  843.             //Fall back to fsockopen which should work in more places, but is missing some features
  844.             $this->edebug(
  845.                 "Connection: stream_socket_client not available, falling back to fsockopen",
  846.                 self::DEBUG_CONNECTION
  847.             );
  848.             set_error_handler(array($this, 'errorHandler'));
  849.             $this->smtp_conn = fsockopen(
  850.                 $host,
  851.                 $port,
  852.                 $errno,
  853.                 $errstr,
  854.                 $timeout
  855.             );
  856.             restore_error_handler();
  857.         }
  858.         // Verify we connected properly
  859.         if (!is_resource($this->smtp_conn)) {
  860.             $this->setError(
  861.                 'Failed to connect to server',
  862.                 $errno,
  863.                 $errstr
  864.             );
  865.             $this->edebug(
  866.                 'SMTP ERROR: ' . $this->error['error']
  867.                 . ": $errstr ($errno)",
  868.                 self::DEBUG_CLIENT
  869.             );
  870.             return false;
  871.         }
  872.         $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
  873.         // SMTP server can take longer to respond, give longer timeout for first read
  874.         // Windows does not have support for this timeout function
  875.         if (substr(PHP_OS, 0, 3) != 'WIN') {
  876.             $max = ini_get('max_execution_time');
  877.             // Don't bother if unlimited
  878.             if ($max != 0 && $timeout > $max) {
  879.                 @set_time_limit($timeout);
  880.             }
  881.             stream_set_timeout($this->smtp_conn, $timeout, 0);
  882.         }
  883.         // Get any announcement
  884.         $announce = $this->get_lines();
  885.         $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
  886.         return true;
  887.     }
  888.     /**
  889.      * Initiate a TLS (encrypted) session.
  890.      * @access public
  891.      * @return boolean
  892.      */
  893.     public function startTLS()
  894.     {
  895.         if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
  896.             return false;
  897.         }
  898.         //Allow the best TLS version(s) we can
  899.         $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
  900.         //PHP 5.6.7 dropped inclusion of TLS 1.1 and 1.2 in STREAM_CRYPTO_METHOD_TLS_CLIENT
  901.         //so add them back in manually if we can
  902.         if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
  903.             $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
  904.             $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
  905.         }
  906.         // Begin encrypted connection
  907.         if (!stream_socket_enable_crypto(
  908.             $this->smtp_conn,
  909.             true,
  910.             $crypto_method
  911.         )) {
  912.             return false;
  913.         }
  914.         return true;
  915.     }
  916.     /**
  917.      * Perform SMTP authentication.
  918.      * Must be run after hello().
  919.      * @see hello()
  920.      * @param string $username The user name
  921.      * @param string $password The password
  922.      * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
  923.      * @param string $realm The auth realm for NTLM
  924.      * @param string $workstation The auth workstation for NTLM
  925.      * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth)
  926.      * @return bool True if successfully authenticated.* @access public
  927.      */
  928.     public function authenticate(
  929.         $username,
  930.         $password,
  931.         $authtype = null,
  932.         $realm = '',
  933.         $workstation = '',
  934.         $OAuth = null
  935.     ) {
  936.         if (!$this->server_caps) {
  937.             $this->setError('Authentication is not allowed before HELO/EHLO');
  938.             return false;
  939.         }
  940.         if (array_key_exists('EHLO', $this->server_caps)) {
  941.         // SMTP extensions are available. Let's try to find a proper authentication method
  942.             if (!array_key_exists('AUTH', $this->server_caps)) {
  943.                 $this->setError('Authentication is not allowed at this stage');
  944.                 // 'at this stage' means that auth may be allowed after the stage changes
  945.                 // e.g. after STARTTLS
  946.                 return false;
  947.             }
  948.             self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
  949.             self::edebug(
  950.                 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
  951.                 self::DEBUG_LOWLEVEL
  952.             );
  953.             if (empty($authtype)) {
  954.                 foreach (array('CRAM-MD5', 'LOGIN', 'PLAIN', 'NTLM', 'XOAUTH2') as $method) {
  955.                     if (in_array($method, $this->server_caps['AUTH'])) {
  956.                         $authtype = $method;
  957.                         break;
  958.                     }
  959.                 }
  960.                 if (empty($authtype)) {
  961.                     $this->setError('No supported authentication methods found');
  962.                     return false;
  963.                 }
  964.                 self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
  965.             }
  966.             if (!in_array($authtype, $this->server_caps['AUTH'])) {
  967.                 $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
  968.                 return false;
  969.             }
  970.         } elseif (empty($authtype)) {
  971.             $authtype = 'LOGIN';
  972.         }
  973.         switch ($authtype) {
  974.             case 'PLAIN':
  975.                 // Start authentication
  976.                 if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
  977.                     return false;
  978.                 }
  979.                 // Send encoded username and password
  980.                 if (!$this->sendCommand(
  981.                     'User & Password',
  982.                     base64_encode("\0" . $username . "\0" . $password),
  983.                     235
  984.                 )
  985.                 ) {
  986.                     return false;
  987.                 }
  988.                 break;
  989.             case 'LOGIN':
  990.                 // Start authentication
  991.                 if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
  992.                     return false;
  993.                 }
  994.                 if (!$this->sendCommand("Username", base64_encode($username), 334)) {
  995.                     return false;
  996.                 }
  997.                 if (!$this->sendCommand("Password", base64_encode($password), 235)) {
  998.                     return false;
  999.                 }
  1000.                 break;
  1001.             case 'XOAUTH2':
  1002.                 //If the OAuth Instance is not set. Can be a case when PHPMailer is used
  1003.                 //instead of PHPMailerOAuth
  1004.                 if (is_null($OAuth)) {
  1005.                     return false;
  1006.                 }
  1007.                 $oauth = $OAuth->getOauth64();
  1008.                 // Start authentication
  1009.                 if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
  1010.                     return false;
  1011.                 }
  1012.                 break;
  1013.             case 'NTLM':
  1014.                 /*
  1015.                  * ntlm_sasl_client.php
  1016.                  * Bundled with Permission
  1017.                  *
  1018.                  * How to telnet in windows:
  1019.                  * http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
  1020.                  * PROTOCOL Docs http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
  1021.                  */
  1022.                 require_once 'extras/ntlm_sasl_client.php';
  1023.                 $temp = new stdClass;
  1024.                 $ntlm_client = new ntlm_sasl_client_class;
  1025.                 //Check that functions are available
  1026.                 if (!$ntlm_client->initialize($temp)) {
  1027.                     $this->setError($temp->error);
  1028.                     $this->edebug(
  1029.                         'You need to enable some modules in your php.ini file: '
  1030.                         . $this->error['error'],
  1031.                         self::DEBUG_CLIENT
  1032.                     );
  1033.                     return false;
  1034.                 }
  1035.                 //msg1
  1036.                 $msg1 = $ntlm_client->typeMsg1($realm, $workstation); //msg1
  1037.                 if (!$this->sendCommand(
  1038.                     'AUTH NTLM',
  1039.                     'AUTH NTLM ' . base64_encode($msg1),
  1040.                     334
  1041.                 )
  1042.                 ) {
  1043.                     return false;
  1044.                 }
  1045.                 //Though 0 based, there is a white space after the 3 digit number
  1046.                 //msg2
  1047.                 $challenge = substr($this->last_reply, 3);
  1048.                 $challenge = base64_decode($challenge);
  1049.                 $ntlm_res = $ntlm_client->NTLMResponse(
  1050.                     substr($challenge, 24, 8),
  1051.                     $password
  1052.                 );
  1053.                 //msg3
  1054.                 $msg3 = $ntlm_client->typeMsg3(
  1055.                     $ntlm_res,
  1056.                     $username,
  1057.                     $realm,
  1058.                     $workstation
  1059.                 );
  1060.                 // send encoded username
  1061.                 return $this->sendCommand('Username', base64_encode($msg3), 235);
  1062.             case 'CRAM-MD5':
  1063.                 // Start authentication
  1064.                 if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
  1065.                     return false;
  1066.                 }
  1067.                 // Get the challenge
  1068.                 $challenge = base64_decode(substr($this->last_reply, 4));
  1069.                 // Build the response
  1070.                 $response = $username . ' ' . $this->hmac($challenge, $password);
  1071.                 // send encoded credentials
  1072.                 return $this->sendCommand('Username', base64_encode($response), 235);
  1073.             default:
  1074.                 $this->setError("Authentication method \"$authtype\" is not supported");
  1075.                 return false;
  1076.         }
  1077.         return true;
  1078.     }
  1079.     /**
  1080.      * Calculate an MD5 HMAC hash.
  1081.      * Works like hash_hmac('md5', $data, $key)
  1082.      * in case that function is not available
  1083.      * @param string $data The data to hash
  1084.      * @param string $key  The key to hash with
  1085.      * @access protected
  1086.      * @return string
  1087.      */
  1088.     protected function hmac($data, $key)
  1089.     {
  1090.         if (function_exists('hash_hmac')) {
  1091.             return hash_hmac('md5', $data, $key);
  1092.         }
  1093.         // The following borrowed from
  1094.         // http://php.net/manual/en/function.mhash.php#27225
  1095.         // RFC 2104 HMAC implementation for php.
  1096.         // Creates an md5 HMAC.
  1097.         // Eliminates the need to install mhash to compute a HMAC
  1098.         // by Lance Rushing
  1099.         $bytelen = 64; // byte length for md5
  1100.         if (strlen($key) > $bytelen) {
  1101.             $key = pack('H*', md5($key));
  1102.         }
  1103.         $key = str_pad($key, $bytelen, chr(0x00));
  1104.         $ipad = str_pad('', $bytelen, chr(0x36));
  1105.         $opad = str_pad('', $bytelen, chr(0x5c));
  1106.         $k_ipad = $key ^ $ipad;
  1107.         $k_opad = $key ^ $opad;
  1108.         return md5($k_opad . pack('H*', md5($k_ipad . $data)));
  1109.     }
  1110.     /**
  1111.      * Check connection state.
  1112.      * @access public
  1113.      * @return boolean True if connected.
  1114.      */
  1115.     public function connected()
  1116.     {
  1117.         if (is_resource($this->smtp_conn)) {
  1118.             $sock_status = stream_get_meta_data($this->smtp_conn);
  1119.             if ($sock_status['eof']) {
  1120.                 // The socket is valid but we are not connected
  1121.                 $this->edebug(
  1122.                     'SMTP NOTICE: EOF caught while checking if connected',
  1123.                     self::DEBUG_CLIENT
  1124.                 );
  1125.                 $this->close();
  1126.                 return false;
  1127.             }
  1128.             return true; // everything looks good
  1129.         }
  1130.         return false;
  1131.     }
  1132.     /**
  1133.      * Close the socket and clean up the state of the class.
  1134.      * Don't use this function without first trying to use QUIT.
  1135.      * @see quit()
  1136.      * @access public
  1137.      * @return void
  1138.      */
  1139.     public function close()
  1140.     {
  1141.         $this->setError('');
  1142.         $this->server_caps = null;
  1143.         $this->helo_rply = null;
  1144.         if (is_resource($this->smtp_conn)) {
  1145.             // close the connection and cleanup
  1146.             fclose($this->smtp_conn);
  1147.             $this->smtp_conn = null; //Makes for cleaner serialization
  1148.             $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
  1149.         }
  1150.     }
  1151.     /**
  1152.      * Send an SMTP DATA command.
  1153.      * Issues a data command and sends the msg_data to the server,
  1154.      * finializing the mail transaction. $msg_data is the message
  1155.      * that is to be send with the headers. Each header needs to be
  1156.      * on a single line followed by a <CRLF> with the message headers
  1157.      * and the message body being separated by and additional <CRLF>.
  1158.      * Implements rfc 821: DATA <CRLF>
  1159.      * @param string $msg_data Message data to send
  1160.      * @access public
  1161.      * @return boolean
  1162.      */
  1163.     public function data($msg_data)
  1164.     {
  1165.         //This will use the standard timelimit
  1166.         if (!$this->sendCommand('DATA', 'DATA', 354)) {
  1167.             return false;
  1168.         }
  1169.         /* The server is ready to accept data!
  1170.          * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF)
  1171.          * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
  1172.          * smaller lines to fit within the limit.
  1173.          * We will also look for lines that start with a '.' and prepend an additional '.'.
  1174.          * NOTE: this does not count towards line-length limit.
  1175.          */
  1176.         // Normalize line breaks before exploding
  1177.         $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
  1178.         /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
  1179.          * of the first line (':' separated) does not contain a space then it _should_ be a header and we will
  1180.          * process all lines before a blank line as headers.
  1181.          */
  1182.         $field = substr($lines[0], 0, strpos($lines[0], ':'));
  1183.         $in_headers = false;
  1184.         if (!empty($field) && strpos($field, ' ') === false) {
  1185.             $in_headers = true;
  1186.         }
  1187.         foreach ($lines as $line) {
  1188.             $lines_out = array();
  1189.             if ($in_headers and $line == '') {
  1190.                 $in_headers = false;
  1191.             }
  1192.             //Break this line up into several smaller lines if it's too long
  1193.             //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len),
  1194.             while (isset($line[self::MAX_LINE_LENGTH])) {
  1195.                 //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
  1196.                 //so as to avoid breaking in the middle of a word
  1197.                 $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
  1198.                 //Deliberately matches both false and 0
  1199.                 if (!$pos) {
  1200.                     //No nice break found, add a hard break
  1201.                     $pos = self::MAX_LINE_LENGTH - 1;
  1202.                     $lines_out[] = substr($line, 0, $pos);
  1203.                     $line = substr($line, $pos);
  1204.                 } else {
  1205.                     //Break at the found point
  1206.                     $lines_out[] = substr($line, 0, $pos);
  1207.                     //Move along by the amount we dealt with
  1208.                     $line = substr($line, $pos + 1);
  1209.                 }
  1210.                 //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
  1211.                 if ($in_headers) {
  1212.                     $line = "\t" . $line;
  1213.                 }
  1214.             }
  1215.             $lines_out[] = $line;
  1216.             //Send the lines to the server
  1217.             foreach ($lines_out as $line_out) {
  1218.                 //RFC2821 section 4.5.2
  1219.                 if (!empty($line_out) and $line_out[0] == '.') {
  1220.                     $line_out = '.' . $line_out;
  1221.                 }
  1222.                 $this->client_send($line_out . self::CRLF);
  1223.             }
  1224.         }
  1225.         //Message data has been sent, complete the command
  1226.         //Increase timelimit for end of DATA command
  1227.         $savetimelimit = $this->Timelimit;
  1228.         $this->Timelimit = $this->Timelimit * 2;
  1229.         $result = $this->sendCommand('DATA END', '.', 250);
  1230.         //Restore timelimit
  1231.         $this->Timelimit = $savetimelimit;
  1232.         return $result;
  1233.     }
  1234.     /**
  1235.      * Send an SMTP HELO or EHLO command.
  1236.      * Used to identify the sending server to the receiving server.
  1237.      * This makes sure that client and server are in a known state.
  1238.      * Implements RFC 821: HELO <SP> <domain> <CRLF>
  1239.      * and RFC 2821 EHLO.
  1240.      * @param string $host The host name or IP to connect to
  1241.      * @access public
  1242.      * @return boolean
  1243.      */
  1244.     public function hello($host = '')
  1245.     {
  1246.         //Try extended hello first (RFC 2821)
  1247.         return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
  1248.     }
  1249.     /**
  1250.      * Send an SMTP HELO or EHLO command.
  1251.      * Low-level implementation used by hello()
  1252.      * @see hello()
  1253.      * @param string $hello The HELO string
  1254.      * @param string $host The hostname to say we are
  1255.      * @access protected
  1256.      * @return boolean
  1257.      */
  1258.     protected function sendHello($hello, $host)
  1259.     {
  1260.         $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
  1261.         $this->helo_rply = $this->last_reply;
  1262.         if ($noerror) {
  1263.             $this->parseHelloFields($hello);
  1264.         } else {
  1265.             $this->server_caps = null;
  1266.         }
  1267.         return $noerror;
  1268.     }
  1269.     /**
  1270.      * Parse a reply to HELO/EHLO command to discover server extensions.
  1271.      * In case of HELO, the only parameter that can be discovered is a server name.
  1272.      * @access protected
  1273.      * @param string $type - 'HELO' or 'EHLO'
  1274.      */
  1275.     protected function parseHelloFields($type)
  1276.     {
  1277.         $this->server_caps = array();
  1278.         $lines = explode("\n", $this->helo_rply);
  1279.         foreach ($lines as $n => $s) {
  1280.             //First 4 chars contain response code followed by - or space
  1281.             $s = trim(substr($s, 4));
  1282.             if (empty($s)) {
  1283.                 continue;
  1284.             }
  1285.             $fields = explode(' ', $s);
  1286.             if (!empty($fields)) {
  1287.                 if (!$n) {
  1288.                     $name = $type;
  1289.                     $fields = $fields[0];
  1290.                 } else {
  1291.                     $name = array_shift($fields);
  1292.                     switch ($name) {
  1293.                         case 'SIZE':
  1294.                             $fields = ($fields ? $fields[0] : 0);
  1295.                             break;
  1296.                         case 'AUTH':
  1297.                             if (!is_array($fields)) {
  1298.                                 $fields = array();
  1299.                             }
  1300.                             break;
  1301.                         default:
  1302.                             $fields = true;
  1303.                     }
  1304.                 }
  1305.                 $this->server_caps[$name] = $fields;
  1306.             }
  1307.         }
  1308.     }
  1309.     /**
  1310.      * Send an SMTP MAIL command.
  1311.      * Starts a mail transaction from the email address specified in
  1312.      * $from. Returns true if successful or false otherwise. If True
  1313.      * the mail transaction is started and then one or more recipient
  1314.      * commands may be called followed by a data command.
  1315.      * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
  1316.      * @param string $from Source address of this message
  1317.      * @access public
  1318.      * @return boolean
  1319.      */
  1320.     public function mail($from)
  1321.     {
  1322.         $useVerp = ($this->do_verp ? ' XVERP' : '');
  1323.         return $this->sendCommand(
  1324.             'MAIL FROM',
  1325.             'MAIL FROM:<' . $from . '>' . $useVerp,
  1326.             250
  1327.         );
  1328.     }
  1329.     /**
  1330.      * Send an SMTP QUIT command.
  1331.      * Closes the socket if there is no error or the $close_on_error argument is true.
  1332.      * Implements from rfc 821: QUIT <CRLF>
  1333.      * @param boolean $close_on_error Should the connection close if an error occurs?
  1334.      * @access public
  1335.      * @return boolean
  1336.      */
  1337.     public function quit($close_on_error = true)
  1338.     {
  1339.         $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
  1340.         $err = $this->error; //Save any error
  1341.         if ($noerror or $close_on_error) {
  1342.             $this->close();
  1343.             $this->error = $err; //Restore any error from the quit command
  1344.         }
  1345.         return $noerror;
  1346.     }
  1347.     /**
  1348.      * Send an SMTP RCPT command.
  1349.      * Sets the TO argument to $toaddr.
  1350.      * Returns true if the recipient was accepted false if it was rejected.
  1351.      * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
  1352.      * @param string $address The address the message is being sent to
  1353.      * @access public
  1354.      * @return boolean
  1355.      */
  1356.     public function recipient($address)
  1357.     {
  1358.         return $this->sendCommand(
  1359.             'RCPT TO',
  1360.             'RCPT TO:<' . $address . '>',
  1361.             array(250, 251)
  1362.         );
  1363.     }
  1364.     /**
  1365.      * Send an SMTP RSET command.
  1366.      * Abort any transaction that is currently in progress.
  1367.      * Implements rfc 821: RSET <CRLF>
  1368.      * @access public
  1369.      * @return boolean True on success.
  1370.      */
  1371.     public function reset()
  1372.     {
  1373.         return $this->sendCommand('RSET', 'RSET', 250);
  1374.     }
  1375.     /**
  1376.      * Send a command to an SMTP server and check its return code.
  1377.      * @param string $command The command name - not sent to the server
  1378.      * @param string $commandstring The actual command to send
  1379.      * @param integer|array $expect One or more expected integer success codes
  1380.      * @access protected
  1381.      * @return boolean True on success.
  1382.      */
  1383.     protected function sendCommand($command, $commandstring, $expect)
  1384.     {
  1385.         if (!$this->connected()) {
  1386.             $this->setError("Called $command without being connected");
  1387.             return false;
  1388.         }
  1389.         //Reject line breaks in all commands
  1390.         if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) {
  1391.             $this->setError("Command '$command' contained line breaks");
  1392.             return false;
  1393.         }
  1394.         $this->client_send($commandstring . self::CRLF);
  1395.         $this->last_reply = $this->get_lines();
  1396.         // Fetch SMTP code and possible error code explanation
  1397.         $matches = array();
  1398.         if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
  1399.             $code = $matches[1];
  1400.             $code_ex = (count($matches) > 2 ? $matches[2] : null);
  1401.             // Cut off error code from each response line
  1402.             $detail = preg_replace(
  1403.                 "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
  1404.                 '',
  1405.                 $this->last_reply
  1406.             );
  1407.         } else {
  1408.             // Fall back to simple parsing if regex fails
  1409.             $code = substr($this->last_reply, 0, 3);
  1410.             $code_ex = null;
  1411.             $detail = substr($this->last_reply, 4);
  1412.         }
  1413.         $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
  1414.         if (!in_array($code, (array)$expect)) {
  1415.             $this->setError(
  1416.                 "$command command failed",
  1417.                 $detail,
  1418.                 $code,
  1419.                 $code_ex
  1420.             );
  1421.             $this->edebug(
  1422.                 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
  1423.                 self::DEBUG_CLIENT
  1424.             );
  1425.             return false;
  1426.         }
  1427.         $this->setError('');
  1428.         return true;
  1429.     }
  1430.     /**
  1431.      * Send an SMTP SAML command.
  1432.      * Starts a mail transaction from the email address specified in $from.
  1433.      * Returns true if successful or false otherwise. If True
  1434.      * the mail transaction is started and then one or more recipient
  1435.      * commands may be called followed by a data command. This command
  1436.      * will send the message to the users terminal if they are logged
  1437.      * in and send them an email.
  1438.      * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
  1439.      * @param string $from The address the message is from
  1440.      * @access public
  1441.      * @return boolean
  1442.      */
  1443.     public function sendAndMail($from)
  1444.     {
  1445.         return $this->sendCommand('SAML', "SAML FROM:$from", 250);
  1446.     }
  1447.     /**
  1448.      * Send an SMTP VRFY command.
  1449.      * @param string $name The name to verify
  1450.      * @access public
  1451.      * @return boolean
  1452.      */
  1453.     public function verify($name)
  1454.     {
  1455.         return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
  1456.     }
  1457.     /**
  1458.      * Send an SMTP NOOP command.
  1459.      * Used to keep keep-alives alive, doesn't actually do anything
  1460.      * @access public
  1461.      * @return boolean
  1462.      */
  1463.     public function noop()
  1464.     {
  1465.         return $this->sendCommand('NOOP', 'NOOP', 250);
  1466.     }
  1467.     /**
  1468.      * Send an SMTP TURN command.
  1469.      * This is an optional command for SMTP that this class does not support.
  1470.      * This method is here to make the RFC821 Definition complete for this class
  1471.      * and _may_ be implemented in future
  1472.      * Implements from rfc 821: TURN <CRLF>
  1473.      * @access public
  1474.      * @return boolean
  1475.      */
  1476.     public function turn()
  1477.     {
  1478.         $this->setError('The SMTP TURN command is not implemented');
  1479.         $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
  1480.         return false;
  1481.     }
  1482.     /**
  1483.      * Send raw data to the server.
  1484.      * @param string $data The data to send
  1485.      * @access public
  1486.      * @return integer|boolean The number of bytes sent to the server or false on error
  1487.      */
  1488.     public function client_send($data)
  1489.     {
  1490.         $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
  1491.         set_error_handler(array($this, 'errorHandler'));
  1492.         $result = fwrite($this->smtp_conn, $data);
  1493.         restore_error_handler();
  1494.         return $result;
  1495.     }
  1496.     /**
  1497.      * Get the latest error.
  1498.      * @access public
  1499.      * @return array
  1500.      */
  1501.     public function getError()
  1502.     {
  1503.         return $this->error;
  1504.     }
  1505.     /**
  1506.      * Get SMTP extensions available on the server
  1507.      * @access public
  1508.      * @return array|null
  1509.      */
  1510.     public function getServerExtList()
  1511.     {
  1512.         return $this->server_caps;
  1513.     }
  1514.     /**
  1515.      * A multipurpose method
  1516.      * The method works in three ways, dependent on argument value and current state
  1517.      *   1. HELO/EHLO was not sent - returns null and set up $this->error
  1518.      *   2. HELO was sent
  1519.      *     $name = 'HELO': returns server name
  1520.      *     $name = 'EHLO': returns boolean false
  1521.      *     $name = any string: returns null and set up $this->error
  1522.      *   3. EHLO was sent
  1523.      *     $name = 'HELO'|'EHLO': returns server name
  1524.      *     $name = any string: if extension $name exists, returns boolean True
  1525.      *       or its options. Otherwise returns boolean False
  1526.      * In other words, one can use this method to detect 3 conditions:
  1527.      *  - null returned: handshake was not or we don't know about ext (refer to $this->error)
  1528.      *  - false returned: the requested feature exactly not exists
  1529.      *  - positive value returned: the requested feature exists
  1530.      * @param string $name Name of SMTP extension or 'HELO'|'EHLO'
  1531.      * @return mixed
  1532.      */
  1533.     public function getServerExt($name)
  1534.     {
  1535.         if (!$this->server_caps) {
  1536.             $this->setError('No HELO/EHLO was sent');
  1537.             return null;
  1538.         }
  1539.         // the tight logic knot ;)
  1540.         if (!array_key_exists($name, $this->server_caps)) {
  1541.             if ($name == 'HELO') {
  1542.                 return $this->server_caps['EHLO'];
  1543.             }
  1544.             if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
  1545.                 return false;
  1546.             }
  1547.             $this->setError('HELO handshake was used. Client knows nothing about server extensions');
  1548.             return null;
  1549.         }
  1550.         return $this->server_caps[$name];
  1551.     }
  1552.     /**
  1553.      * Get the last reply from the server.
  1554.      * @access public
  1555.      * @return string
  1556.      */
  1557.     public function getLastReply()
  1558.     {
  1559.         return $this->last_reply;
  1560.     }
  1561.     /**
  1562.      * Read the SMTP server's response.
  1563.      * Either before eof or socket timeout occurs on the operation.
  1564.      * With SMTP we can tell if we have more lines to read if the
  1565.      * 4th character is '-' symbol. If it is a space then we don't
  1566.      * need to read anything else.
  1567.      * @access protected
  1568.      * @return string
  1569.      */
  1570.     protected function get_lines()
  1571.     {
  1572.         // If the connection is bad, give up straight away
  1573.         if (!is_resource($this->smtp_conn)) {
  1574.             return '';
  1575.         }
  1576.         $data = '';
  1577.         $endtime = 0;
  1578.         stream_set_timeout($this->smtp_conn, $this->Timeout);
  1579.         if ($this->Timelimit > 0) {
  1580.             $endtime = time() + $this->Timelimit;
  1581.         }
  1582.         while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
  1583.             $str = @fgets($this->smtp_conn, 515);
  1584.             $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
  1585.             $this->edebug("SMTP -> get_lines(): \$str is  \"$str\"", self::DEBUG_LOWLEVEL);
  1586.             $data .= $str;
  1587.             // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen
  1588.             if (!isset($str[3]) or (isset($str[3]) and $str[3] == ' ')) {
  1589.                  break;
  1590.              }
  1591.             // Timed-out? Log and break
  1592.             $info = stream_get_meta_data($this->smtp_conn);
  1593.             if ($info['timed_out']) {
  1594.                 $this->edebug(
  1595.                     'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
  1596.                     self::DEBUG_LOWLEVEL
  1597.                 );
  1598.                 break;
  1599.             }
  1600.             // Now check if reads took too long
  1601.             if ($endtime and time() > $endtime) {
  1602.                 $this->edebug(
  1603.                     'SMTP -> get_lines(): timelimit reached ('.
  1604.                     $this->Timelimit . ' sec)',
  1605.                     self::DEBUG_LOWLEVEL
  1606.                 );
  1607.                 break;
  1608.             }
  1609.         }
  1610.         return $data;
  1611.     }
  1612.     /**
  1613.      * Enable or disable VERP address generation.
  1614.      * @param boolean $enabled
  1615.      */
  1616.     public function setVerp($enabled = false)
  1617.     {
  1618.         $this->do_verp = $enabled;
  1619.     }
  1620.     /**
  1621.      * Get VERP address generation mode.
  1622.      * @return boolean
  1623.      */
  1624.     public function getVerp()
  1625.     {
  1626.         return $this->do_verp;
  1627.     }
  1628.     /**
  1629.      * Set error messages and codes.
  1630.      * @param string $message The error message
  1631.      * @param string $detail Further detail on the error
  1632.      * @param string $smtp_code An associated SMTP error code
  1633.      * @param string $smtp_code_ex Extended SMTP code
  1634.      */
  1635.     protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
  1636.     {
  1637.         $this->error = array(
  1638.             'error' => $message,
  1639.             'detail' => $detail,
  1640.             'smtp_code' => $smtp_code,
  1641.             'smtp_code_ex' => $smtp_code_ex
  1642.         );
  1643.     }
  1644.     /**
  1645.      * Set debug output method.
  1646.      * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it.
  1647.      */
  1648.     public function setDebugOutput($method = 'echo')
  1649.     {
  1650.         $this->Debugoutput = $method;
  1651.     }
  1652.     /**
  1653.      * Get debug output method.
  1654.      * @return string
  1655.      */
  1656.     public function getDebugOutput()
  1657.     {
  1658.         return $this->Debugoutput;
  1659.     }
  1660.     /**
  1661.      * Set debug output level.
  1662.      * @param integer $level
  1663.      */
  1664.     public function setDebugLevel($level = 0)
  1665.     {
  1666.         $this->do_debug = $level;
  1667.     }
  1668.     /**
  1669.      * Get debug output level.
  1670.      * @return integer
  1671.      */
  1672.     public function getDebugLevel()
  1673.     {
  1674.         return $this->do_debug;
  1675.     }
  1676.     /**
  1677.      * Set SMTP timeout.
  1678.      * @param integer $timeout
  1679.      */
  1680.     public function setTimeout($timeout = 0)
  1681.     {
  1682.         $this->Timeout = $timeout;
  1683.     }
  1684.     /**
  1685.      * Get SMTP timeout.
  1686.      * @return integer
  1687.      */
  1688.     public function getTimeout()
  1689.     {
  1690.         return $this->Timeout;
  1691.     }
  1692.     /**
  1693.      * Reports an error number and string.
  1694.      * @param integer $errno The error number returned by PHP.
  1695.      * @param string $errmsg The error message returned by PHP.
  1696.      */
  1697.     protected function errorHandler($errno, $errmsg)
  1698.     {
  1699.         $notice = 'Connection: Failed to connect to server.';
  1700.         $this->setError(
  1701.             $notice,
  1702.             $errno,
  1703.             $errmsg
  1704.         );
  1705.         $this->edebug(
  1706.             $notice . ' Error number ' . $errno . '. "Error notice: ' . $errmsg,
  1707.             self::DEBUG_CONNECTION
  1708.         );
  1709.     }
  1710.     /**
  1711.      * Will return the ID of the last smtp transaction based on a list of patterns provided
  1712.      * in SMTP::$smtp_transaction_id_patterns.
  1713.      * If no reply has been received yet, it will return null.
  1714.      * If no pattern has been matched, it will return false.
  1715.      * @return bool|null|string
  1716.      */
  1717.     public function getLastTransactionID()
  1718.     {
  1719.         $reply = $this->getLastReply();
  1720.         if (empty($reply)) {
  1721.             return null;
  1722.         }
  1723.         foreach($this->smtp_transaction_id_patterns as $smtp_transaction_id_pattern) {
  1724.             if(preg_match($smtp_transaction_id_pattern, $reply, $matches)) {
  1725.                 return $matches[1];
  1726.             }
  1727.         }
  1728.         return false;
  1729.     }
  1730. }
  1731. class PHPMailer
  1732. {
  1733.     /**
  1734.      * The PHPMailer Version number.
  1735.      * @var string
  1736.      */
  1737.     public $Version = '5.2.17';
  1738.     /**
  1739.      * Email priority.
  1740.      * Options: null (default), 1 = High, 3 = Normal, 5 = low.
  1741.      * When null, the header is not set at all.
  1742.      * @var integer
  1743.      */
  1744.     public $Priority = null;
  1745.     /**
  1746.      * The character set of the message.
  1747.      * @var string
  1748.      */
  1749.     public $CharSet = 'iso-8859-1';
  1750.     /**
  1751.      * The MIME Content-type of the message.
  1752.      * @var string
  1753.      */
  1754.     public $ContentType = 'text/plain';
  1755.     /**
  1756.      * The message encoding.
  1757.      * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
  1758.      * @var string
  1759.      */
  1760.     public $Encoding = '8bit';
  1761.     /**
  1762.      * Holds the most recent mailer error message.
  1763.      * @var string
  1764.      */
  1765.     public $ErrorInfo = '';
  1766.     /**
  1767.      * The From email address for the message.
  1768.      * @var string
  1769.      */
  1770.     public $From = 'root@localhost';
  1771.     /**
  1772.      * The From name of the message.
  1773.      * @var string
  1774.      */
  1775.     public $FromName = 'Root User';
  1776.     /**
  1777.      * The Sender email (Return-Path) of the message.
  1778.      * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  1779.      * @var string
  1780.      */
  1781.     public $Sender = '';
  1782.     /**
  1783.      * The Return-Path of the message.
  1784.      * If empty, it will be set to either From or Sender.
  1785.      * @var string
  1786.      * @deprecated Email senders should never set a return-path header;
  1787.      * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
  1788.      * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
  1789.      */
  1790.     public $ReturnPath = '';
  1791.     /**
  1792.      * The Subject of the message.
  1793.      * @var string
  1794.      */
  1795.     public $Subject = '';
  1796.     /**
  1797.      * An HTML or plain text message body.
  1798.      * If HTML then call isHTML(true).
  1799.      * @var string
  1800.      */
  1801.     public $Body = '';
  1802.     /**
  1803.      * The plain-text message body.
  1804.      * This body can be read by mail clients that do not have HTML email
  1805.      * capability such as mutt & Eudora.
  1806.      * Clients that can read HTML will view the normal Body.
  1807.      * @var string
  1808.      */
  1809.     public $AltBody = '';
  1810.     /**
  1811.      * An iCal message part body.
  1812.      * Only supported in simple alt or alt_inline message types
  1813.      * To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
  1814.      * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
  1815.      * @link http://kigkonsult.se/iCalcreator/
  1816.      * @var string
  1817.      */
  1818.     public $Ical = '';
  1819.     /**
  1820.      * The complete compiled MIME message body.
  1821.      * @access protected
  1822.      * @var string
  1823.      */
  1824.     protected $MIMEBody = '';
  1825.     /**
  1826.      * The complete compiled MIME message headers.
  1827.      * @var string
  1828.      * @access protected
  1829.      */
  1830.     protected $MIMEHeader = '';
  1831.     /**
  1832.      * Extra headers that createHeader() doesn't fold in.
  1833.      * @var string
  1834.      * @access protected
  1835.      */
  1836.     protected $mailHeader = '';
  1837.     /**
  1838.      * Word-wrap the message body to this number of chars.
  1839.      * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
  1840.      * @var integer
  1841.      */
  1842.     public $WordWrap = 0;
  1843.     /**
  1844.      * Which method to use to send mail.
  1845.      * Options: "mail", "sendmail", or "smtp".
  1846.      * @var string
  1847.      */
  1848.     public $Mailer = 'mail';
  1849.     /**
  1850.      * The path to the sendmail program.
  1851.      * @var string
  1852.      */
  1853.     public $Sendmail = '/usr/sbin/sendmail';
  1854.     /**
  1855.      * Whether mail() uses a fully sendmail-compatible MTA.
  1856.      * One which supports sendmail's "-oi -f" options.
  1857.      * @var boolean
  1858.      */
  1859.     public $UseSendmailOptions = true;
  1860.     /**
  1861.      * Path to PHPMailer plugins.
  1862.      * Useful if the SMTP class is not in the PHP include path.
  1863.      * @var string
  1864.      * @deprecated Should not be needed now there is an autoloader.
  1865.      */
  1866.     public $PluginDir = '';
  1867.     /**
  1868.      * The email address that a reading confirmation should be sent to, also known as read receipt.
  1869.      * @var string
  1870.      */
  1871.     public $ConfirmReadingTo = '';
  1872.     /**
  1873.      * The hostname to use in the Message-ID header and as default HELO string.
  1874.      * If empty, PHPMailer attempts to find one with, in order,
  1875.      * $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value
  1876.      * 'localhost.localdomain'.
  1877.      * @var string
  1878.      */
  1879.     public $Hostname = '';
  1880.     /**
  1881.      * An ID to be used in the Message-ID header.
  1882.      * If empty, a unique id will be generated.
  1883.      * You can set your own, but it must be in the format "<id@domain>",
  1884.      * as defined in RFC5322 section 3.6.4 or it will be ignored.
  1885.      * @see https://tools.ietf.org/html/rfc5322#section-3.6.4
  1886.      * @var string
  1887.      */
  1888.     public $MessageID = '';
  1889.     /**
  1890.      * The message Date to be used in the Date header.
  1891.      * If empty, the current date will be added.
  1892.      * @var string
  1893.      */
  1894.     public $MessageDate = '';
  1895.     /**
  1896.      * SMTP hosts.
  1897.      * Either a single hostname or multiple semicolon-delimited hostnames.
  1898.      * You can also specify a different port
  1899.      * for each host by using this format: [hostname:port]
  1900.      * (e.g. "smtp1.example.com:25;smtp2.example.com").
  1901.      * You can also specify encryption type, for example:
  1902.      * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
  1903.      * Hosts will be tried in order.
  1904.      * @var string
  1905.      */
  1906.     public $Host = 'localhost';
  1907.     /**
  1908.      * The default SMTP server port.
  1909.      * @var integer
  1910.      * @TODO Why is this needed when the SMTP class takes care of it?
  1911.      */
  1912.     public $Port = 25;
  1913.     /**
  1914.      * The SMTP HELO of the message.
  1915.      * Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find
  1916.      * one with the same method described above for $Hostname.
  1917.      * @var string
  1918.      * @see PHPMailer::$Hostname
  1919.      */
  1920.     public $Helo = '';
  1921.     /**
  1922.      * What kind of encryption to use on the SMTP connection.
  1923.      * Options: '', 'ssl' or 'tls'
  1924.      * @var string
  1925.      */
  1926.     public $SMTPSecure = '';
  1927.     /**
  1928.      * Whether to enable TLS encryption automatically if a server supports it,
  1929.      * even if `SMTPSecure` is not set to 'tls'.
  1930.      * Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
  1931.      * @var boolean
  1932.      */
  1933.     public $SMTPAutoTLS = true;
  1934.     /**
  1935.      * Whether to use SMTP authentication.
  1936.      * Uses the Username and Password properties.
  1937.      * @var boolean
  1938.      * @see PHPMailer::$Username
  1939.      * @see PHPMailer::$Password
  1940.      */
  1941.     public $SMTPAuth = false;
  1942.     /**
  1943.      * Options array passed to stream_context_create when connecting via SMTP.
  1944.      * @var array
  1945.      */
  1946.     public $SMTPOptions = array();
  1947.     /**
  1948.      * SMTP username.
  1949.      * @var string
  1950.      */
  1951.     public $Username = '';
  1952.     /**
  1953.      * SMTP password.
  1954.      * @var string
  1955.      */
  1956.     public $Password = '';
  1957.     /**
  1958.      * SMTP auth type.
  1959.      * Options are CRAM-MD5, LOGIN, PLAIN, NTLM, XOAUTH2, attempted in that order if not specified
  1960.      * @var string
  1961.      */
  1962.     public $AuthType = '';
  1963.     /**
  1964.      * SMTP realm.
  1965.      * Used for NTLM auth
  1966.      * @var string
  1967.      */
  1968.     public $Realm = '';
  1969.     /**
  1970.      * SMTP workstation.
  1971.      * Used for NTLM auth
  1972.      * @var string
  1973.      */
  1974.     public $Workstation = '';
  1975.     /**
  1976.      * The SMTP server timeout in seconds.
  1977.      * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
  1978.      * @var integer
  1979.      */
  1980.     public $Timeout = 300;
  1981.     /**
  1982.      * SMTP class debug output mode.
  1983.      * Debug output level.
  1984.      * Options:
  1985.      * * `0` No output
  1986.      * * `1` Commands
  1987.      * * `2` Data and commands
  1988.      * * `3` As 2 plus connection status
  1989.      * * `4` Low-level data output
  1990.      * @var integer
  1991.      * @see SMTP::$do_debug
  1992.      */
  1993.     public $SMTPDebug = 0;
  1994.     /**
  1995.      * How to handle debug output.
  1996.      * Options:
  1997.      * * `echo` Output plain-text as-is, appropriate for CLI
  1998.      * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
  1999.      * * `error_log` Output to error log as configured in php.ini
  2000.      *
  2001.      * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
  2002.      * <code>
  2003.      * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
  2004.      * </code>
  2005.      * @var string|callable
  2006.      * @see SMTP::$Debugoutput
  2007.      */
  2008.     public $Debugoutput = 'echo';
  2009.     /**
  2010.      * Whether to keep SMTP connection open after each message.
  2011.      * If this is set to true then to close the connection
  2012.      * requires an explicit call to smtpClose().
  2013.      * @var boolean
  2014.      */
  2015.     public $SMTPKeepAlive = false;
  2016.     /**
  2017.      * Whether to split multiple to addresses into multiple messages
  2018.      * or send them all in one message.
  2019.      * Only supported in `mail` and `sendmail` transports, not in SMTP.
  2020.      * @var boolean
  2021.      */
  2022.     public $SingleTo = false;
  2023.     /**
  2024.      * Storage for addresses when SingleTo is enabled.
  2025.      * @var array
  2026.      * @TODO This should really not be public
  2027.      */
  2028.     public $SingleToArray = array();
  2029.     /**
  2030.      * Whether to generate VERP addresses on send.
  2031.      * Only applicable when sending via SMTP.
  2032.      * @link https://en.wikipedia.org/wiki/Variable_envelope_return_path
  2033.      * @link http://www.postfix.org/VERP_README.html Postfix VERP info
  2034.      * @var boolean
  2035.      */
  2036.     public $do_verp = false;
  2037.     /**
  2038.      * Whether to allow sending messages with an empty body.
  2039.      * @var boolean
  2040.      */
  2041.     public $AllowEmpty = false;
  2042.     /**
  2043.      * The default line ending.
  2044.      * @note The default remains "\n". We force CRLF where we know
  2045.      *        it must be used via self::CRLF.
  2046.      * @var string
  2047.      */
  2048.     public $LE = "\n";
  2049.     /**
  2050.      * DKIM selector.
  2051.      * @var string
  2052.      */
  2053.     public $DKIM_selector = '';
  2054.     /**
  2055.      * DKIM Identity.
  2056.      * Usually the email address used as the source of the email.
  2057.      * @var string
  2058.      */
  2059.     public $DKIM_identity = '';
  2060.     /**
  2061.      * DKIM passphrase.
  2062.      * Used if your key is encrypted.
  2063.      * @var string
  2064.      */
  2065.     public $DKIM_passphrase = '';
  2066.     /**
  2067.      * DKIM signing domain name.
  2068.      * @example 'example.com'
  2069.      * @var string
  2070.      */
  2071.     public $DKIM_domain = '';
  2072.     /**
  2073.      * DKIM private key file path.
  2074.      * @var string
  2075.      */
  2076.     public $DKIM_private = '';
  2077.     /**
  2078.      * DKIM private key string.
  2079.      * If set, takes precedence over `$DKIM_private`.
  2080.      * @var string
  2081.      */
  2082.     public $DKIM_private_string = '';
  2083.     /**
  2084.      * Callback Action function name.
  2085.      *
  2086.      * The function that handles the result of the send email action.
  2087.      * It is called out by send() for each email sent.
  2088.      *
  2089.      * Value can be any php callable: http://www.php.net/is_callable
  2090.      *
  2091.      * Parameters:
  2092.      *   boolean $result        result of the send action
  2093.      *   string  $to            email address of the recipient
  2094.      *   string  $cc            cc email addresses
  2095.      *   string  $bcc           bcc email addresses
  2096.      *   string  $subject       the subject
  2097.      *   string  $body          the email body
  2098.      *   string  $from          email address of sender
  2099.      * @var string
  2100.      */
  2101.     public $action_function = '';
  2102.     /**
  2103.      * What to put in the X-Mailer header.
  2104.      * Options: An empty string for PHPMailer default, whitespace for none, or a string to use
  2105.      * @var string
  2106.      */
  2107.     public $XMailer = '';
  2108.     /**
  2109.      * Which validator to use by default when validating email addresses.
  2110.      * May be a callable to inject your own validator, but there are several built-in validators.
  2111.      * @see PHPMailer::validateAddress()
  2112.      * @var string|callable
  2113.      * @static
  2114.      */
  2115.     public static $validator = 'auto';
  2116.     /**
  2117.      * An instance of the SMTP sender class.
  2118.      * @var SMTP
  2119.      * @access protected
  2120.      */
  2121.     protected $smtp = null;
  2122.     /**
  2123.      * The array of 'to' names and addresses.
  2124.      * @var array
  2125.      * @access protected
  2126.      */
  2127.     protected $to = array();
  2128.     /**
  2129.      * The array of 'cc' names and addresses.
  2130.      * @var array
  2131.      * @access protected
  2132.      */
  2133.     protected $cc = array();
  2134.     /**
  2135.      * The array of 'bcc' names and addresses.
  2136.      * @var array
  2137.      * @access protected
  2138.      */
  2139.     protected $bcc = array();
  2140.     /**
  2141.      * The array of reply-to names and addresses.
  2142.      * @var array
  2143.      * @access protected
  2144.      */
  2145.     protected $ReplyTo = array();
  2146.     /**
  2147.      * An array of all kinds of addresses.
  2148.      * Includes all of $to, $cc, $bcc
  2149.      * @var array
  2150.      * @access protected
  2151.      * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  2152.      */
  2153.     protected $all_recipients = array();
  2154.     /**
  2155.      * An array of names and addresses queued for validation.
  2156.      * In send(), valid and non duplicate entries are moved to $all_recipients
  2157.      * and one of $to, $cc, or $bcc.
  2158.      * This array is used only for addresses with IDN.
  2159.      * @var array
  2160.      * @access protected
  2161.      * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  2162.      * @see PHPMailer::$all_recipients
  2163.      */
  2164.     protected $RecipientsQueue = array();
  2165.     /**
  2166.      * An array of reply-to names and addresses queued for validation.
  2167.      * In send(), valid and non duplicate entries are moved to $ReplyTo.
  2168.      * This array is used only for addresses with IDN.
  2169.      * @var array
  2170.      * @access protected
  2171.      * @see PHPMailer::$ReplyTo
  2172.      */
  2173.     protected $ReplyToQueue = array();
  2174.     /**
  2175.      * The array of attachments.
  2176.      * @var array
  2177.      * @access protected
  2178.      */
  2179.     protected $attachment = array();
  2180.     /**
  2181.      * The array of custom headers.
  2182.      * @var array
  2183.      * @access protected
  2184.      */
  2185.     protected $CustomHeader = array();
  2186.     /**
  2187.      * The most recent Message-ID (including angular brackets).
  2188.      * @var string
  2189.      * @access protected
  2190.      */
  2191.     protected $lastMessageID = '';
  2192.     /**
  2193.      * The message's MIME type.
  2194.      * @var string
  2195.      * @access protected
  2196.      */
  2197.     protected $message_type = '';
  2198.     /**
  2199.      * The array of MIME boundary strings.
  2200.      * @var array
  2201.      * @access protected
  2202.      */
  2203.     protected $boundary = array();
  2204.     /**
  2205.      * The array of available languages.
  2206.      * @var array
  2207.      * @access protected
  2208.      */
  2209.     protected $language = array();
  2210.     /**
  2211.      * The number of errors encountered.
  2212.      * @var integer
  2213.      * @access protected
  2214.      */
  2215.     protected $error_count = 0;
  2216.     /**
  2217.      * The S/MIME certificate file path.
  2218.      * @var string
  2219.      * @access protected
  2220.      */
  2221.     protected $sign_cert_file = '';
  2222.     /**
  2223.      * The S/MIME key file path.
  2224.      * @var string
  2225.      * @access protected
  2226.      */
  2227.     protected $sign_key_file = '';
  2228.     /**
  2229.      * The optional S/MIME extra certificates ("CA Chain") file path.
  2230.      * @var string
  2231.      * @access protected
  2232.      */
  2233.     protected $sign_extracerts_file = '';
  2234.     /**
  2235.      * The S/MIME password for the key.
  2236.      * Used only if the key is encrypted.
  2237.      * @var string
  2238.      * @access protected
  2239.      */
  2240.     protected $sign_key_pass = '';
  2241.     /**
  2242.      * Whether to throw exceptions for errors.
  2243.      * @var boolean
  2244.      * @access protected
  2245.      */
  2246.     protected $exceptions = false;
  2247.     /**
  2248.      * Unique ID used for message ID and boundaries.
  2249.      * @var string
  2250.      * @access protected
  2251.      */
  2252.     protected $uniqueid = '';
  2253.     /**
  2254.      * Error severity: message only, continue processing.
  2255.      */
  2256.     const STOP_MESSAGE = 0;
  2257.     /**
  2258.      * Error severity: message, likely ok to continue processing.
  2259.      */
  2260.     const STOP_CONTINUE = 1;
  2261.     /**
  2262.      * Error severity: message, plus full stop, critical error reached.
  2263.      */
  2264.     const STOP_CRITICAL = 2;
  2265.     /**
  2266.      * SMTP RFC standard line ending.
  2267.      */
  2268.     const CRLF = "\r\n";
  2269.     /**
  2270.      * The maximum line length allowed by RFC 2822 section 2.1.1
  2271.      * @var integer
  2272.      */
  2273.     const MAX_LINE_LENGTH = 998;
  2274.     /**
  2275.      * Constructor.
  2276.      * @param boolean $exceptions Should we throw external exceptions?
  2277.      */
  2278.     public function __construct($exceptions = null)
  2279.     {
  2280.         if ($exceptions !== null) {
  2281.             $this->exceptions = (boolean)$exceptions;
  2282.         }
  2283.     }
  2284.     /**
  2285.      * Destructor.
  2286.      */
  2287.     public function __destruct()
  2288.     {
  2289.         //Close any open SMTP connection nicely
  2290.         $this->smtpClose();
  2291.     }
  2292.     /**
  2293.      * Call mail() in a safe_mode-aware fashion.
  2294.      * Also, unless sendmail_path points to sendmail (or something that
  2295.      * claims to be sendmail), don't pass params (not a perfect fix,
  2296.      * but it will do)
  2297.      * @param string $to To
  2298.      * @param string $subject Subject
  2299.      * @param string $body Message Body
  2300.      * @param string $header Additional Header(s)
  2301.      * @param string $params Params
  2302.      * @access private
  2303.      * @return boolean
  2304.      */
  2305.     private function mailPassthru($to, $subject, $body, $header, $params)
  2306.     {
  2307.         //Check overloading of mail function to avoid double-encoding
  2308.         if (ini_get('mbstring.func_overload') & 1) {
  2309.             $subject = $this->secureHeader($subject);
  2310.         } else {
  2311.             $subject = $this->encodeHeader($this->secureHeader($subject));
  2312.         }
  2313.         //Can't use additional_parameters in safe_mode
  2314.         //@link http://php.net/manual/en/function.mail.php
  2315.         if (ini_get('safe_mode') or !$this->UseSendmailOptions or is_null($params)) {
  2316.             $result = @mail($to, $subject, $body, $header);
  2317.         } else {
  2318.             $result = @mail($to, $subject, $body, $header, $params);
  2319.         }
  2320.         return $result;
  2321.     }
  2322.     /**
  2323.      * Output debugging info via user-defined method.
  2324.      * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
  2325.      * @see PHPMailer::$Debugoutput
  2326.      * @see PHPMailer::$SMTPDebug
  2327.      * @param string $str
  2328.      */
  2329.     protected function edebug($str)
  2330.     {
  2331.         if ($this->SMTPDebug <= 0) {
  2332.             return;
  2333.         }
  2334.         //Avoid clash with built-in function names
  2335.         if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  2336.             call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  2337.             return;
  2338.         }
  2339.         switch ($this->Debugoutput) {
  2340.             case 'error_log':
  2341.                 //Don't output, just log
  2342.                 error_log($str);
  2343.                 break;
  2344.             case 'html':
  2345.                 //Cleans up output a bit for a better looking, HTML-safe output
  2346.                 echo htmlentities(
  2347.                     preg_replace('/[\r\n]+/', '', $str),
  2348.                     ENT_QUOTES,
  2349.                     'UTF-8'
  2350.                 )
  2351.                 . "<br>\n";
  2352.                 break;
  2353.             case 'echo':
  2354.             default:
  2355.                 //Normalize line breaks
  2356.                 $str = preg_replace('/\r\n?/ms', "\n", $str);
  2357.                 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  2358.                     "\n",
  2359.                     "\n                   \t                  ",
  2360.                     trim($str)
  2361.                 ) . "\n";
  2362.         }
  2363.     }
  2364.     /**
  2365.      * Sets message type to HTML or plain.
  2366.      * @param boolean $isHtml True for HTML mode.
  2367.      * @return void
  2368.      */
  2369.     public function isHTML($isHtml = true)
  2370.     {
  2371.         if ($isHtml) {
  2372.             $this->ContentType = 'text/html';
  2373.         } else {
  2374.             $this->ContentType = 'text/plain';
  2375.         }
  2376.     }
  2377.     /**
  2378.      * Send messages using SMTP.
  2379.      * @return void
  2380.      */
  2381.     public function isSMTP()
  2382.     {
  2383.         $this->Mailer = 'smtp';
  2384.     }
  2385.     /**
  2386.      * Send messages using PHP's mail() function.
  2387.      * @return void
  2388.      */
  2389.     public function isMail()
  2390.     {
  2391.         $this->Mailer = 'mail';
  2392.     }
  2393.     /**
  2394.      * Send messages using $Sendmail.
  2395.      * @return void
  2396.      */
  2397.     public function isSendmail()
  2398.     {
  2399.         $ini_sendmail_path = ini_get('sendmail_path');
  2400.         if (!stristr($ini_sendmail_path, 'sendmail')) {
  2401.             $this->Sendmail = '/usr/sbin/sendmail';
  2402.         } else {
  2403.             $this->Sendmail = $ini_sendmail_path;
  2404.         }
  2405.         $this->Mailer = 'sendmail';
  2406.     }
  2407.     /**
  2408.      * Send messages using qmail.
  2409.      * @return void
  2410.      */
  2411.     public function isQmail()
  2412.     {
  2413.         $ini_sendmail_path = ini_get('sendmail_path');
  2414.         if (!stristr($ini_sendmail_path, 'qmail')) {
  2415.             $this->Sendmail = '/var/qmail/bin/qmail-inject';
  2416.         } else {
  2417.             $this->Sendmail = $ini_sendmail_path;
  2418.         }
  2419.         $this->Mailer = 'qmail';
  2420.     }
  2421.     /**
  2422.      * Add a "To" address.
  2423.      * @param string $address The email address to send to
  2424.      * @param string $name
  2425.      * @return boolean true on success, false if address already used or invalid in some way
  2426.      */
  2427.     public function addAddress($address, $name = '')
  2428.     {
  2429.         return $this->addOrEnqueueAnAddress('to', $address, $name);
  2430.     }
  2431.     /**
  2432.      * Add a "CC" address.
  2433.      * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  2434.      * @param string $address The email address to send to
  2435.      * @param string $name
  2436.      * @return boolean true on success, false if address already used or invalid in some way
  2437.      */
  2438.     public function addCC($address, $name = '')
  2439.     {
  2440.         return $this->addOrEnqueueAnAddress('cc', $address, $name);
  2441.     }
  2442.     /**
  2443.      * Add a "BCC" address.
  2444.      * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  2445.      * @param string $address The email address to send to
  2446.      * @param string $name
  2447.      * @return boolean true on success, false if address already used or invalid in some way
  2448.      */
  2449.     public function addBCC($address, $name = '')
  2450.     {
  2451.         return $this->addOrEnqueueAnAddress('bcc', $address, $name);
  2452.     }
  2453.     /**
  2454.      * Add a "Reply-To" address.
  2455.      * @param string $address The email address to reply to
  2456.      * @param string $name
  2457.      * @return boolean true on success, false if address already used or invalid in some way
  2458.      */
  2459.     public function addReplyTo($address, $name = '')
  2460.     {
  2461.         return $this->addOrEnqueueAnAddress('Reply-To', $address, $name);
  2462.     }
  2463.     /**
  2464.      * Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer
  2465.      * can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still
  2466.      * be modified after calling this function), addition of such addresses is delayed until send().
  2467.      * Addresses that have been added already return false, but do not throw exceptions.
  2468.      * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  2469.      * @param string $address The email address to send, resp. to reply to
  2470.      * @param string $name
  2471.      * @throws phpmailerException
  2472.      * @return boolean true on success, false if address already used or invalid in some way
  2473.      * @access protected
  2474.      */
  2475.     protected function addOrEnqueueAnAddress($kind, $address, $name)
  2476.     {
  2477.         $address = trim($address);
  2478.         $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  2479.         if (($pos = strrpos($address, '@')) === false) {
  2480.             // At-sign is misssing.
  2481.             $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address";
  2482.             $this->setError($error_message);
  2483.             $this->edebug($error_message);
  2484.             if ($this->exceptions) {
  2485.                 throw new phpmailerException($error_message);
  2486.             }
  2487.             return false;
  2488.         }
  2489.         $params = array($kind, $address, $name);
  2490.         // Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
  2491.         if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
  2492.             if ($kind != 'Reply-To') {
  2493.                 if (!array_key_exists($address, $this->RecipientsQueue)) {
  2494.                     $this->RecipientsQueue[$address] = $params;
  2495.                     return true;
  2496.                 }
  2497.             } else {
  2498.                 if (!array_key_exists($address, $this->ReplyToQueue)) {
  2499.                     $this->ReplyToQueue[$address] = $params;
  2500.                     return true;
  2501.                 }
  2502.             }
  2503.             return false;
  2504.         }
  2505.         // Immediately add standard addresses without IDN.
  2506.         return call_user_func_array(array($this, 'addAnAddress'), $params);
  2507.     }
  2508.     /**
  2509.      * Add an address to one of the recipient arrays or to the ReplyTo array.
  2510.      * Addresses that have been added already return false, but do not throw exceptions.
  2511.      * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  2512.      * @param string $address The email address to send, resp. to reply to
  2513.      * @param string $name
  2514.      * @throws phpmailerException
  2515.      * @return boolean true on success, false if address already used or invalid in some way
  2516.      * @access protected
  2517.      */
  2518.     protected function addAnAddress($kind, $address, $name = '')
  2519.     {
  2520.         if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) {
  2521.             $error_message = $this->lang('Invalid recipient kind: ') . $kind;
  2522.             $this->setError($error_message);
  2523.             $this->edebug($error_message);
  2524.             if ($this->exceptions) {
  2525.                 throw new phpmailerException($error_message);
  2526.             }
  2527.             return false;
  2528.         }
  2529.         if (!$this->validateAddress($address)) {
  2530.             $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address";
  2531.             $this->setError($error_message);
  2532.             $this->edebug($error_message);
  2533.             if ($this->exceptions) {
  2534.                 throw new phpmailerException($error_message);
  2535.             }
  2536.             return false;
  2537.         }
  2538.         if ($kind != 'Reply-To') {
  2539.             if (!array_key_exists(strtolower($address), $this->all_recipients)) {
  2540.                 array_push($this->$kind, array($address, $name));
  2541.                 $this->all_recipients[strtolower($address)] = true;
  2542.                 return true;
  2543.             }
  2544.         } else {
  2545.             if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  2546.                 $this->ReplyTo[strtolower($address)] = array($address, $name);
  2547.                 return true;
  2548.             }
  2549.         }
  2550.         return false;
  2551.     }
  2552.     /**
  2553.      * Parse and validate a string containing one or more RFC822-style comma-separated email addresses
  2554.      * of the form "display name <address>" into an array of name/address pairs.
  2555.      * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available.
  2556.      * Note that quotes in the name part are removed.
  2557.      * @param string $addrstr The address list string
  2558.      * @param bool $useimap Whether to use the IMAP extension to parse the list
  2559.      * @return array
  2560.      * @link http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation
  2561.      */
  2562.     public function parseAddresses($addrstr, $useimap = true)
  2563.     {
  2564.         $addresses = array();
  2565.         if ($useimap and function_exists('imap_rfc822_parse_adrlist')) {
  2566.             //Use this built-in parser if it's available
  2567.             $list = imap_rfc822_parse_adrlist($addrstr, '');
  2568.             foreach ($list as $address) {
  2569.                 if ($address->host != '.SYNTAX-ERROR.') {
  2570.                     if ($this->validateAddress($address->mailbox . '@' . $address->host)) {
  2571.                         $addresses[] = array(
  2572.                             'name' => (property_exists($address, 'personal') ? $address->personal : ''),
  2573.                             'address' => $address->mailbox . '@' . $address->host
  2574.                         );
  2575.                     }
  2576.                 }
  2577.             }
  2578.         } else {
  2579.             //Use this simpler parser
  2580.             $list = explode(',', $addrstr);
  2581.             foreach ($list as $address) {
  2582.                 $address = trim($address);
  2583.                 //Is there a separate name part?
  2584.                 if (strpos($address, '<') === false) {
  2585.                     //No separate name, just use the whole thing
  2586.                     if ($this->validateAddress($address)) {
  2587.                         $addresses[] = array(
  2588.                             'name' => '',
  2589.                             'address' => $address
  2590.                         );
  2591.                     }
  2592.                 } else {
  2593.                     list($name, $email) = explode('<', $address);
  2594.                     $email = trim(str_replace('>', '', $email));
  2595.                     if ($this->validateAddress($email)) {
  2596.                         $addresses[] = array(
  2597.                             'name' => trim(str_replace(array('"', "'"), '', $name)),
  2598.                             'address' => $email
  2599.                         );
  2600.                     }
  2601.                 }
  2602.             }
  2603.         }
  2604.         return $addresses;
  2605.     }
  2606.     /**
  2607.      * Set the From and FromName properties.
  2608.      * @param string $address
  2609.      * @param string $name
  2610.      * @param boolean $auto Whether to also set the Sender address, defaults to true
  2611.      * @throws phpmailerException
  2612.      * @return boolean
  2613.      */
  2614.     public function setFrom($address, $name = '', $auto = true)
  2615.     {
  2616.         $address = trim($address);
  2617.         $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  2618.         // Don't validate now addresses with IDN. Will be done in send().
  2619.         if (($pos = strrpos($address, '@')) === false or
  2620.             (!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and
  2621.             !$this->validateAddress($address)) {
  2622.             $error_message = $this->lang('invalid_address') . " (setFrom) $address";
  2623.             $this->setError($error_message);
  2624.             $this->edebug($error_message);
  2625.             if ($this->exceptions) {
  2626.                 throw new phpmailerException($error_message);
  2627.             }
  2628.             return false;
  2629.         }
  2630.         $this->From = $address;
  2631.         $this->FromName = $name;
  2632.         if ($auto) {
  2633.             if (empty($this->Sender)) {
  2634.                 $this->Sender = $address;
  2635.             }
  2636.         }
  2637.         return true;
  2638.     }
  2639.     /**
  2640.      * Return the Message-ID header of the last email.
  2641.      * Technically this is the value from the last time the headers were created,
  2642.      * but it's also the message ID of the last sent message except in
  2643.      * pathological cases.
  2644.      * @return string
  2645.      */
  2646.     public function getLastMessageID()
  2647.     {
  2648.         return $this->lastMessageID;
  2649.     }
  2650.     /**
  2651.      * Check that a string looks like an email address.
  2652.      * @param string $address The email address to check
  2653.      * @param string|callable $patternselect A selector for the validation pattern to use :
  2654.      * * `auto` Pick best pattern automatically;
  2655.      * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  2656.      * * `pcre` Use old PCRE implementation;
  2657.      * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
  2658.      * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
  2659.      * * `noregex` Don't use a regex: super fast, really dumb.
  2660.      * Alternatively you may pass in a callable to inject your own validator, for example:
  2661.      * PHPMailer::validateAddress('user@example.com', function($address) {
  2662.      *     return (strpos($address, '@') !== false);
  2663.      * });
  2664.      * You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator.
  2665.      * @return boolean
  2666.      * @static
  2667.      * @access public
  2668.      */
  2669.     public static function validateAddress($address, $patternselect = null)
  2670.     {
  2671.         if (is_null($patternselect)) {
  2672.             $patternselect = self::$validator;
  2673.         }
  2674.         if (is_callable($patternselect)) {
  2675.             return call_user_func($patternselect, $address);
  2676.         }
  2677.         //Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
  2678.         if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) {
  2679.             return false;
  2680.         }
  2681.         if (!$patternselect or $patternselect == 'auto') {
  2682.             //Check this constant first so it works when extension_loaded() is disabled by safe mode
  2683.             //Constant was added in PHP 5.2.4
  2684.             if (defined('PCRE_VERSION')) {
  2685.                 //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  2686.                 if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
  2687.                     $patternselect = 'pcre8';
  2688.                 } else {
  2689.                     $patternselect = 'pcre';
  2690.                 }
  2691.             } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
  2692.                 //Fall back to older PCRE
  2693.                 $patternselect = 'pcre';
  2694.             } else {
  2695.                 //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  2696.                 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  2697.                     $patternselect = 'php';
  2698.                 } else {
  2699.                     $patternselect = 'noregex';
  2700.                 }
  2701.             }
  2702.         }
  2703.         switch ($patternselect) {
  2704.             case 'pcre8':
  2705.                 /**
  2706.                  * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
  2707.                  * @link http://squiloople.com/2009/12/20/email-address-validation/
  2708.                  * @copyright 2009-2010 Michael Rushton
  2709.                  * Feel free to use and redistribute this code. But please keep this copyright notice.
  2710.                  */
  2711.                 return (boolean)preg_match(
  2712.                     '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  2713.                     '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  2714.                     '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  2715.                     '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  2716.                     '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  2717.                     '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  2718.                     '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  2719.                     '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  2720.                     '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  2721.                     $address
  2722.                 );
  2723.             case 'pcre':
  2724.                 //An older regex that doesn't need a recent PCRE
  2725.                 return (boolean)preg_match(
  2726.                     '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  2727.                     '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  2728.                     '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  2729.                     '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  2730.                     '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  2731.                     '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  2732.                     '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  2733.                     '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  2734.                     '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  2735.                     '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  2736.                     $address
  2737.                 );
  2738.             case 'html5':
  2739.                 /**
  2740.                  * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
  2741.                  * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
  2742.                  */
  2743.                 return (boolean)preg_match(
  2744.                     '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  2745.                     '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  2746.                     $address
  2747.                 );
  2748.             case 'noregex':
  2749.                 //No PCRE! Do something _very_ approximate!
  2750.                 //Check the address is 3 chars or longer and contains an @ that's not the first or last char
  2751.                 return (strlen($address) >= 3
  2752.                     and strpos($address, '@') >= 1
  2753.                     and strpos($address, '@') != strlen($address) - 1);
  2754.             case 'php':
  2755.             default:
  2756.                 return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  2757.         }
  2758.     }
  2759.     /**
  2760.      * Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the
  2761.      * "intl" and "mbstring" PHP extensions.
  2762.      * @return bool "true" if required functions for IDN support are present
  2763.      */
  2764.     public function idnSupported()
  2765.     {
  2766.         // @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2.
  2767.         return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding');
  2768.     }
  2769.     /**
  2770.      * Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
  2771.      * Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet.
  2772.      * This function silently returns unmodified address if:
  2773.      * - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
  2774.      * - Conversion to punycode is impossible (e.g. required PHP functions are not available)
  2775.      *   or fails for any reason (e.g. domain has characters not allowed in an IDN)
  2776.      * @see PHPMailer::$CharSet
  2777.      * @param string $address The email address to convert
  2778.      * @return string The encoded address in ASCII form
  2779.      */
  2780.     public function punyencodeAddress($address)
  2781.     {
  2782.         // Verify we have required functions, CharSet, and at-sign.
  2783.         if ($this->idnSupported() and
  2784.             !empty($this->CharSet) and
  2785.             ($pos = strrpos($address, '@')) !== false) {
  2786.             $domain = substr($address, ++$pos);
  2787.             // Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
  2788.             if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
  2789.                 $domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet);
  2790.                 if (($punycode = defined('INTL_IDNA_VARIANT_UTS46') ?
  2791.                     idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
  2792.                     idn_to_ascii($domain)) !== false) {
  2793.                     return substr($address, 0, $pos) . $punycode;
  2794.                 }
  2795.             }
  2796.         }
  2797.         return $address;
  2798.     }
  2799.     /**
  2800.      * Create a message and send it.
  2801.      * Uses the sending method specified by $Mailer.
  2802.      * @throws phpmailerException
  2803.      * @return boolean false on error - See the ErrorInfo property for details of the error.
  2804.      */
  2805.     public function send()
  2806.     {
  2807.         try {
  2808.             if (!$this->preSend()) {
  2809.                 return false;
  2810.             }
  2811.             return $this->postSend();
  2812.         } catch (phpmailerException $exc) {
  2813.             $this->mailHeader = '';
  2814.             $this->setError($exc->getMessage());
  2815.             if ($this->exceptions) {
  2816.                 throw $exc;
  2817.             }
  2818.             return false;
  2819.         }
  2820.     }
  2821.     /**
  2822.      * Prepare a message for sending.
  2823.      * @throws phpmailerException
  2824.      * @return boolean
  2825.      */
  2826.     public function preSend()
  2827.     {
  2828.         try {
  2829.             $this->error_count = 0; // Reset errors
  2830.             $this->mailHeader = '';
  2831.             // Dequeue recipient and Reply-To addresses with IDN
  2832.             foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
  2833.                 $params[1] = $this->punyencodeAddress($params[1]);
  2834.                 call_user_func_array(array($this, 'addAnAddress'), $params);
  2835.             }
  2836.             if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  2837.                 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  2838.             }
  2839.             // Validate From, Sender, and ConfirmReadingTo addresses
  2840.             foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) {
  2841.                 $this->$address_kind = trim($this->$address_kind);
  2842.                 if (empty($this->$address_kind)) {
  2843.                     continue;
  2844.                 }
  2845.                 $this->$address_kind = $this->punyencodeAddress($this->$address_kind);
  2846.                 if (!$this->validateAddress($this->$address_kind)) {
  2847.                     $error_message = $this->lang('invalid_address') . ' (punyEncode) ' . $this->$address_kind;
  2848.                     $this->setError($error_message);
  2849.                     $this->edebug($error_message);
  2850.                     if ($this->exceptions) {
  2851.                         throw new phpmailerException($error_message);
  2852.                     }
  2853.                     return false;
  2854.                 }
  2855.             }
  2856.             // Set whether the message is multipart/alternative
  2857.             if ($this->alternativeExists()) {
  2858.                 $this->ContentType = 'multipart/alternative';
  2859.             }
  2860.             $this->setMessageType();
  2861.             // Refuse to send an empty message unless we are specifically allowing it
  2862.             if (!$this->AllowEmpty and empty($this->Body)) {
  2863.                 throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  2864.             }
  2865.             // Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
  2866.             $this->MIMEHeader = '';
  2867.             $this->MIMEBody = $this->createBody();
  2868.             // createBody may have added some headers, so retain them
  2869.             $tempheaders = $this->MIMEHeader;
  2870.             $this->MIMEHeader = $this->createHeader();
  2871.             $this->MIMEHeader .= $tempheaders;
  2872.             // To capture the complete message when using mail(), create
  2873.             // an extra header list which createHeader() doesn't fold in
  2874.             if ($this->Mailer == 'mail') {
  2875.                 if (count($this->to) > 0) {
  2876.                     $this->mailHeader .= $this->addrAppend('To', $this->to);
  2877.                 } else {
  2878.                     $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  2879.                 }
  2880.                 $this->mailHeader .= $this->headerLine(
  2881.                     'Subject',
  2882.                     $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  2883.                 );
  2884.             }
  2885.             // Sign with DKIM if enabled
  2886.             if (!empty($this->DKIM_domain)
  2887.                 && !empty($this->DKIM_selector)
  2888.                 && (!empty($this->DKIM_private_string)
  2889.                    || (!empty($this->DKIM_private) && file_exists($this->DKIM_private))
  2890.                 )
  2891.             ) {
  2892.                 $header_dkim = $this->DKIM_Add(
  2893.                     $this->MIMEHeader . $this->mailHeader,
  2894.                     $this->encodeHeader($this->secureHeader($this->Subject)),
  2895.                     $this->MIMEBody
  2896.                 );
  2897.                 $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  2898.                     str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  2899.             }
  2900.             return true;
  2901.         } catch (phpmailerException $exc) {
  2902.             $this->setError($exc->getMessage());
  2903.             if ($this->exceptions) {
  2904.                 throw $exc;
  2905.             }
  2906.             return false;
  2907.         }
  2908.     }
  2909.     /**
  2910.      * Actually send a message.
  2911.      * Send the email via the selected mechanism
  2912.      * @throws phpmailerException
  2913.      * @return boolean
  2914.      */
  2915.     public function postSend()
  2916.     {
  2917.         try {
  2918.             // Choose the mailer and send through it
  2919.             switch ($this->Mailer) {
  2920.                 case 'sendmail':
  2921.                 case 'qmail':
  2922.                     return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  2923.                 case 'smtp':
  2924.                     return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
  2925.                 case 'mail':
  2926.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  2927.                 default:
  2928.                     $sendMethod = $this->Mailer.'Send';
  2929.                     if (method_exists($this, $sendMethod)) {
  2930.                         return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  2931.                     }
  2932.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  2933.             }
  2934.         } catch (phpmailerException $exc) {
  2935.             $this->setError($exc->getMessage());
  2936.             $this->edebug($exc->getMessage());
  2937.             if ($this->exceptions) {
  2938.                 throw $exc;
  2939.             }
  2940.         }
  2941.         return false;
  2942.     }
  2943.     /**
  2944.      * Send mail using the $Sendmail program.
  2945.      * @param string $header The message headers
  2946.      * @param string $body The message body
  2947.      * @see PHPMailer::$Sendmail
  2948.      * @throws phpmailerException
  2949.      * @access protected
  2950.      * @return boolean
  2951.      */
  2952.     protected function sendmailSend($header, $body)
  2953.     {
  2954.         if ($this->Sender != '') {
  2955.             if ($this->Mailer == 'qmail') {
  2956.                 $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  2957.             } else {
  2958.                 $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  2959.             }
  2960.         } else {
  2961.             if ($this->Mailer == 'qmail') {
  2962.                 $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  2963.             } else {
  2964.                 $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  2965.             }
  2966.         }
  2967.         if ($this->SingleTo) {
  2968.             foreach ($this->SingleToArray as $toAddr) {
  2969.                 if (!@$mail = popen($sendmail, 'w')) {
  2970.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  2971.                 }
  2972.                 fputs($mail, 'To: ' . $toAddr . "\n");
  2973.                 fputs($mail, $header);
  2974.                 fputs($mail, $body);
  2975.                 $result = pclose($mail);
  2976.                 $this->doCallback(
  2977.                     ($result == 0),
  2978.                     array($toAddr),
  2979.                     $this->cc,
  2980.                     $this->bcc,
  2981.                     $this->Subject,
  2982.                     $body,
  2983.                     $this->From
  2984.                 );
  2985.                 if ($result != 0) {
  2986.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  2987.                 }
  2988.             }
  2989.         } else {
  2990.             if (!@$mail = popen($sendmail, 'w')) {
  2991.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  2992.             }
  2993.             fputs($mail, $header);
  2994.             fputs($mail, $body);
  2995.             $result = pclose($mail);
  2996.             $this->doCallback(
  2997.                 ($result == 0),
  2998.                 $this->to,
  2999.                 $this->cc,
  3000.                 $this->bcc,
  3001.                 $this->Subject,
  3002.                 $body,
  3003.                 $this->From
  3004.             );
  3005.             if ($result != 0) {
  3006.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  3007.             }
  3008.         }
  3009.         return true;
  3010.     }
  3011.     /**
  3012.      * Send mail using the PHP mail() function.
  3013.      * @param string $header The message headers
  3014.      * @param string $body The message body
  3015.      * @link http://www.php.net/manual/en/book.mail.php
  3016.      * @throws phpmailerException
  3017.      * @access protected
  3018.      * @return boolean
  3019.      */
  3020.     protected function mailSend($header, $body)
  3021.     {
  3022.         $toArr = array();
  3023.         foreach ($this->to as $toaddr) {
  3024.             $toArr[] = $this->addrFormat($toaddr);
  3025.         }
  3026.         $to = implode(', ', $toArr);
  3027.         $params = null;
  3028.         //This sets the SMTP envelope sender which gets turned into a return-path header by the receiver
  3029.         if (!empty($this->Sender)) {
  3030.             $params = sprintf('-f%s', $this->Sender);
  3031.         }
  3032.         if ($this->Sender != '' and !ini_get('safe_mode')) {
  3033.             $old_from = ini_get('sendmail_from');
  3034.             ini_set('sendmail_from', $this->Sender);
  3035.         }
  3036.         $result = false;
  3037.         if ($this->SingleTo and count($toArr) > 1) {
  3038.             foreach ($toArr as $toAddr) {
  3039.                 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  3040.                 $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  3041.             }
  3042.         } else {
  3043.             $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  3044.             $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  3045.         }
  3046.         if (isset($old_from)) {
  3047.             ini_set('sendmail_from', $old_from);
  3048.         }
  3049.         if (!$result) {
  3050.             throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  3051.         }
  3052.         return true;
  3053.     }
  3054.     /**
  3055.      * Get an instance to use for SMTP operations.
  3056.      * Override this function to load your own SMTP implementation
  3057.      * @return SMTP
  3058.      */
  3059.     public function getSMTPInstance()
  3060.     {
  3061.         if (!is_object($this->smtp)) {
  3062.             $this->smtp = new SMTP;
  3063.         }
  3064.         return $this->smtp;
  3065.     }
  3066.     /**
  3067.      * Send mail via SMTP.
  3068.      * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  3069.      * Uses the PHPMailerSMTP class by default.
  3070.      * @see PHPMailer::getSMTPInstance() to use a different class.
  3071.      * @param string $header The message headers
  3072.      * @param string $body The message body
  3073.      * @throws phpmailerException
  3074.      * @uses SMTP
  3075.      * @access protected
  3076.      * @return boolean
  3077.      */
  3078.     protected function smtpSend($header, $body)
  3079.     {
  3080.         $bad_rcpt = array();
  3081.         if (!$this->smtpConnect($this->SMTPOptions)) {
  3082.             throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  3083.         }
  3084.         if ('' == $this->Sender) {
  3085.             $smtp_from = $this->From;
  3086.         } else {
  3087.             $smtp_from = $this->Sender;
  3088.         }
  3089.         if (!$this->smtp->mail($smtp_from)) {
  3090.             $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  3091.             throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  3092.         }
  3093.         // Attempt to send to all recipients
  3094.         foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
  3095.             foreach ($togroup as $to) {
  3096.                 if (!$this->smtp->recipient($to[0])) {
  3097.                     $error = $this->smtp->getError();
  3098.                     $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
  3099.                     $isSent = false;
  3100.                 } else {
  3101.                     $isSent = true;
  3102.                 }
  3103.                 $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  3104.             }
  3105.         }
  3106.         // Only send the DATA command if we have viable recipients
  3107.         if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  3108.             throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  3109.         }
  3110.         if ($this->SMTPKeepAlive) {
  3111.             $this->smtp->reset();
  3112.         } else {
  3113.             $this->smtp->quit();
  3114.             $this->smtp->close();
  3115.         }
  3116.         //Create error message for any bad addresses
  3117.         if (count($bad_rcpt) > 0) {
  3118.             $errstr = '';
  3119.             foreach ($bad_rcpt as $bad) {
  3120.                 $errstr .= $bad['to'] . ': ' . $bad['error'];
  3121.             }
  3122.             throw new phpmailerException(
  3123.                 $this->lang('recipients_failed') . $errstr,
  3124.                 self::STOP_CONTINUE
  3125.             );
  3126.         }
  3127.         return true;
  3128.     }
  3129.     /**
  3130.      * Initiate a connection to an SMTP server.
  3131.      * Returns false if the operation failed.
  3132.      * @param array $options An array of options compatible with stream_context_create()
  3133.      * @uses SMTP
  3134.      * @access public
  3135.      * @throws phpmailerException
  3136.      * @return boolean
  3137.      */
  3138.     public function smtpConnect($options = null)
  3139.     {
  3140.         if (is_null($this->smtp)) {
  3141.             $this->smtp = $this->getSMTPInstance();
  3142.         }
  3143.         //If no options are provided, use whatever is set in the instance
  3144.         if (is_null($options)) {
  3145.             $options = $this->SMTPOptions;
  3146.         }
  3147.         // Already connected?
  3148.         if ($this->smtp->connected()) {
  3149.             return true;
  3150.         }
  3151.         $this->smtp->setTimeout($this->Timeout);
  3152.         $this->smtp->setDebugLevel($this->SMTPDebug);
  3153.         $this->smtp->setDebugOutput($this->Debugoutput);
  3154.         $this->smtp->setVerp($this->do_verp);
  3155.         $hosts = explode(';', $this->Host);
  3156.         $lastexception = null;
  3157.         foreach ($hosts as $hostentry) {
  3158.             $hostinfo = array();
  3159.             if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9:\[\]\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)){
  3160.                 // Not a valid host entry
  3161.                 continue;
  3162.             }
  3163.             // $hostinfo[2]: optional ssl or tls prefix
  3164.             // $hostinfo[3]: the hostname
  3165.             // $hostinfo[4]: optional port number
  3166.             // The host string prefix can temporarily override the current setting for SMTPSecure
  3167.             // If it's not specified, the default value is used
  3168.             $prefix = '';
  3169.             $secure = $this->SMTPSecure;
  3170.             $tls = ($this->SMTPSecure == 'tls');
  3171.             if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
  3172.                 $prefix = 'ssl://';
  3173.                 $tls = false; // Can't have SSL and TLS at the same time
  3174.                 $secure = 'ssl';
  3175.             } elseif ($hostinfo[2] == 'tls') {
  3176.                 $tls = true;
  3177.                 // tls doesn't use a prefix
  3178.                 $secure = 'tls';
  3179.             }
  3180.             //Do we need the OpenSSL extension?
  3181.             $sslext = defined('OPENSSL_ALGO_SHA1');
  3182.             if ('tls' === $secure or 'ssl' === $secure) {
  3183.                 //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
  3184.                 if (!$sslext) {
  3185.                     throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
  3186.                 }
  3187.             }
  3188.             $host = $hostinfo[3];
  3189.             $port = $this->Port;
  3190.             $tport = (integer)$hostinfo[4];
  3191.             if ($tport > 0 and $tport < 65536) {
  3192.                 $port = $tport;
  3193.             }
  3194.             if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  3195.                 try {
  3196.                     if ($this->Helo) {
  3197.                         $hello = $this->Helo;
  3198.                     } else {
  3199.                         $hello = $this->serverHostname();
  3200.                     }
  3201.                     $this->smtp->hello($hello);
  3202.                     //Automatically enable TLS encryption if:
  3203.                     // * it's not disabled
  3204.                     // * we have openssl extension
  3205.                     // * we are not already using SSL
  3206.                     // * the server offers STARTTLS
  3207.                     if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
  3208.                         $tls = true;
  3209.                     }
  3210.                     if ($tls) {
  3211.                         if (!$this->smtp->startTLS()) {
  3212.                             throw new phpmailerException($this->lang('connect_host'));
  3213.                         }
  3214.                         // We must resend EHLO after TLS negotiation
  3215.                         $this->smtp->hello($hello);
  3216.                     }
  3217.                     if ($this->SMTPAuth) {
  3218.                         if (!$this->smtp->authenticate(
  3219.                             $this->Username,
  3220.                             $this->Password,
  3221.                             $this->AuthType,
  3222.                             $this->Realm,
  3223.                             $this->Workstation
  3224.                         )
  3225.                         ) {
  3226.                             throw new phpmailerException($this->lang('authenticate'));
  3227.                         }
  3228.                     }
  3229.                     return true;
  3230.                 } catch (phpmailerException $exc) {
  3231.                     $lastexception = $exc;
  3232.                     $this->edebug($exc->getMessage());
  3233.                     // We must have connected, but then failed TLS or Auth, so close connection nicely
  3234.                     $this->smtp->quit();
  3235.                 }
  3236.             }
  3237.         }
  3238.         // If we get here, all connection attempts have failed, so close connection hard
  3239.         $this->smtp->close();
  3240.         // As we've caught all exceptions, just report whatever the last one was
  3241.         if ($this->exceptions and !is_null($lastexception)) {
  3242.             throw $lastexception;
  3243.         }
  3244.         return false;
  3245.     }
  3246.     /**
  3247.      * Close the active SMTP session if one exists.
  3248.      * @return void
  3249.      */
  3250.     public function smtpClose()
  3251.     {
  3252.         if (is_a($this->smtp, 'SMTP')) {
  3253.             if ($this->smtp->connected()) {
  3254.                 $this->smtp->quit();
  3255.                 $this->smtp->close();
  3256.             }
  3257.         }
  3258.     }
  3259.     /**
  3260.      * Set the language for error messages.
  3261.      * Returns false if it cannot load the language file.
  3262.      * The default language is English.
  3263.      * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
  3264.      * @param string $lang_path Path to the language file directory, with trailing separator (slash)
  3265.      * @return boolean
  3266.      * @access public
  3267.      */
  3268.     public function setLanguage($langcode = 'en', $lang_path = '')
  3269.     {
  3270.         // Backwards compatibility for renamed language codes
  3271.         $renamed_langcodes = array(
  3272.             'br' => 'pt_br',
  3273.             'cz' => 'cs',
  3274.             'dk' => 'da',
  3275.             'no' => 'nb',
  3276.             'se' => 'sv',
  3277.         );
  3278.         if (isset($renamed_langcodes[$langcode])) {
  3279.             $langcode = $renamed_langcodes[$langcode];
  3280.         }
  3281.         // Define full set of translatable strings in English
  3282.         $PHPMAILER_LANG = array(
  3283.             'authenticate' => 'SMTP Error: Could not authenticate.',
  3284.             'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  3285.             'data_not_accepted' => 'SMTP Error: data not accepted.',
  3286.             'empty_message' => 'Message body empty',
  3287.             'encoding' => 'Unknown encoding: ',
  3288.             'execute' => 'Could not execute: ',
  3289.             'file_access' => 'Could not access file: ',
  3290.             'file_open' => 'File Error: Could not open file: ',
  3291.             'from_failed' => 'The following From address failed: ',
  3292.             'instantiate' => 'Could not instantiate mail function.',
  3293.             'invalid_address' => 'Invalid address: ',
  3294.             'mailer_not_supported' => ' mailer is not supported.',
  3295.             'provide_address' => 'You must provide at least one recipient email address.',
  3296.             'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  3297.             'signing' => 'Signing Error: ',
  3298.             'smtp_connect_failed' => 'SMTP connect() failed.',
  3299.             'smtp_error' => 'SMTP server error: ',
  3300.             'variable_set' => 'Cannot set or reset variable: ',
  3301.             'extension_missing' => 'Extension missing: '
  3302.         );
  3303.         if (empty($lang_path)) {
  3304.             // Calculate an absolute path so it can work if CWD is not here
  3305.             $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  3306.         }
  3307.         //Validate $langcode
  3308.         if (!preg_match('/^[a-z]{2}(?:_[a-zA-Z]{2})?$/', $langcode)) {
  3309.             $langcode = 'en';
  3310.         }
  3311.         $foundlang = true;
  3312.         $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  3313.         // There is no English translation file
  3314.         if ($langcode != 'en') {
  3315.             // Make sure language file path is readable
  3316.             if (!is_readable($lang_file)) {
  3317.                 $foundlang = false;
  3318.             } else {
  3319.                 // Overwrite language-specific strings.
  3320.                 // This way we'll never have missing translation keys.
  3321.                 $foundlang = include $lang_file;
  3322.             }
  3323.         }
  3324.         $this->language = $PHPMAILER_LANG;
  3325.         return (boolean)$foundlang; // Returns false if language not found
  3326.     }
  3327.     /**
  3328.      * Get the array of strings for the current language.
  3329.      * @return array
  3330.      */
  3331.     public function getTranslations()
  3332.     {
  3333.         return $this->language;
  3334.     }
  3335.     /**
  3336.      * Create recipient headers.
  3337.      * @access public
  3338.      * @param string $type
  3339.      * @param array $addr An array of recipient,
  3340.      * where each recipient is a 2-element indexed array with element 0 containing an address
  3341.      * and element 1 containing a name, like:
  3342.      * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
  3343.      * @return string
  3344.      */
  3345.     public function addrAppend($type, $addr)
  3346.     {
  3347.         $addresses = array();
  3348.         foreach ($addr as $address) {
  3349.             $addresses[] = $this->addrFormat($address);
  3350.         }
  3351.         return $type . ': ' . implode(', ', $addresses) . $this->LE;
  3352.     }
  3353.     /**
  3354.      * Format an address for use in a message header.
  3355.      * @access public
  3356.      * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
  3357.      *      like array('joe@example.com', 'Joe User')
  3358.      * @return string
  3359.      */
  3360.     public function addrFormat($addr)
  3361.     {
  3362.         if (empty($addr[1])) { // No name provided
  3363.             return $this->secureHeader($addr[0]);
  3364.         } else {
  3365.             return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
  3366.                 $addr[0]
  3367.             ) . '>';
  3368.         }
  3369.     }
  3370.     /**
  3371.      * Word-wrap message.
  3372.      * For use with mailers that do not automatically perform wrapping
  3373.      * and for quoted-printable encoded messages.
  3374.      * Original written by philippe.
  3375.      * @param string $message The message to wrap
  3376.      * @param integer $length The line length to wrap to
  3377.      * @param boolean $qp_mode Whether to run in Quoted-Printable mode
  3378.      * @access public
  3379.      * @return string
  3380.      */
  3381.     public function wrapText($message, $length, $qp_mode = false)
  3382.     {
  3383.         if ($qp_mode) {
  3384.             $soft_break = sprintf(' =%s', $this->LE);
  3385.         } else {
  3386.             $soft_break = $this->LE;
  3387.         }
  3388.         // If utf-8 encoding is used, we will need to make sure we don't
  3389.         // split multibyte characters when we wrap
  3390.         $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  3391.         $lelen = strlen($this->LE);
  3392.         $crlflen = strlen(self::CRLF);
  3393.         $message = $this->fixEOL($message);
  3394.         //Remove a trailing line break
  3395.         if (substr($message, -$lelen) == $this->LE) {
  3396.             $message = substr($message, 0, -$lelen);
  3397.         }
  3398.         //Split message into lines
  3399.         $lines = explode($this->LE, $message);
  3400.         //Message will be rebuilt in here
  3401.         $message = '';
  3402.         foreach ($lines as $line) {
  3403.             $words = explode(' ', $line);
  3404.             $buf = '';
  3405.             $firstword = true;
  3406.             foreach ($words as $word) {
  3407.                 if ($qp_mode and (strlen($word) > $length)) {
  3408.                     $space_left = $length - strlen($buf) - $crlflen;
  3409.                     if (!$firstword) {
  3410.                         if ($space_left > 20) {
  3411.                             $len = $space_left;
  3412.                             if ($is_utf8) {
  3413.                                 $len = $this->utf8CharBoundary($word, $len);
  3414.                             } elseif (substr($word, $len - 1, 1) == '=') {
  3415.                                 $len--;
  3416.                             } elseif (substr($word, $len - 2, 1) == '=') {
  3417.                                 $len -= 2;
  3418.                             }
  3419.                             $part = substr($word, 0, $len);
  3420.                             $word = substr($word, $len);
  3421.                             $buf .= ' ' . $part;
  3422.                             $message .= $buf . sprintf('=%s', self::CRLF);
  3423.                         } else {
  3424.                             $message .= $buf . $soft_break;
  3425.                         }
  3426.                         $buf = '';
  3427.                     }
  3428.                     while (strlen($word) > 0) {
  3429.                         if ($length <= 0) {
  3430.                             break;
  3431.                         }
  3432.                         $len = $length;
  3433.                         if ($is_utf8) {
  3434.                             $len = $this->utf8CharBoundary($word, $len);
  3435.                         } elseif (substr($word, $len - 1, 1) == '=') {
  3436.                             $len--;
  3437.                         } elseif (substr($word, $len - 2, 1) == '=') {
  3438.                             $len -= 2;
  3439.                         }
  3440.                         $part = substr($word, 0, $len);
  3441.                         $word = substr($word, $len);
  3442.                         if (strlen($word) > 0) {
  3443.                             $message .= $part . sprintf('=%s', self::CRLF);
  3444.                         } else {
  3445.                             $buf = $part;
  3446.                         }
  3447.                     }
  3448.                 } else {
  3449.                     $buf_o = $buf;
  3450.                     if (!$firstword) {
  3451.                         $buf .= ' ';
  3452.                     }
  3453.                     $buf .= $word;
  3454.                     if (strlen($buf) > $length and $buf_o != '') {
  3455.                         $message .= $buf_o . $soft_break;
  3456.                         $buf = $word;
  3457.                     }
  3458.                 }
  3459.                 $firstword = false;
  3460.             }
  3461.             $message .= $buf . self::CRLF;
  3462.         }
  3463.         return $message;
  3464.     }
  3465.     /**
  3466.      * Find the last character boundary prior to $maxLength in a utf-8
  3467.      * quoted-printable encoded string.
  3468.      * Original written by Colin Brown.
  3469.      * @access public
  3470.      * @param string $encodedText utf-8 QP text
  3471.      * @param integer $maxLength Find the last character boundary prior to this length
  3472.      * @return integer
  3473.      */
  3474.     public function utf8CharBoundary($encodedText, $maxLength)
  3475.     {
  3476.         $foundSplitPos = false;
  3477.         $lookBack = 3;
  3478.         while (!$foundSplitPos) {
  3479.             $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  3480.             $encodedCharPos = strpos($lastChunk, '=');
  3481.             if (false !== $encodedCharPos) {
  3482.                 // Found start of encoded character byte within $lookBack block.
  3483.                 // Check the encoded byte value (the 2 chars after the '=')
  3484.                 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  3485.                 $dec = hexdec($hex);
  3486.                 if ($dec < 128) {
  3487.                     // Single byte character.
  3488.                     // If the encoded char was found at pos 0, it will fit
  3489.                     // otherwise reduce maxLength to start of the encoded char
  3490.                     if ($encodedCharPos > 0) {
  3491.                         $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  3492.                     }
  3493.                     $foundSplitPos = true;
  3494.                 } elseif ($dec >= 192) {
  3495.                     // First byte of a multi byte character
  3496.                     // Reduce maxLength to split at start of character
  3497.                     $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  3498.                     $foundSplitPos = true;
  3499.                 } elseif ($dec < 192) {
  3500.                     // Middle byte of a multi byte character, look further back
  3501.                     $lookBack += 3;
  3502.                 }
  3503.             } else {
  3504.                 // No encoded character found
  3505.                 $foundSplitPos = true;
  3506.             }
  3507.         }
  3508.         return $maxLength;
  3509.     }
  3510.     /**
  3511.      * Apply word wrapping to the message body.
  3512.      * Wraps the message body to the number of chars set in the WordWrap property.
  3513.      * You should only do this to plain-text bodies as wrapping HTML tags may break them.
  3514.      * This is called automatically by createBody(), so you don't need to call it yourself.
  3515.      * @access public
  3516.      * @return void
  3517.      */
  3518.     public function setWordWrap()
  3519.     {
  3520.         if ($this->WordWrap < 1) {
  3521.             return;
  3522.         }
  3523.         switch ($this->message_type) {
  3524.             case 'alt':
  3525.             case 'alt_inline':
  3526.             case 'alt_attach':
  3527.             case 'alt_inline_attach':
  3528.                 $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  3529.                 break;
  3530.             default:
  3531.                 $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  3532.                 break;
  3533.         }
  3534.     }
  3535.     /**
  3536.      * Assemble message headers.
  3537.      * @access public
  3538.      * @return string The assembled headers
  3539.      */
  3540.     public function createHeader()
  3541.     {
  3542.         $result = '';
  3543.         if ($this->MessageDate == '') {
  3544.             $this->MessageDate = self::rfcDate();
  3545.         }
  3546.         $result .= $this->headerLine('Date', $this->MessageDate == '' ? self::rfcDate() : $this->MessageDate);
  3547.         // To be created automatically by mail()
  3548.         if ($this->SingleTo) {
  3549.             if ($this->Mailer != 'mail') {
  3550.                 foreach ($this->to as $toaddr) {
  3551.                     $this->SingleToArray[] = $this->addrFormat($toaddr);
  3552.                 }
  3553.             }
  3554.         } else {
  3555.             if (count($this->to) > 0) {
  3556.                 if ($this->Mailer != 'mail') {
  3557.                     $result .= $this->addrAppend('To', $this->to);
  3558.                 }
  3559.             } elseif (count($this->cc) == 0) {
  3560.                 $result .= $this->headerLine('To', 'undisclosed-recipients:;');
  3561.             }
  3562.         }
  3563.         $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  3564.         // sendmail and mail() extract Cc from the header before sending
  3565.         if (count($this->cc) > 0) {
  3566.             $result .= $this->addrAppend('Cc', $this->cc);
  3567.         }
  3568.         // sendmail and mail() extract Bcc from the header before sending
  3569.         if ((
  3570.                 $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
  3571.             )
  3572.             and count($this->bcc) > 0
  3573.         ) {
  3574.             $result .= $this->addrAppend('Bcc', $this->bcc);
  3575.         }
  3576.         if (count($this->ReplyTo) > 0) {
  3577.             $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  3578.         }
  3579.         // mail() sets the subject itself
  3580.         if ($this->Mailer != 'mail') {
  3581.             $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  3582.         }
  3583.         // Only allow a custom message ID if it conforms to RFC 5322 section 3.6.4
  3584.         // https://tools.ietf.org/html/rfc5322#section-3.6.4
  3585.         if ('' != $this->MessageID and preg_match('/^<.*@.*>$/', $this->MessageID)) {
  3586.             $this->lastMessageID = $this->MessageID;
  3587.         } else {
  3588.             //$this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->serverHostname());
  3589.             $this->lastMessageID = '<'.md5($this->uniqueid)."@".explode("@",$this->From)[1].'>';
  3590.         }
  3591.         $result .= $this->headerLine('Message-ID', $this->lastMessageID);
  3592.         if (!is_null($this->Priority)) {
  3593.             $result .= $this->headerLine('X-Priority', $this->Priority);
  3594.         }
  3595.         /* if ($this->XMailer == '') {
  3596.             $result .= $this->headerLine(
  3597.                 'X-Mailer',
  3598.                 //'PHPMailer ' . $this->Version . '(https://github.com/PHPMailer/PHPMailer)'
  3599.                 'PHPMailer ' . $this->uniqueid
  3600.             );
  3601.         } else {
  3602.             $myXmailer = trim($this->XMailer);
  3603.             if ($myXmailer) {
  3604.                 //$result .= $this->headerLine('X-Mailer', $myXmailer);
  3605.                 $result .= $this->headerLine('X-Mailer', $myXmailer.$this->uniqueid);
  3606.             }
  3607.         }*/
  3608.         if ($this->ConfirmReadingTo != '') {
  3609.             $result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>');
  3610.         }
  3611.         // Add custom headers
  3612.         foreach ($this->CustomHeader as $header) {
  3613.             $result .= $this->headerLine(
  3614.                 trim($header[0]),
  3615.                 $this->encodeHeader(trim($header[1]))
  3616.             );
  3617.         }
  3618.         if (!$this->sign_key_file) {
  3619.             $result .= $this->headerLine('MIME-Version', '1.0');
  3620.             $result .= $this->getMailMIME();
  3621.         }
  3622.         return $result;
  3623.     }
  3624.     /**
  3625.      * Get the message MIME type headers.
  3626.      * @access public
  3627.      * @return string
  3628.      */
  3629.     public function getMailMIME()
  3630.     {
  3631.         $result = '';
  3632.         $ismultipart = true;
  3633.         switch ($this->message_type) {
  3634.             case 'inline':
  3635.                 $result .= $this->headerLine('Content-Type', 'multipart/related;');
  3636.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  3637.                 break;
  3638.             case 'attach':
  3639.             case 'inline_attach':
  3640.             case 'alt_attach':
  3641.             case 'alt_inline_attach':
  3642.                 $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
  3643.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  3644.                 break;
  3645.             case 'alt':
  3646.             case 'alt_inline':
  3647.                 $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
  3648.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  3649.                 break;
  3650.             default:
  3651.                 // Catches case 'plain': and case '':
  3652.                 $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
  3653.                 $ismultipart = false;
  3654.                 break;
  3655.         }
  3656.         // RFC1341 part 5 says 7bit is assumed if not specified
  3657.         if ($this->Encoding != '7bit') {
  3658.             // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
  3659.             if ($ismultipart) {
  3660.                 if ($this->Encoding == '8bit') {
  3661.                     $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  3662.                 }
  3663.                 // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
  3664.             } else {
  3665.                 $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  3666.             }
  3667.         }
  3668.         if ($this->Mailer != 'mail') {
  3669.             $result .= $this->LE;
  3670.         }
  3671.         return $result;
  3672.     }
  3673.     /**
  3674.      * Returns the whole MIME message.
  3675.      * Includes complete headers and body.
  3676.      * Only valid post preSend().
  3677.      * @see PHPMailer::preSend()
  3678.      * @access public
  3679.      * @return string
  3680.      */
  3681.     public function getSentMIMEMessage()
  3682.     {
  3683.         return rtrim($this->MIMEHeader . $this->mailHeader, "\n\r") . self::CRLF . self::CRLF . $this->MIMEBody;
  3684.     }
  3685.     /**
  3686.      * Create unique ID
  3687.      * @return string
  3688.      */
  3689.     protected function generateId() {
  3690.         return md5(uniqid(time()));
  3691.     }
  3692.     /**
  3693.      * Assemble the message body.
  3694.      * Returns an empty string on failure.
  3695.      * @access public
  3696.      * @throws phpmailerException
  3697.      * @return string The assembled message body
  3698.      */
  3699.     public function createBody()
  3700.     {
  3701.         $body = '';
  3702.         //Create unique IDs and preset boundaries
  3703.         $this->uniqueid = $this->generateId();
  3704.         $this->boundary[1] = '1' . $this->uniqueid;
  3705.         $this->boundary[2] = '2' . $this->uniqueid;
  3706.         $this->boundary[3] = '3' . $this->uniqueid;
  3707.         if ($this->sign_key_file) {
  3708.             $body .= $this->getMailMIME() . $this->LE;
  3709.         }
  3710.         $this->setWordWrap();
  3711.         $bodyEncoding = $this->Encoding;
  3712.         $bodyCharSet = $this->CharSet;
  3713.         //Can we do a 7-bit downgrade?
  3714.         if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
  3715.             $bodyEncoding = '7bit';
  3716.             //All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit
  3717.             $bodyCharSet = 'us-ascii';
  3718.         }
  3719.         //If lines are too long, and we're not already using an encoding that will shorten them,
  3720.         //change to quoted-printable transfer encoding for the body part only
  3721.         if ('base64' != $this->Encoding and self::hasLineLongerThanMax($this->Body)) {
  3722.             $bodyEncoding = 'quoted-printable';
  3723.         }
  3724.         $altBodyEncoding = $this->Encoding;
  3725.         $altBodyCharSet = $this->CharSet;
  3726.         //Can we do a 7-bit downgrade?
  3727.         if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
  3728.             $altBodyEncoding = '7bit';
  3729.             //All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit
  3730.             $altBodyCharSet = 'us-ascii';
  3731.         }
  3732.         //If lines are too long, and we're not already using an encoding that will shorten them,
  3733.         //change to quoted-printable transfer encoding for the alt body part only
  3734.         if ('base64' != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) {
  3735.             $altBodyEncoding = 'quoted-printable';
  3736.         }
  3737.         //Use this as a preamble in all multipart message types
  3738.         $mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE;
  3739.         switch ($this->message_type) {
  3740.             case 'inline':
  3741.                 $body .= $mimepre;
  3742.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  3743.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  3744.                 $body .= $this->LE . $this->LE;
  3745.                 $body .= $this->attachAll('inline', $this->boundary[1]);
  3746.                 break;
  3747.             case 'attach':
  3748.                 $body .= $mimepre;
  3749.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  3750.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  3751.                 $body .= $this->LE . $this->LE;
  3752.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  3753.                 break;
  3754.             case 'inline_attach':
  3755.                 $body .= $mimepre;
  3756.                 $body .= $this->textLine('--' . $this->boundary[1]);
  3757.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  3758.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  3759.                 $body .= $this->LE;
  3760.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  3761.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  3762.                 $body .= $this->LE . $this->LE;
  3763.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  3764.                 $body .= $this->LE;
  3765.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  3766.                 break;
  3767.             case 'alt':
  3768.                 $body .= $mimepre;
  3769.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  3770.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  3771.                 $body .= $this->LE . $this->LE;
  3772.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  3773.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  3774.                 $body .= $this->LE . $this->LE;
  3775.                 if (!empty($this->Ical)) {
  3776.                     $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
  3777.                     $body .= $this->encodeString($this->Ical, $this->Encoding);
  3778.                     $body .= $this->LE . $this->LE;
  3779.                 }
  3780.                 $body .= $this->endBoundary($this->boundary[1]);
  3781.                 break;
  3782.             case 'alt_inline':
  3783.                 $body .= $mimepre;
  3784.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  3785.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  3786.                 $body .= $this->LE . $this->LE;
  3787.                 $body .= $this->textLine('--' . $this->boundary[1]);
  3788.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  3789.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  3790.                 $body .= $this->LE;
  3791.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  3792.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  3793.                 $body .= $this->LE . $this->LE;
  3794.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  3795.                 $body .= $this->LE;
  3796.                 $body .= $this->endBoundary($this->boundary[1]);
  3797.                 break;
  3798.             case 'alt_attach':
  3799.                 $body .= $mimepre;
  3800.                 $body .= $this->textLine('--' . $this->boundary[1]);
  3801.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  3802.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  3803.                 $body .= $this->LE;
  3804.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  3805.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  3806.                 $body .= $this->LE . $this->LE;
  3807.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  3808.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  3809.                 $body .= $this->LE . $this->LE;
  3810.                 $body .= $this->endBoundary($this->boundary[2]);
  3811.                 $body .= $this->LE;
  3812.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  3813.                 break;
  3814.             case 'alt_inline_attach':
  3815.                 $body .= $mimepre;
  3816.                 $body .= $this->textLine('--' . $this->boundary[1]);
  3817.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  3818.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  3819.                 $body .= $this->LE;
  3820.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  3821.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  3822.                 $body .= $this->LE . $this->LE;
  3823.                 $body .= $this->textLine('--' . $this->boundary[2]);
  3824.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  3825.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  3826.                 $body .= $this->LE;
  3827.                 $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  3828.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  3829.                 $body .= $this->LE . $this->LE;
  3830.                 $body .= $this->attachAll('inline', $this->boundary[3]);
  3831.                 $body .= $this->LE;
  3832.                 $body .= $this->endBoundary($this->boundary[2]);
  3833.                 $body .= $this->LE;
  3834.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  3835.                 break;
  3836.             default:
  3837.                 // Catch case 'plain' and case '', applies to simple `text/plain` and `text/html` body content types
  3838.                 //Reset the `Encoding` property in case we changed it for line length reasons
  3839.                 $this->Encoding = $bodyEncoding;
  3840.                 $body .= $this->encodeString($this->Body, $this->Encoding);
  3841.                 break;
  3842.         }
  3843.         if ($this->isError()) {
  3844.             $body = '';
  3845.         } elseif ($this->sign_key_file) {
  3846.             try {
  3847.                 if (!defined('PKCS7_TEXT')) {
  3848.                     throw new phpmailerException($this->lang('extension_missing') . 'openssl');
  3849.                 }
  3850.                 // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
  3851.                 $file = tempnam(sys_get_temp_dir(), 'mail');
  3852.                 if (false === file_put_contents($file, $body)) {
  3853.                     throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
  3854.                 }
  3855.                 $signed = tempnam(sys_get_temp_dir(), 'signed');
  3856.                 //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
  3857.                 if (empty($this->sign_extracerts_file)) {
  3858.                     $sign = @openssl_pkcs7_sign(
  3859.                         $file,
  3860.                         $signed,
  3861.                         'file://' . realpath($this->sign_cert_file),
  3862.                         array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  3863.                         null
  3864.                     );
  3865.                 } else {
  3866.                     $sign = @openssl_pkcs7_sign(
  3867.                         $file,
  3868.                         $signed,
  3869.                         'file://' . realpath($this->sign_cert_file),
  3870.                         array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  3871.                         null,
  3872.                         PKCS7_DETACHED,
  3873.                         $this->sign_extracerts_file
  3874.                     );
  3875.                 }
  3876.                 if ($sign) {
  3877.                     @unlink($file);
  3878.                     $body = file_get_contents($signed);
  3879.                     @unlink($signed);
  3880.                     //The message returned by openssl contains both headers and body, so need to split them up
  3881.                     $parts = explode("\n\n", $body, 2);
  3882.                     $this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
  3883.                     $body = $parts[1];
  3884.                 } else {
  3885.                     @unlink($file);
  3886.                     @unlink($signed);
  3887.                     throw new phpmailerException($this->lang('signing') . openssl_error_string());
  3888.                 }
  3889.             } catch (phpmailerException $exc) {
  3890.                 $body = '';
  3891.                 if ($this->exceptions) {
  3892.                     throw $exc;
  3893.                 }
  3894.             }
  3895.         }
  3896.         return $body;
  3897.     }
  3898.     /**
  3899.      * Return the start of a message boundary.
  3900.      * @access protected
  3901.      * @param string $boundary
  3902.      * @param string $charSet
  3903.      * @param string $contentType
  3904.      * @param string $encoding
  3905.      * @return string
  3906.      */
  3907.     protected function getBoundary($boundary, $charSet, $contentType, $encoding)
  3908.     {
  3909.         $result = '';
  3910.         if ($charSet == '') {
  3911.             $charSet = $this->CharSet;
  3912.         }
  3913.         if ($contentType == '') {
  3914.             $contentType = $this->ContentType;
  3915.         }
  3916.         if ($encoding == '') {
  3917.             $encoding = $this->Encoding;
  3918.         }
  3919.         $result .= $this->textLine('--' . $boundary);
  3920.         $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  3921.         $result .= $this->LE;
  3922.         // RFC1341 part 5 says 7bit is assumed if not specified
  3923.         if ($encoding != '7bit') {
  3924.             $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  3925.         }
  3926.         $result .= $this->LE;
  3927.         return $result;
  3928.     }
  3929.     /**
  3930.      * Return the end of a message boundary.
  3931.      * @access protected
  3932.      * @param string $boundary
  3933.      * @return string
  3934.      */
  3935.     protected function endBoundary($boundary)
  3936.     {
  3937.         return $this->LE . '--' . $boundary . '--' . $this->LE;
  3938.     }
  3939.     /**
  3940.      * Set the message type.
  3941.      * PHPMailer only supports some preset message types, not arbitrary MIME structures.
  3942.      * @access protected
  3943.      * @return void
  3944.      */
  3945.     protected function setMessageType()
  3946.     {
  3947.         $type = array();
  3948.         if ($this->alternativeExists()) {
  3949.             $type[] = 'alt';
  3950.         }
  3951.         if ($this->inlineImageExists()) {
  3952.             $type[] = 'inline';
  3953.         }
  3954.         if ($this->attachmentExists()) {
  3955.             $type[] = 'attach';
  3956.         }
  3957.         $this->message_type = implode('_', $type);
  3958.         if ($this->message_type == '') {
  3959.             //The 'plain' message_type refers to the message having a single body element, not that it is plain-text
  3960.             $this->message_type = 'plain';
  3961.         }
  3962.     }
  3963.     /**
  3964.      * Format a header line.
  3965.      * @access public
  3966.      * @param string $name
  3967.      * @param string $value
  3968.      * @return string
  3969.      */
  3970.     public function headerLine($name, $value)
  3971.     {
  3972.         return $name . ': ' . $value . $this->LE;
  3973.     }
  3974.     /**
  3975.      * Return a formatted mail line.
  3976.      * @access public
  3977.      * @param string $value
  3978.      * @return string
  3979.      */
  3980.     public function textLine($value)
  3981.     {
  3982.         return $value . $this->LE;
  3983.     }
  3984.     /**
  3985.      * Add an attachment from a path on the filesystem.
  3986.      * Returns false if the file could not be found or read.
  3987.      * @param string $path Path to the attachment.
  3988.      * @param string $name Overrides the attachment name.
  3989.      * @param string $encoding File encoding (see $Encoding).
  3990.      * @param string $type File extension (MIME) type.
  3991.      * @param string $disposition Disposition to use
  3992.      * @throws phpmailerException
  3993.      * @return boolean
  3994.      */
  3995.     public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  3996.     {
  3997.         try {
  3998.             if (!@is_file($path)) {
  3999.                 throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  4000.             }
  4001.             // If a MIME type is not specified, try to work it out from the file name
  4002.             if ($type == '') {
  4003.                 $type = self::filenameToType($path);
  4004.             }
  4005.             $filename = basename($path);
  4006.             if ($name == '') {
  4007.                 $name = $filename;
  4008.             }
  4009.             $this->attachment[] = array(
  4010.                 0 => $path,
  4011.                 1 => $filename,
  4012.                 2 => $name,
  4013.                 3 => $encoding,
  4014.                 4 => $type,
  4015.                 5 => false, // isStringAttachment
  4016.                 6 => $disposition,
  4017.                 7 => 0
  4018.             );
  4019.         } catch (phpmailerException $exc) {
  4020.             $this->setError($exc->getMessage());
  4021.             $this->edebug($exc->getMessage());
  4022.             if ($this->exceptions) {
  4023.                 throw $exc;
  4024.             }
  4025.             return false;
  4026.         }
  4027.         return true;
  4028.     }
  4029.     /**
  4030.      * Return the array of attachments.
  4031.      * @return array
  4032.      */
  4033.     public function getAttachments()
  4034.     {
  4035.         return $this->attachment;
  4036.     }
  4037.     /**
  4038.      * Attach all file, string, and binary attachments to the message.
  4039.      * Returns an empty string on failure.
  4040.      * @access protected
  4041.      * @param string $disposition_type
  4042.      * @param string $boundary
  4043.      * @return string
  4044.      */
  4045.     protected function attachAll($disposition_type, $boundary)
  4046.     {
  4047.         // Return text of body
  4048.         $mime = array();
  4049.         $cidUniq = array();
  4050.         $incl = array();
  4051.         // Add all attachments
  4052.         foreach ($this->attachment as $attachment) {
  4053.             // Check if it is a valid disposition_filter
  4054.             if ($attachment[6] == $disposition_type) {
  4055.                 // Check for string attachment
  4056.                 $string = '';
  4057.                 $path = '';
  4058.                 $bString = $attachment[5];
  4059.                 if ($bString) {
  4060.                     $string = $attachment[0];
  4061.                 } else {
  4062.                     $path = $attachment[0];
  4063.                 }
  4064.                 $inclhash = md5(serialize($attachment));
  4065.                 if (in_array($inclhash, $incl)) {
  4066.                     continue;
  4067.                 }
  4068.                 $incl[] = $inclhash;
  4069.                 $name = $attachment[2];
  4070.                 $encoding = $attachment[3];
  4071.                 $type = $attachment[4];
  4072.                 $disposition = $attachment[6];
  4073.                 $cid = $attachment[7];
  4074.                 if ($disposition == 'inline' && array_key_exists($cid, $cidUniq)) {
  4075.                     continue;
  4076.                 }
  4077.                 $cidUniq[$cid] = true;
  4078.                 $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  4079.                 //Only include a filename property if we have one
  4080.                 if (!empty($name)) {
  4081.                     $mime[] = sprintf(
  4082.                         'Content-Type: %s; name="%s"%s',
  4083.                         $type,
  4084.                         $this->encodeHeader($this->secureHeader($name)),
  4085.                         $this->LE
  4086.                     );
  4087.                 } else {
  4088.                     $mime[] = sprintf(
  4089.                         'Content-Type: %s%s',
  4090.                         $type,
  4091.                         $this->LE
  4092.                     );
  4093.                 }
  4094.                 // RFC1341 part 5 says 7bit is assumed if not specified
  4095.                 if ($encoding != '7bit') {
  4096.                     $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  4097.                 }
  4098.                 if ($disposition == 'inline') {
  4099.                     $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  4100.                 }
  4101.                 // If a filename contains any of these chars, it should be quoted,
  4102.                 // but not otherwise: RFC2183 & RFC2045 5.1
  4103.                 // Fixes a warning in IETF's msglint MIME checker
  4104.                 // Allow for bypassing the Content-Disposition header totally
  4105.                 if (!(empty($disposition))) {
  4106.                     $encoded_name = $this->encodeHeader($this->secureHeader($name));
  4107.                     if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
  4108.                         $mime[] = sprintf(
  4109.                             'Content-Disposition: %s; filename="%s"%s',
  4110.                             $disposition,
  4111.                             $encoded_name,
  4112.                             $this->LE . $this->LE
  4113.                         );
  4114.                     } else {
  4115.                         if (!empty($encoded_name)) {
  4116.                             $mime[] = sprintf(
  4117.                                 'Content-Disposition: %s; filename=%s%s',
  4118.                                 $disposition,
  4119.                                 $encoded_name,
  4120.                                 $this->LE . $this->LE
  4121.                             );
  4122.                         } else {
  4123.                             $mime[] = sprintf(
  4124.                                 'Content-Disposition: %s%s',
  4125.                                 $disposition,
  4126.                                 $this->LE . $this->LE
  4127.                             );
  4128.                         }
  4129.                     }
  4130.                 } else {
  4131.                     $mime[] = $this->LE;
  4132.                 }
  4133.                 // Encode as string attachment
  4134.                 if ($bString) {
  4135.                     $mime[] = $this->encodeString($string, $encoding);
  4136.                     if ($this->isError()) {
  4137.                         return '';
  4138.                     }
  4139.                     $mime[] = $this->LE . $this->LE;
  4140.                 } else {
  4141.                     $mime[] = $this->encodeFile($path, $encoding);
  4142.                     if ($this->isError()) {
  4143.                         return '';
  4144.                     }
  4145.                     $mime[] = $this->LE . $this->LE;
  4146.                 }
  4147.             }
  4148.         }
  4149.         $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  4150.         return implode('', $mime);
  4151.     }
  4152.     /**
  4153.      * Encode a file attachment in requested format.
  4154.      * Returns an empty string on failure.
  4155.      * @param string $path The full path to the file
  4156.      * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  4157.      * @throws phpmailerException
  4158.      * @access protected
  4159.      * @return string
  4160.      */
  4161.     protected function encodeFile($path, $encoding = 'base64')
  4162.     {
  4163.         try {
  4164.             if (!is_readable($path)) {
  4165.                 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  4166.             }
  4167.             $magic_quotes = get_magic_quotes_runtime();
  4168.             if ($magic_quotes) {
  4169.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  4170.                     set_magic_quotes_runtime(false);
  4171.                 } else {
  4172.                     //Doesn't exist in PHP 5.4, but we don't need to check because
  4173.                     //get_magic_quotes_runtime always returns false in 5.4+
  4174.                     //so it will never get here
  4175.                     ini_set('magic_quotes_runtime', false);
  4176.                 }
  4177.             }
  4178.             $file_buffer = file_get_contents($path);
  4179.             $file_buffer = $this->encodeString($file_buffer, $encoding);
  4180.             if ($magic_quotes) {
  4181.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  4182.                     set_magic_quotes_runtime($magic_quotes);
  4183.                 } else {
  4184.                     ini_set('magic_quotes_runtime', $magic_quotes);
  4185.                 }
  4186.             }
  4187.             return $file_buffer;
  4188.         } catch (Exception $exc) {
  4189.             $this->setError($exc->getMessage());
  4190.             return '';
  4191.         }
  4192.     }
  4193.     /**
  4194.      * Encode a string in requested format.
  4195.      * Returns an empty string on failure.
  4196.      * @param string $str The text to encode
  4197.      * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  4198.      * @access public
  4199.      * @return string
  4200.      */
  4201.     public function encodeString($str, $encoding = 'base64')
  4202.     {
  4203.         $encoded = '';
  4204.         switch (strtolower($encoding)) {
  4205.             case 'base64':
  4206.                 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  4207.                 break;
  4208.             case '7bit':
  4209.             case '8bit':
  4210.                 $encoded = $this->fixEOL($str);
  4211.                 // Make sure it ends with a line break
  4212.                 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  4213.                     $encoded .= $this->LE;
  4214.                 }
  4215.                 break;
  4216.             case 'binary':
  4217.                 $encoded = $str;
  4218.                 break;
  4219.             case 'quoted-printable':
  4220.                 $encoded = $this->encodeQP($str);
  4221.                 break;
  4222.             default:
  4223.                 $this->setError($this->lang('encoding') . $encoding);
  4224.                 break;
  4225.         }
  4226.         return $encoded;
  4227.     }
  4228.     /**
  4229.      * Encode a header string optimally.
  4230.      * Picks shortest of Q, B, quoted-printable or none.
  4231.      * @access public
  4232.      * @param string $str
  4233.      * @param string $position
  4234.      * @return string
  4235.      */
  4236.     public function encodeHeader($str, $position = 'text')
  4237.     {
  4238.         $matchcount = 0;
  4239.         switch (strtolower($position)) {
  4240.             case 'phrase':
  4241.                 if (!preg_match('/[\200-\377]/', $str)) {
  4242.                     // Can't use addslashes as we don't know the value of magic_quotes_sybase
  4243.                     $encoded = addcslashes($str, "\0..\37\177\\\"");
  4244.                     if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  4245.                         return ($encoded);
  4246.                     } else {
  4247.                         return ("\"$encoded\"");
  4248.                     }
  4249.                 }
  4250.                 $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  4251.                 break;
  4252.             /** @noinspection PhpMissingBreakStatementInspection */
  4253.             case 'comment':
  4254.                 $matchcount = preg_match_all('/[()"]/', $str, $matches);
  4255.                 // Intentional fall-through
  4256.             case 'text':
  4257.             default:
  4258.                 $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  4259.                 break;
  4260.         }
  4261.         //There are no chars that need encoding
  4262.         if ($matchcount == 0) {
  4263.             return ($str);
  4264.         }
  4265.         $maxlen = 75 - 7 - strlen($this->CharSet);
  4266.         // Try to select the encoding which should produce the shortest output
  4267.         if ($matchcount > strlen($str) / 3) {
  4268.             // More than a third of the content will need encoding, so B encoding will be most efficient
  4269.             $encoding = 'B';
  4270.             if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
  4271.                 // Use a custom function which correctly encodes and wraps long
  4272.                 // multibyte strings without breaking lines within a character
  4273.                 $encoded = $this->base64EncodeWrapMB($str, "\n");
  4274.             } else {
  4275.                 $encoded = base64_encode($str);
  4276.                 $maxlen -= $maxlen % 4;
  4277.                 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  4278.             }
  4279.         } else {
  4280.             $encoding = 'Q';
  4281.             $encoded = $this->encodeQ($str, $position);
  4282.             $encoded = $this->wrapText($encoded, $maxlen, true);
  4283.             $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  4284.         }
  4285.         $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  4286.         $encoded = trim(str_replace("\n", $this->LE, $encoded));
  4287.         return $encoded;
  4288.     }
  4289.     /**
  4290.      * Check if a string contains multi-byte characters.
  4291.      * @access public
  4292.      * @param string $str multi-byte text to wrap encode
  4293.      * @return boolean
  4294.      */
  4295.     public function hasMultiBytes($str)
  4296.     {
  4297.         if (function_exists('mb_strlen')) {
  4298.             return (strlen($str) > mb_strlen($str, $this->CharSet));
  4299.         } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  4300.             return false;
  4301.         }
  4302.     }
  4303.     /**
  4304.      * Does a string contain any 8-bit chars (in any charset)?
  4305.      * @param string $text
  4306.      * @return boolean
  4307.      */
  4308.     public function has8bitChars($text)
  4309.     {
  4310.         return (boolean)preg_match('/[\x80-\xFF]/', $text);
  4311.     }
  4312.     /**
  4313.      * Encode and wrap long multibyte strings for mail headers
  4314.      * without breaking lines within a character.
  4315.      * Adapted from a function by paravoid
  4316.      * @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
  4317.      * @access public
  4318.      * @param string $str multi-byte text to wrap encode
  4319.      * @param string $linebreak string to use as linefeed/end-of-line
  4320.      * @return string
  4321.      */
  4322.     public function base64EncodeWrapMB($str, $linebreak = null)
  4323.     {
  4324.         $start = '=?' . $this->CharSet . '?B?';
  4325.         $end = '?=';
  4326.         $encoded = '';
  4327.         if ($linebreak === null) {
  4328.             $linebreak = $this->LE;
  4329.         }
  4330.         $mb_length = mb_strlen($str, $this->CharSet);
  4331.         // Each line must have length <= 75, including $start and $end
  4332.         $length = 75 - strlen($start) - strlen($end);
  4333.         // Average multi-byte ratio
  4334.         $ratio = $mb_length / strlen($str);
  4335.         // Base64 has a 4:3 ratio
  4336.         $avgLength = floor($length * $ratio * .75);
  4337.         for ($i = 0; $i < $mb_length; $i += $offset) {
  4338.             $lookBack = 0;
  4339.             do {
  4340.                 $offset = $avgLength - $lookBack;
  4341.                 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  4342.                 $chunk = base64_encode($chunk);
  4343.                 $lookBack++;
  4344.             } while (strlen($chunk) > $length);
  4345.             $encoded .= $chunk . $linebreak;
  4346.         }
  4347.         // Chomp the last linefeed
  4348.         $encoded = substr($encoded, 0, -strlen($linebreak));
  4349.         return $encoded;
  4350.     }
  4351.     /**
  4352.      * Encode a string in quoted-printable format.
  4353.      * According to RFC2045 section 6.7.
  4354.      * @access public
  4355.      * @param string $string The text to encode
  4356.      * @param integer $line_max Number of chars allowed on a line before wrapping
  4357.      * @return string
  4358.      * @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment
  4359.      */
  4360.     public function encodeQP($string, $line_max = 76)
  4361.     {
  4362.         // Use native function if it's available (>= PHP5.3)
  4363.         if (function_exists('quoted_printable_encode')) {
  4364.             return quoted_printable_encode($string);
  4365.         }
  4366.         // Fall back to a pure PHP implementation
  4367.         $string = str_replace(
  4368.             array('%20', '%0D%0A.', '%0D%0A', '%'),
  4369.             array(' ', "\r\n=2E", "\r\n", '='),
  4370.             rawurlencode($string)
  4371.         );
  4372.         return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  4373.     }
  4374.     /**
  4375.      * Backward compatibility wrapper for an old QP encoding function that was removed.
  4376.      * @see PHPMailer::encodeQP()
  4377.      * @access public
  4378.      * @param string $string
  4379.      * @param integer $line_max
  4380.      * @param boolean $space_conv
  4381.      * @return string
  4382.      * @deprecated Use encodeQP instead.
  4383.      */
  4384.     public function encodeQPphp(
  4385.         $string,
  4386.         $line_max = 76,
  4387.         /** @noinspection PhpUnusedParameterInspection */ $space_conv = false
  4388.     ) {
  4389.         return $this->encodeQP($string, $line_max);
  4390.     }
  4391.     /**
  4392.      * Encode a string using Q encoding.
  4393.      * @link http://tools.ietf.org/html/rfc2047
  4394.      * @param string $str the text to encode
  4395.      * @param string $position Where the text is going to be used, see the RFC for what that means
  4396.      * @access public
  4397.      * @return string
  4398.      */
  4399.     public function encodeQ($str, $position = 'text')
  4400.     {
  4401.         // There should not be any EOL in the string
  4402.         $pattern = '';
  4403.         $encoded = str_replace(array("\r", "\n"), '', $str);
  4404.         switch (strtolower($position)) {
  4405.             case 'phrase':
  4406.                 // RFC 2047 section 5.3
  4407.                 $pattern = '^A-Za-z0-9!*+\/ -';
  4408.                 break;
  4409.             /** @noinspection PhpMissingBreakStatementInspection */
  4410.             case 'comment':
  4411.                 // RFC 2047 section 5.2
  4412.                 $pattern = '\(\)"';
  4413.                 // intentional fall-through
  4414.                 // for this reason we build the $pattern without including delimiters and []
  4415.             case 'text':
  4416.             default:
  4417.                 // RFC 2047 section 5.1
  4418.                 // Replace every high ascii, control, =, ? and _ characters
  4419.                 $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  4420.                 break;
  4421.         }
  4422.         $matches = array();
  4423.         if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  4424.             // If the string contains an '=', make sure it's the first thing we replace
  4425.             // so as to avoid double-encoding
  4426.             $eqkey = array_search('=', $matches[0]);
  4427.             if (false !== $eqkey) {
  4428.                 unset($matches[0][$eqkey]);
  4429.                 array_unshift($matches[0], '=');
  4430.             }
  4431.             foreach (array_unique($matches[0]) as $char) {
  4432.                 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  4433.             }
  4434.         }
  4435.         // Replace every spaces to _ (more readable than =20)
  4436.         return str_replace(' ', '_', $encoded);
  4437.     }
  4438.     /**
  4439.      * Add a string or binary attachment (non-filesystem).
  4440.      * This method can be used to attach ascii or binary data,
  4441.      * such as a BLOB record from a database.
  4442.      * @param string $string String attachment data.
  4443.      * @param string $filename Name of the attachment.
  4444.      * @param string $encoding File encoding (see $Encoding).
  4445.      * @param string $type File extension (MIME) type.
  4446.      * @param string $disposition Disposition to use
  4447.      * @return void
  4448.      */
  4449.     public function addStringAttachment(
  4450.         $string,
  4451.         $filename,
  4452.         $encoding = 'base64',
  4453.         $type = '',
  4454.         $disposition = 'attachment'
  4455.     ) {
  4456.         // If a MIME type is not specified, try to work it out from the file name
  4457.         if ($type == '') {
  4458.             $type = self::filenameToType($filename);
  4459.         }
  4460.         // Append to $attachment array
  4461.         $this->attachment[] = array(
  4462.             0 => $string,
  4463.             1 => $filename,
  4464.             2 => basename($filename),
  4465.             3 => $encoding,
  4466.             4 => $type,
  4467.             5 => true, // isStringAttachment
  4468.             6 => $disposition,
  4469.             7 => 0
  4470.         );
  4471.     }
  4472.     /**
  4473.      * Add an embedded (inline) attachment from a file.
  4474.      * This can include images, sounds, and just about any other document type.
  4475.      * These differ from 'regular' attachments in that they are intended to be
  4476.      * displayed inline with the message, not just attached for download.
  4477.      * This is used in HTML messages that embed the images
  4478.      * the HTML refers to using the $cid value.
  4479.      * @param string $path Path to the attachment.
  4480.      * @param string $cid Content ID of the attachment; Use this to reference
  4481.      *        the content when using an embedded image in HTML.
  4482.      * @param string $name Overrides the attachment name.
  4483.      * @param string $encoding File encoding (see $Encoding).
  4484.      * @param string $type File MIME type.
  4485.      * @param string $disposition Disposition to use
  4486.      * @return boolean True on successfully adding an attachment
  4487.      */
  4488.     public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  4489.     {
  4490.         if (!@is_file($path)) {
  4491.             $this->setError($this->lang('file_access') . $path);
  4492.             return false;
  4493.         }
  4494.         // If a MIME type is not specified, try to work it out from the file name
  4495.         if ($type == '') {
  4496.             $type = self::filenameToType($path);
  4497.         }
  4498.         $filename = basename($path);
  4499.         if ($name == '') {
  4500.             $name = $filename;
  4501.         }
  4502.         // Append to $attachment array
  4503.         $this->attachment[] = array(
  4504.             0 => $path,
  4505.             1 => $filename,
  4506.             2 => $name,
  4507.             3 => $encoding,
  4508.             4 => $type,
  4509.             5 => false, // isStringAttachment
  4510.             6 => $disposition,
  4511.             7 => $cid
  4512.         );
  4513.         return true;
  4514.     }
  4515.     /**
  4516.      * Add an embedded stringified attachment.
  4517.      * This can include images, sounds, and just about any other document type.
  4518.      * Be sure to set the $type to an image type for images:
  4519.      * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.
  4520.      * @param string $string The attachment binary data.
  4521.      * @param string $cid Content ID of the attachment; Use this to reference
  4522.      *        the content when using an embedded image in HTML.
  4523.      * @param string $name
  4524.      * @param string $encoding File encoding (see $Encoding).
  4525.      * @param string $type MIME type.
  4526.      * @param string $disposition Disposition to use
  4527.      * @return boolean True on successfully adding an attachment
  4528.      */
  4529.     public function addStringEmbeddedImage(
  4530.         $string,
  4531.         $cid,
  4532.         $name = '',
  4533.         $encoding = 'base64',
  4534.         $type = '',
  4535.         $disposition = 'inline'
  4536.     ) {
  4537.         // If a MIME type is not specified, try to work it out from the name
  4538.         if ($type == '' and !empty($name)) {
  4539.             $type = self::filenameToType($name);
  4540.         }
  4541.         // Append to $attachment array
  4542.         $this->attachment[] = array(
  4543.             0 => $string,
  4544.             1 => $name,
  4545.             2 => $name,
  4546.             3 => $encoding,
  4547.             4 => $type,
  4548.             5 => true, // isStringAttachment
  4549.             6 => $disposition,
  4550.             7 => $cid
  4551.         );
  4552.         return true;
  4553.     }
  4554.     /**
  4555.      * Check if an inline attachment is present.
  4556.      * @access public
  4557.      * @return boolean
  4558.      */
  4559.     public function inlineImageExists()
  4560.     {
  4561.         foreach ($this->attachment as $attachment) {
  4562.             if ($attachment[6] == 'inline') {
  4563.                 return true;
  4564.             }
  4565.         }
  4566.         return false;
  4567.     }
  4568.     /**
  4569.      * Check if an attachment (non-inline) is present.
  4570.      * @return boolean
  4571.      */
  4572.     public function attachmentExists()
  4573.     {
  4574.         foreach ($this->attachment as $attachment) {
  4575.             if ($attachment[6] == 'attachment') {
  4576.                 return true;
  4577.             }
  4578.         }
  4579.         return false;
  4580.     }
  4581.     /**
  4582.      * Check if this message has an alternative body set.
  4583.      * @return boolean
  4584.      */
  4585.     public function alternativeExists()
  4586.     {
  4587.         return !empty($this->AltBody);
  4588.     }
  4589.     /**
  4590.      * Clear queued addresses of given kind.
  4591.      * @access protected
  4592.      * @param string $kind 'to', 'cc', or 'bcc'
  4593.      * @return void
  4594.      */
  4595.     public function clearQueuedAddresses($kind)
  4596.     {
  4597.         $RecipientsQueue = $this->RecipientsQueue;
  4598.         foreach ($RecipientsQueue as $address => $params) {
  4599.             if ($params[0] == $kind) {
  4600.                 unset($this->RecipientsQueue[$address]);
  4601.             }
  4602.         }
  4603.     }
  4604.     /**
  4605.      * Clear all To recipients.
  4606.      * @return void
  4607.      */
  4608.     public function clearAddresses()
  4609.     {
  4610.         foreach ($this->to as $to) {
  4611.             unset($this->all_recipients[strtolower($to[0])]);
  4612.         }
  4613.         $this->to = array();
  4614.         $this->clearQueuedAddresses('to');
  4615.     }
  4616.     /**
  4617.      * Clear all CC recipients.
  4618.      * @return void
  4619.      */
  4620.     public function clearCCs()
  4621.     {
  4622.         foreach ($this->cc as $cc) {
  4623.             unset($this->all_recipients[strtolower($cc[0])]);
  4624.         }
  4625.         $this->cc = array();
  4626.         $this->clearQueuedAddresses('cc');
  4627.     }
  4628.     /**
  4629.      * Clear all BCC recipients.
  4630.      * @return void
  4631.      */
  4632.     public function clearBCCs()
  4633.     {
  4634.         foreach ($this->bcc as $bcc) {
  4635.             unset($this->all_recipients[strtolower($bcc[0])]);
  4636.         }
  4637.         $this->bcc = array();
  4638.         $this->clearQueuedAddresses('bcc');
  4639.     }
  4640.     /**
  4641.      * Clear all ReplyTo recipients.
  4642.      * @return void
  4643.      */
  4644.     public function clearReplyTos()
  4645.     {
  4646.         $this->ReplyTo = array();
  4647.         $this->ReplyToQueue = array();
  4648.     }
  4649.     /**
  4650.      * Clear all recipient types.
  4651.      * @return void
  4652.      */
  4653.     public function clearAllRecipients()
  4654.     {
  4655.         $this->to = array();
  4656.         $this->cc = array();
  4657.         $this->bcc = array();
  4658.         $this->all_recipients = array();
  4659.         $this->RecipientsQueue = array();
  4660.     }
  4661.     /**
  4662.      * Clear all filesystem, string, and binary attachments.
  4663.      * @return void
  4664.      */
  4665.     public function clearAttachments()
  4666.     {
  4667.         $this->attachment = array();
  4668.     }
  4669.     /**
  4670.      * Clear all custom headers.
  4671.      * @return void
  4672.      */
  4673.     public function clearCustomHeaders()
  4674.     {
  4675.         $this->CustomHeader = array();
  4676.     }
  4677.     /**
  4678.      * Add an error message to the error container.
  4679.      * @access protected
  4680.      * @param string $msg
  4681.      * @return void
  4682.      */
  4683.     protected function setError($msg)
  4684.     {
  4685.         $this->error_count++;
  4686.         if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  4687.             $lasterror = $this->smtp->getError();
  4688.             if (!empty($lasterror['error'])) {
  4689.                 $msg .= $this->lang('smtp_error') . $lasterror['error'];
  4690.                 if (!empty($lasterror['detail'])) {
  4691.                     $msg .= ' Detail: '. $lasterror['detail'];
  4692.                 }
  4693.                 if (!empty($lasterror['smtp_code'])) {
  4694.                     $msg .= ' SMTP code: ' . $lasterror['smtp_code'];
  4695.                 }
  4696.                 if (!empty($lasterror['smtp_code_ex'])) {
  4697.                     $msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex'];
  4698.                 }
  4699.             }
  4700.         }
  4701.         $this->ErrorInfo = $msg;
  4702.     }
  4703.     /**
  4704.      * Return an RFC 822 formatted date.
  4705.      * @access public
  4706.      * @return string
  4707.      * @static
  4708.      */
  4709.     public static function rfcDate()
  4710.     {
  4711.         // Set the time zone to whatever the default is to avoid 500 errors
  4712.         // Will default to UTC if it's not set properly in php.ini
  4713.         date_default_timezone_set(@date_default_timezone_get());
  4714.         return date('D, j M Y H:i:s O');
  4715.     }
  4716.     /**
  4717.      * Get the server hostname.
  4718.      * Returns 'localhost.localdomain' if unknown.
  4719.      * @access protected
  4720.      * @return string
  4721.      */
  4722.     protected function serverHostname()
  4723.     {
  4724.         $result = 'localhost.localdomain';
  4725.         if (!empty($this->Hostname)) {
  4726.             $result = $this->Hostname;
  4727.         } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
  4728.             $result = $_SERVER['SERVER_NAME'];
  4729.         } elseif (function_exists('gethostname') && gethostname() !== false) {
  4730.             $result = gethostname();
  4731.         } elseif (php_uname('n') !== false) {
  4732.             $result = php_uname('n');
  4733.         }
  4734.         return $result;
  4735.     }
  4736.     /**
  4737.      * Get an error message in the current language.
  4738.      * @access protected
  4739.      * @param string $key
  4740.      * @return string
  4741.      */
  4742.     protected function lang($key)
  4743.     {
  4744.         if (count($this->language) < 1) {
  4745.             $this->setLanguage('en'); // set the default language
  4746.         }
  4747.         if (array_key_exists($key, $this->language)) {
  4748.             if ($key == 'smtp_connect_failed') {
  4749.                 //Include a link to troubleshooting docs on SMTP connection failure
  4750.                 //this is by far the biggest cause of support questions
  4751.                 //but it's usually not PHPMailer's fault.
  4752.                 return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
  4753.             }
  4754.             return $this->language[$key];
  4755.         } else {
  4756.             //Return the key as a fallback
  4757.             return $key;
  4758.         }
  4759.     }
  4760.     /**
  4761.      * Check if an error occurred.
  4762.      * @access public
  4763.      * @return boolean True if an error did occur.
  4764.      */
  4765.     public function isError()
  4766.     {
  4767.         return ($this->error_count > 0);
  4768.     }
  4769.     /**
  4770.      * Ensure consistent line endings in a string.
  4771.      * Changes every end of line from CRLF, CR or LF to $this->LE.
  4772.      * @access public
  4773.      * @param string $str String to fixEOL
  4774.      * @return string
  4775.      */
  4776.     public function fixEOL($str)
  4777.     {
  4778.         // Normalise to \n
  4779.         $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  4780.         // Now convert LE as needed
  4781.         if ($this->LE !== "\n") {
  4782.             $nstr = str_replace("\n", $this->LE, $nstr);
  4783.         }
  4784.         return $nstr;
  4785.     }
  4786.     /**
  4787.      * Add a custom header.
  4788.      * $name value can be overloaded to contain
  4789.      * both header name and value (name:value)
  4790.      * @access public
  4791.      * @param string $name Custom header name
  4792.      * @param string $value Header value
  4793.      * @return void
  4794.      */
  4795.     public function addCustomHeader($name, $value = null,$overwrite = false)
  4796.     {
  4797.         if ($value === null)
  4798.         {
  4799.             $header = explode(':', $name, 2);
  4800.             $name = $header[0];
  4801.         }
  4802.         if ($overwrite)
  4803.         {
  4804.             $this->CustomHeader[$name] = isset($header) ? $header : array($name, $value);
  4805.         }
  4806.         else
  4807.         {
  4808.             $this->CustomHeader[] = isset($header) ? $header : array($name, $value);
  4809.         }
  4810.     }
  4811.     /**
  4812.      * Returns all custom headers.
  4813.      * @return array
  4814.      */
  4815.     public function getCustomHeaders()
  4816.     {
  4817.         return array_values($this->CustomHeader);
  4818.     }
  4819.     /**
  4820.      * Create a message body from an HTML string.
  4821.      * Automatically inlines images and creates a plain-text version by converting the HTML,
  4822.      * overwriting any existing values in Body and AltBody.
  4823.      * $basedir is used when handling relative image paths, e.g. <img src="images/a.png">
  4824.      * will look for an image file in $basedir/images/a.png and convert it to inline.
  4825.      * If you don't want to apply these transformations to your HTML, just set Body and AltBody yourself.
  4826.      * @access public
  4827.      * @param string $message HTML message string
  4828.      * @param string $basedir base directory for relative paths to images
  4829.      * @param boolean|callable $advanced Whether to use the internal HTML to text converter
  4830.      *    or your own custom converter @see PHPMailer::html2text()
  4831.      * @return string $message The transformed message Body
  4832.      */
  4833.     public function msgHTML($message, $basedir = '', $advanced = false)
  4834.     {
  4835.         preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  4836.         if (array_key_exists(2, $images)) {
  4837.             foreach ($images[2] as $imgindex => $url) {
  4838.                 // Convert data URIs into embedded images
  4839.                 if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
  4840.                     $data = substr($url, strpos($url, ','));
  4841.                     if ($match[2]) {
  4842.                         $data = base64_decode($data);
  4843.                     } else {
  4844.                         $data = rawurldecode($data);
  4845.                     }
  4846.                     $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  4847.                     if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) {
  4848.                         $message = str_replace(
  4849.                             $images[0][$imgindex],
  4850.                             $images[1][$imgindex] . '="cid:' . $cid . '"',
  4851.                             $message
  4852.                         );
  4853.                     }
  4854.                 } elseif (substr($url, 0, 4) !== 'cid:' && !preg_match('#^[a-z][a-z0-9+.-]*://#i', $url)) {
  4855.                     // Do not change urls for absolute images (thanks to corvuscorax)
  4856.                     // Do not change urls that are already inline images
  4857.                     $filename = basename($url);
  4858.                     $directory = dirname($url);
  4859.                     if ($directory == '.') {
  4860.                         $directory = '';
  4861.                     }
  4862.                     $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  4863.                     if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
  4864.                         $basedir .= '/';
  4865.                     }
  4866.                     if (strlen($directory) > 1 && substr($directory, -1) != '/') {
  4867.                         $directory .= '/';
  4868.                     }
  4869.                     if ($this->addEmbeddedImage(
  4870.                         $basedir . $directory . $filename,
  4871.                         $cid,
  4872.                         $filename,
  4873.                         'base64',
  4874.                         self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
  4875.                     )
  4876.                     ) {
  4877.                         $message = preg_replace(
  4878.                             '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
  4879.                             $images[1][$imgindex] . '="cid:' . $cid . '"',
  4880.                             $message
  4881.                         );
  4882.                     }
  4883.                 }
  4884.             }
  4885.         }
  4886.         $this->isHTML(true);
  4887.         // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
  4888.         $this->Body = $this->normalizeBreaks($message);
  4889.         $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  4890.         if (!$this->alternativeExists()) {
  4891.             $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
  4892.                 self::CRLF . self::CRLF;
  4893.         }
  4894.         return $this->Body;
  4895.     }
  4896.     /**
  4897.      * Convert an HTML string into plain text.
  4898.      * This is used by msgHTML().
  4899.      * Note - older versions of this function used a bundled advanced converter
  4900.      * which was been removed for license reasons in #232.
  4901.      * Example usage:
  4902.      * <code>
  4903.      * // Use default conversion
  4904.      * $plain = $mail->html2text($html);
  4905.      * // Use your own custom converter
  4906.      * $plain = $mail->html2text($html, function($html) {
  4907.      *     $converter = new MyHtml2text($html);
  4908.      *     return $converter->get_text();
  4909.      * });
  4910.      * </code>
  4911.      * @param string $html The HTML text to convert
  4912.      * @param boolean|callable $advanced Any boolean value to use the internal converter,
  4913.      *   or provide your own callable for custom conversion.
  4914.      * @return string
  4915.      */
  4916.     public function html2text($html, $advanced = false)
  4917.     {
  4918.         if (is_callable($advanced)) {
  4919.             return call_user_func($advanced, $html);
  4920.         }
  4921.         return html_entity_decode(
  4922.             trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
  4923.             ENT_QUOTES,
  4924.             $this->CharSet
  4925.         );
  4926.     }
  4927.     /**
  4928.      * Get the MIME type for a file extension.
  4929.      * @param string $ext File extension
  4930.      * @access public
  4931.      * @return string MIME type of file.
  4932.      * @static
  4933.      */
  4934.     public static function _mime_types($ext = '')
  4935.     {
  4936.         $mimes = array(
  4937.             'xl'    => 'application/excel',
  4938.             'js'    => 'application/javascript',
  4939.             'hqx'   => 'application/mac-binhex40',
  4940.             'cpt'   => 'application/mac-compactpro',
  4941.             'bin'   => 'application/macbinary',
  4942.             'doc'   => 'application/msword',
  4943.             'word'  => 'application/msword',
  4944.             'xlsx'  => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  4945.             'xltx'  => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  4946.             'potx'  => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  4947.             'ppsx'  => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  4948.             'pptx'  => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  4949.             'sldx'  => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  4950.             'docx'  => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  4951.             'dotx'  => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  4952.             'xlam'  => 'application/vnd.ms-excel.addin.macroEnabled.12',
  4953.             'xlsb'  => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
  4954.             'class' => 'application/octet-stream',
  4955.             'dll'   => 'application/octet-stream',
  4956.             'dms'   => 'application/octet-stream',
  4957.             'exe'   => 'application/octet-stream',
  4958.             'lha'   => 'application/octet-stream',
  4959.             'lzh'   => 'application/octet-stream',
  4960.             'psd'   => 'application/octet-stream',
  4961.             'sea'   => 'application/octet-stream',
  4962.             'so'    => 'application/octet-stream',
  4963.             'oda'   => 'application/oda',
  4964.             'pdf'   => 'application/pdf',
  4965.             'ai'    => 'application/postscript',
  4966.             'eps'   => 'application/postscript',
  4967.             'ps'    => 'application/postscript',
  4968.             'smi'   => 'application/smil',
  4969.             'smil'  => 'application/smil',
  4970.             'mif'   => 'application/vnd.mif',
  4971.             'xls'   => 'application/vnd.ms-excel',
  4972.             'ppt'   => 'application/vnd.ms-powerpoint',
  4973.             'wbxml' => 'application/vnd.wap.wbxml',
  4974.             'wmlc'  => 'application/vnd.wap.wmlc',
  4975.             'dcr'   => 'application/x-director',
  4976.             'dir'   => 'application/x-director',
  4977.             'dxr'   => 'application/x-director',
  4978.             'dvi'   => 'application/x-dvi',
  4979.             'gtar'  => 'application/x-gtar',
  4980.             'php3'  => 'application/x-httpd-php',
  4981.             'php4'  => 'application/x-httpd-php',
  4982.             'php'   => 'application/x-httpd-php',
  4983.             'phtml' => 'application/x-httpd-php',
  4984.             'phps'  => 'application/x-httpd-php-source',
  4985.             'swf'   => 'application/x-shockwave-flash',
  4986.             'sit'   => 'application/x-stuffit',
  4987.             'tar'   => 'application/x-tar',
  4988.             'tgz'   => 'application/x-tar',
  4989.             'xht'   => 'application/xhtml+xml',
  4990.             'xhtml' => 'application/xhtml+xml',
  4991.             'zip'   => 'application/zip',
  4992.             'mid'   => 'audio/midi',
  4993.             'midi'  => 'audio/midi',
  4994.             'mp2'   => 'audio/mpeg',
  4995.             'mp3'   => 'audio/mpeg',
  4996.             'mpga'  => 'audio/mpeg',
  4997.             'aif'   => 'audio/x-aiff',
  4998.             'aifc'  => 'audio/x-aiff',
  4999.             'aiff'  => 'audio/x-aiff',
  5000.             'ram'   => 'audio/x-pn-realaudio',
  5001.             'rm'    => 'audio/x-pn-realaudio',
  5002.             'rpm'   => 'audio/x-pn-realaudio-plugin',
  5003.             'ra'    => 'audio/x-realaudio',
  5004.             'wav'   => 'audio/x-wav',
  5005.             'bmp'   => 'image/bmp',
  5006.             'gif'   => 'image/gif',
  5007.             'jpeg'  => 'image/jpeg',
  5008.             'jpe'   => 'image/jpeg',
  5009.             'jpg'   => 'image/jpeg',
  5010.             'png'   => 'image/png',
  5011.             'tiff'  => 'image/tiff',
  5012.             'tif'   => 'image/tiff',
  5013.             'eml'   => 'message/rfc822',
  5014.             'css'   => 'text/css',
  5015.             'html'  => 'text/html',
  5016.             'htm'   => 'text/html',
  5017.             'shtml' => 'text/html',
  5018.             'log'   => 'text/plain',
  5019.             'text'  => 'text/plain',
  5020.             'txt'   => 'text/plain',
  5021.             'rtx'   => 'text/richtext',
  5022.             'rtf'   => 'text/rtf',
  5023.             'vcf'   => 'text/vcard',
  5024.             'vcard' => 'text/vcard',
  5025.             'xml'   => 'text/xml',
  5026.             'xsl'   => 'text/xml',
  5027.             'mpeg'  => 'video/mpeg',
  5028.             'mpe'   => 'video/mpeg',
  5029.             'mpg'   => 'video/mpeg',
  5030.             'mov'   => 'video/quicktime',
  5031.             'qt'    => 'video/quicktime',
  5032.             'rv'    => 'video/vnd.rn-realvideo',
  5033.             'avi'   => 'video/x-msvideo',
  5034.             'movie' => 'video/x-sgi-movie'
  5035.         );
  5036.         if (array_key_exists(strtolower($ext), $mimes)) {
  5037.             return $mimes[strtolower($ext)];
  5038.         }
  5039.         return 'application/octet-stream';
  5040.     }
  5041.     /**
  5042.      * Map a file name to a MIME type.
  5043.      * Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
  5044.      * @param string $filename A file name or full path, does not need to exist as a file
  5045.      * @return string
  5046.      * @static
  5047.      */
  5048.     public static function filenameToType($filename)
  5049.     {
  5050.         // In case the path is a URL, strip any query string before getting extension
  5051.         $qpos = strpos($filename, '?');
  5052.         if (false !== $qpos) {
  5053.             $filename = substr($filename, 0, $qpos);
  5054.         }
  5055.         $pathinfo = self::mb_pathinfo($filename);
  5056.         return self::_mime_types($pathinfo['extension']);
  5057.     }
  5058.     /**
  5059.      * Multi-byte-safe pathinfo replacement.
  5060.      * Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe.
  5061.      * Works similarly to the one in PHP >= 5.2.0
  5062.      * @link http://www.php.net/manual/en/function.pathinfo.php#107461
  5063.      * @param string $path A filename or path, does not need to exist as a file
  5064.      * @param integer|string $options Either a PATHINFO_* constant,
  5065.      *      or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
  5066.      * @return string|array
  5067.      * @static
  5068.      */
  5069.     public static function mb_pathinfo($path, $options = null)
  5070.     {
  5071.         $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  5072.         $pathinfo = array();
  5073.         if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
  5074.             if (array_key_exists(1, $pathinfo)) {
  5075.                 $ret['dirname'] = $pathinfo[1];
  5076.             }
  5077.             if (array_key_exists(2, $pathinfo)) {
  5078.                 $ret['basename'] = $pathinfo[2];
  5079.             }
  5080.             if (array_key_exists(5, $pathinfo)) {
  5081.                 $ret['extension'] = $pathinfo[5];
  5082.             }
  5083.             if (array_key_exists(3, $pathinfo)) {
  5084.                 $ret['filename'] = $pathinfo[3];
  5085.             }
  5086.         }
  5087.         switch ($options) {
  5088.             case PATHINFO_DIRNAME:
  5089.             case 'dirname':
  5090.                 return $ret['dirname'];
  5091.             case PATHINFO_BASENAME:
  5092.             case 'basename':
  5093.                 return $ret['basename'];
  5094.             case PATHINFO_EXTENSION:
  5095.             case 'extension':
  5096.                 return $ret['extension'];
  5097.             case PATHINFO_FILENAME:
  5098.             case 'filename':
  5099.                 return $ret['filename'];
  5100.             default:
  5101.                 return $ret;
  5102.         }
  5103.     }
  5104.     /**
  5105.      * Set or reset instance properties.
  5106.      * You should avoid this function - it's more verbose, less efficient, more error-prone and
  5107.      * harder to debug than setting properties directly.
  5108.      * Usage Example:
  5109.      * `$mail->set('SMTPSecure', 'tls');`
  5110.      *   is the same as:
  5111.      * `$mail->SMTPSecure = 'tls';`
  5112.      * @access public
  5113.      * @param string $name The property name to set
  5114.      * @param mixed $value The value to set the property to
  5115.      * @return boolean
  5116.      * @TODO Should this not be using the __set() magic function?
  5117.      */
  5118.     public function set($name, $value = '')
  5119.     {
  5120.         if (property_exists($this, $name)) {
  5121.             $this->$name = $value;
  5122.             return true;
  5123.         } else {
  5124.             $this->setError($this->lang('variable_set') . $name);
  5125.             return false;
  5126.         }
  5127.     }
  5128.     /**
  5129.      * Strip newlines to prevent header injection.
  5130.      * @access public
  5131.      * @param string $str
  5132.      * @return string
  5133.      */
  5134.     public function secureHeader($str)
  5135.     {
  5136.         return trim(str_replace(array("\r", "\n"), '', $str));
  5137.     }
  5138.     /**
  5139.      * Normalize line breaks in a string.
  5140.      * Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format.
  5141.      * Defaults to CRLF (for message bodies) and preserves consecutive breaks.
  5142.      * @param string $text
  5143.      * @param string $breaktype What kind of line break to use, defaults to CRLF
  5144.      * @return string
  5145.      * @access public
  5146.      * @static
  5147.      */
  5148.     public static function normalizeBreaks($text, $breaktype = "\r\n")
  5149.     {
  5150.         return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  5151.     }
  5152.     /**
  5153.      * Set the public and private key files and password for S/MIME signing.
  5154.      * @access public
  5155.      * @param string $cert_filename
  5156.      * @param string $key_filename
  5157.      * @param string $key_pass Password for private key
  5158.      * @param string $extracerts_filename Optional path to chain certificate
  5159.      */
  5160.     public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '')
  5161.     {
  5162.         $this->sign_cert_file = $cert_filename;
  5163.         $this->sign_key_file = $key_filename;
  5164.         $this->sign_key_pass = $key_pass;
  5165.         $this->sign_extracerts_file = $extracerts_filename;
  5166.     }
  5167.     /**
  5168.      * Quoted-Printable-encode a DKIM header.
  5169.      * @access public
  5170.      * @param string $txt
  5171.      * @return string
  5172.      */
  5173.     public function DKIM_QP($txt)
  5174.     {
  5175.         $line = '';
  5176.         for ($i = 0; $i < strlen($txt); $i++) {
  5177.             $ord = ord($txt[$i]);
  5178.             if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
  5179.                 $line .= $txt[$i];
  5180.             } else {
  5181.                 $line .= '=' . sprintf('%02X', $ord);
  5182.             }
  5183.         }
  5184.         return $line;
  5185.     }
  5186.     /**
  5187.      * Generate a DKIM signature.
  5188.      * @access public
  5189.      * @param string $signHeader
  5190.      * @throws phpmailerException
  5191.      * @return string The DKIM signature value
  5192.      */
  5193.     public function DKIM_Sign($signHeader)
  5194.     {
  5195.         if (!defined('PKCS7_TEXT')) {
  5196.             if ($this->exceptions) {
  5197.                 throw new phpmailerException($this->lang('extension_missing') . 'openssl');
  5198.             }
  5199.             return '';
  5200.         }
  5201.         $privKeyStr = !empty($this->DKIM_private_string) ? $this->DKIM_private_string : file_get_contents($this->DKIM_private);
  5202.         if ('' != $this->DKIM_passphrase) {
  5203.             $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  5204.         } else {
  5205.             $privKey = openssl_pkey_get_private($privKeyStr);
  5206.         }
  5207.         //Workaround for missing digest algorithms in old PHP & OpenSSL versions
  5208.         //@link http://stackoverflow.com/a/11117338/333340
  5209.         if (version_compare(PHP_VERSION, '5.3.0') >= 0 and
  5210.             in_array('sha256WithRSAEncryption', openssl_get_md_methods(true))) {
  5211.             if (openssl_sign($signHeader, $signature, $privKey, 'sha256WithRSAEncryption')) {
  5212.                 openssl_pkey_free($privKey);
  5213.                 return base64_encode($signature);
  5214.             }
  5215.         } else {
  5216.             $pinfo = openssl_pkey_get_details($privKey);
  5217.             $hash = hash('sha256', $signHeader);
  5218.             //'Magic' constant for SHA256 from RFC3447
  5219.             //@link https://tools.ietf.org/html/rfc3447#page-43
  5220.             $t = '3031300d060960864801650304020105000420' . $hash;
  5221.             $pslen = $pinfo['bits'] / 8 - (strlen($t) / 2 + 3);
  5222.             $eb = pack('H*', '0001' . str_repeat('FF', $pslen) . '00' . $t);
  5223.             if (openssl_private_encrypt($eb, $signature, $privKey, OPENSSL_NO_PADDING)) {
  5224.                 openssl_pkey_free($privKey);
  5225.                 return base64_encode($signature);
  5226.             }
  5227.         }
  5228.         openssl_pkey_free($privKey);
  5229.         return '';
  5230.     }
  5231.     /**
  5232.      * Generate a DKIM canonicalization header.
  5233.      * @access public
  5234.      * @param string $signHeader Header
  5235.      * @return string
  5236.      */
  5237.     public function DKIM_HeaderC($signHeader)
  5238.     {
  5239.         $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  5240.         $lines = explode("\r\n", $signHeader);
  5241.         foreach ($lines as $key => $line) {
  5242.             list($heading, $value) = explode(':', $line, 2);
  5243.             $heading = strtolower($heading);
  5244.             $value = preg_replace('/\s{2,}/', ' ', $value); // Compress useless spaces
  5245.             $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
  5246.         }
  5247.         $signHeader = implode("\r\n", $lines);
  5248.         return $signHeader;
  5249.     }
  5250.     /**
  5251.      * Generate a DKIM canonicalization body.
  5252.      * @access public
  5253.      * @param string $body Message Body
  5254.      * @return string
  5255.      */
  5256.     public function DKIM_BodyC($body)
  5257.     {
  5258.         if ($body == '') {
  5259.             return "\r\n";
  5260.         }
  5261.         // stabilize line endings
  5262.         $body = str_replace("\r\n", "\n", $body);
  5263.         $body = str_replace("\n", "\r\n", $body);
  5264.         // END stabilize line endings
  5265.         while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  5266.             $body = substr($body, 0, strlen($body) - 2);
  5267.         }
  5268.         return $body;
  5269.     }
  5270.     /**
  5271.      * Create the DKIM header and body in a new message header.
  5272.      * @access public
  5273.      * @param string $headers_line Header lines
  5274.      * @param string $subject Subject
  5275.      * @param string $body Body
  5276.      * @return string
  5277.      */
  5278.     public function DKIM_Add($headers_line, $subject, $body)
  5279.     {
  5280.         $DKIMsignatureType = 'rsa-sha256'; // Signature & hash algorithms
  5281.         $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  5282.         $DKIMquery = 'dns/txt'; // Query method
  5283.         $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  5284.         $subject_header = "Subject: $subject";
  5285.         $headers = explode($this->LE, $headers_line);
  5286.         $from_header = '';
  5287.         $to_header = '';
  5288.         $date_header = '';
  5289.         $current = '';
  5290.         foreach ($headers as $header) {
  5291.             if (strpos($header, 'From:') === 0) {
  5292.                 $from_header = $header;
  5293.                 $current = 'from_header';
  5294.             } elseif (strpos($header, 'To:') === 0) {
  5295.                 $to_header = $header;
  5296.                 $current = 'to_header';
  5297.             } elseif (strpos($header, 'Date:') === 0) {
  5298.                 $date_header = $header;
  5299.                 $current = 'date_header';
  5300.             } else {
  5301.                 if (!empty($$current) && strpos($header, ' =?') === 0) {
  5302.                     $$current .= $header;
  5303.                 } else {
  5304.                     $current = '';
  5305.                 }
  5306.             }
  5307.         }
  5308.         $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  5309.         $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  5310.         $date = str_replace('|', '=7C', $this->DKIM_QP($date_header));
  5311.         $subject = str_replace(
  5312.             '|',
  5313.             '=7C',
  5314.             $this->DKIM_QP($subject_header)
  5315.         ); // Copied header fields (dkim-quoted-printable)
  5316.         $body = $this->DKIM_BodyC($body);
  5317.         $DKIMlen = strlen($body); // Length of body
  5318.         $DKIMb64 = base64_encode(pack('H*', hash('sha256', $body))); // Base64 of packed binary SHA-256 hash of body
  5319.         if ('' == $this->DKIM_identity) {
  5320.             $ident = '';
  5321.         } else {
  5322.             $ident = ' i=' . $this->DKIM_identity . ';';
  5323.         }
  5324.         $dkimhdrs = 'DKIM-Signature: v=1; a=' .
  5325.             $DKIMsignatureType . '; q=' .
  5326.             $DKIMquery . '; l=' .
  5327.             $DKIMlen . '; s=' .
  5328.             $this->DKIM_selector .
  5329.             ";\r\n" .
  5330.             "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
  5331.             "\th=From:To:Date:Subject;\r\n" .
  5332.             "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
  5333.             "\tz=$from\r\n" .
  5334.             "\t|$to\r\n" .
  5335.             "\t|$date\r\n" .
  5336.             "\t|$subject;\r\n" .
  5337.             "\tbh=" . $DKIMb64 . ";\r\n" .
  5338.             "\tb=";
  5339.         $toSign = $this->DKIM_HeaderC(
  5340.             $from_header . "\r\n" .
  5341.             $to_header . "\r\n" .
  5342.             $date_header . "\r\n" .
  5343.             $subject_header . "\r\n" .
  5344.             $dkimhdrs
  5345.         );
  5346.         $signed = $this->DKIM_Sign($toSign);
  5347.         return $dkimhdrs . $signed . "\r\n";
  5348.     }
  5349.     /**
  5350.      * Detect if a string contains a line longer than the maximum line length allowed.
  5351.      * @param string $str
  5352.      * @return boolean
  5353.      * @static
  5354.      */
  5355.     public static function hasLineLongerThanMax($str)
  5356.     {
  5357.         //+2 to include CRLF line break for a 1000 total
  5358.         return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str);
  5359.     }
  5360.     /**
  5361.      * Allows for public read access to 'to' property.
  5362.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  5363.      * @access public
  5364.      * @return array
  5365.      */
  5366.     public function getToAddresses()
  5367.     {
  5368.         return $this->to;
  5369.     }
  5370.     /**
  5371.      * Allows for public read access to 'cc' property.
  5372.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  5373.      * @access public
  5374.      * @return array
  5375.      */
  5376.     public function getCcAddresses()
  5377.     {
  5378.         return $this->cc;
  5379.     }
  5380.     /**
  5381.      * Allows for public read access to 'bcc' property.
  5382.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  5383.      * @access public
  5384.      * @return array
  5385.      */
  5386.     public function getBccAddresses()
  5387.     {
  5388.         return $this->bcc;
  5389.     }
  5390.     /**
  5391.      * Allows for public read access to 'ReplyTo' property.
  5392.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  5393.      * @access public
  5394.      * @return array
  5395.      */
  5396.     public function getReplyToAddresses()
  5397.     {
  5398.         return $this->ReplyTo;
  5399.     }
  5400.     /**
  5401.      * Allows for public read access to 'all_recipients' property.
  5402.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  5403.      * @access public
  5404.      * @return array
  5405.      */
  5406.     public function getAllRecipientAddresses()
  5407.     {
  5408.         return $this->all_recipients;
  5409.     }
  5410.     /**
  5411.      * Perform a callback.
  5412.      * @param boolean $isSent
  5413.      * @param array $to
  5414.      * @param array $cc
  5415.      * @param array $bcc
  5416.      * @param string $subject
  5417.      * @param string $body
  5418.      * @param string $from
  5419.      */
  5420.     protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
  5421.     {
  5422.         if (!empty($this->action_function) && is_callable($this->action_function)) {
  5423.             $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  5424.             call_user_func_array($this->action_function, $params);
  5425.         }
  5426.     }
  5427. }
  5428. /**
  5429.  * PHPMailer exception handler
  5430.  * @package PHPMailer
  5431.  */
  5432. class phpmailerException extends Exception
  5433. {
  5434.     /**
  5435.      * Prettify error message output
  5436.      * @return string
  5437.      */
  5438.     public function errorMessage()
  5439.     {
  5440.         $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  5441.         return $errorMsg;
  5442.     }
  5443. }
  5444.  
  5445.  
  5446. $mail = new PHPMailer();
  5447.  
  5448.  
  5449. // REMOVE ALL HTML TAG WILL BE USED IN ALTBODY
  5450. function strip_tags_content($text, $tags = '', $invert = FALSE) {
  5451.  
  5452.   /*preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
  5453.   $tags = array_unique($tags[1]);
  5454.    
  5455.   if(is_array($tags) AND count($tags) > 0) {
  5456.     if($invert == FALSE) {
  5457.       return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
  5458.     }
  5459.     else {
  5460.       return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
  5461.     }
  5462.   }
  5463.   elseif($invert == FALSE) {
  5464.     return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
  5465.   } */
  5466.   return strip_tags($text);
  5467. }
  5468.  
  5469. // TRIM LEFT AND RIGHT
  5470. function lrtrim($string)
  5471. {
  5472.     return stripslashes(ltrim(rtrim($string)));
  5473. }
  5474. // REPLACE LAST OCCURENCE OF STRING
  5475. function str_lreplace($search, $replace, $subject)
  5476. {
  5477.     $pos = strrpos($subject, $search);
  5478.  
  5479.     if($pos !== false)
  5480.     {
  5481.         $subject = substr_replace($subject, $replace, $pos, strlen($search));
  5482.     }
  5483.  
  5484.     return $subject;
  5485. }
  5486. // RANDOM STRING FUNCTION
  5487. function generateRandomString($matches)
  5488. {
  5489.     $length = intval(ltrim(rtrim($matches[3])));
  5490.     $PATTERN = str_lreplace('-','',$matches[2]);
  5491.    
  5492.     $characters = '';
  5493.     if(strpos($PATTERN, '09') !== false)
  5494.         $characters .= '0123456789';
  5495.     if(strpos($PATTERN, 'az') !== false)
  5496.         $characters .= 'abcdefghijklmnopqrstuvwxyz';
  5497.     if(strpos($PATTERN, 'AZ') !== false)
  5498.         $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  5499.     $charactersLength = strlen($characters);
  5500.     $randomString = '';
  5501.     for ($i = 0; $i < $length; $i++) {
  5502.         $randomString .= $characters[rand(0, $charactersLength - 1)];
  5503.     }
  5504.     return $randomString;
  5505. }
  5506. // WAITING FUNCTION
  5507. function pause($pause,$mail)
  5508. {
  5509.                     $sec=doubleval($pause);
  5510.                     $mail->SmtpClose();
  5511.                     echo "\n\n<br><br>############################### WAITING $sec SEC TO CONTINUE SENDING ###############################<br><br>\n\n";
  5512.                     flush();
  5513.                     sleep($sec);
  5514. }
  5515. // SMTP SWITCH
  5516. function switch_smtp()
  5517. {
  5518.     global $allsmtps;
  5519.     global $curentsmtp;
  5520.     global $mail;
  5521.     global $isbcc;
  5522.     global $from;
  5523.     global $lase;
  5524.     global $replyto;
  5525.     global $reading;
  5526.     global $repaslog;
  5527.     if(count($allsmtps) > $curentsmtp)
  5528.     {
  5529.         $smtprot = explode(':',$allsmtps[$curentsmtp]);
  5530.         if(count($smtprot) > 0)
  5531.         {
  5532.             $mail->Host = $smtprot[0];
  5533.             $mail->Port = $smtprot[1];
  5534.             $mail->Username = $smtprot[2];
  5535.             $mail->Password = $smtprot[3];
  5536.             if($reading && $repaslog)
  5537.                 $replyto = $smtprot[2];
  5538.             if($lase)
  5539.             {
  5540.                 $from = $smtprot[2];
  5541.                 $from_base = $smtprot[2];
  5542.             }
  5543.    
  5544.             if($smtprot[4] =="SSL")
  5545.             $mail->SMTPSecure  = "ssl"; //you can change it to ssl or tls
  5546.             else if($smtprot[4] =="TLS")
  5547.                 $mail->SMTPSecure  = "tls";
  5548.             else if($smtprot[4] =="NON")
  5549.                 $mail->SMTPSecure  = "";
  5550.             if($smtprot[5] =="BCC")
  5551.             $isbcc = true;
  5552.             else $isbcc = false;
  5553.            
  5554.         }
  5555.     }
  5556. }
  5557.  
  5558.  
  5559.     if ($action)
  5560.     {
  5561.         if (!$from && !$subject && !$message && !$emaillist)
  5562.         {
  5563.             print "<script>alert('PLEASE FILL ALL FIELDS BEFORE SENDING YOUR MESSAGE.'); </script>";
  5564.             die(); 
  5565.         }
  5566.         else
  5567.         {
  5568.             $allemails =  preg_split("/\\r\\n|\\r|\\n/", $emaillist);
  5569.             $numemails = count($allemails);
  5570.             $nq=0;
  5571.             $qx=0;
  5572.            
  5573.             if(!empty($epriority))
  5574.                 $mail->Priority = "$epriority";
  5575.             if($contenttype == "html")
  5576.                 $mail->IsHtml(true);
  5577.             else
  5578.                 $mail->IsHtml(false);
  5579.             if(empty($reconnect))
  5580.                 $reconnect=0;
  5581.             if(!empty($replyto))
  5582.                 $mail->AddReplyTo("$replyto");
  5583.             if(empty($my_smtp))
  5584.             {
  5585.                 $mail->SMTPAuth = false;
  5586.                 $mail->IsSendmail();
  5587.                 $default_system="1";
  5588.             }
  5589.             else
  5590.             {
  5591.                 $mail->IsSMTP();
  5592.                 $mail->SMTPKeepAlive = true;
  5593.                 $mail->SMTPAuth = true;
  5594.                 switch_smtp();
  5595.             }
  5596.             $mail->From = $from;
  5597.             #$mail->addCustomHeader('List-Unsubscribe',preg_replace_callback('/(##([a-zA-Z0-9\-]+)\{([0-9]+)\}##)/', "generateRandomString", 'mailto:bounce##09-{3}##-##az-AZ-09-{15}##@'.explode('@',$from)[1].'?subject=list-unsubscribe'));
  5598.             // SET DEBUG LVL
  5599.             $mail->SMTPDebug = $debg;
  5600.             // SET CHARSET
  5601.             $mail->CharSet = "UTF-8";
  5602.             // READING CONFIRMATION
  5603.             if($reading)
  5604.                 $mail->ConfirmReadingTo = $replyto;
  5605.             else $mail->ConfirmReadingTo = '';
  5606.             // SET ENCODING TYPE
  5607.             if($encodety !="no") $mail->Encoding = $encodety;
  5608.             // ADD ATTACH
  5609.             if (array_key_exists('userfile', $_FILES))
  5610.             {
  5611.                 // First handle the upload
  5612.                 // Don't trust provided filename - same goes for MIME types
  5613.                 // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
  5614.                 $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
  5615.                 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
  5616.                 {
  5617.                     $mail->addAttachment($uploadfile,$_FILES['userfile']['name']);
  5618.                 }
  5619.             }
  5620.             for($x=1; $x<=$numemails; $x++)
  5621.             {
  5622.                 // BCC EMAIL COUNT
  5623.                 if($isbcc && $x % intval($nbcc) == 0)
  5624.                 {
  5625.                     $nm += 1;
  5626.                     $nopose=false;
  5627.                     $canrotat=true;
  5628.                 }
  5629.                 else
  5630.                 {
  5631.                     $nopose=true;
  5632.                     $canrotat=false;
  5633.                 }
  5634.                 //END//
  5635.                
  5636.                 $send=false;
  5637.                 $v=$x-1;
  5638.                 $to = $allemails[$v];
  5639.                 $to = preg_replace("/ /", "", $to);
  5640.                
  5641.                 // ADD ADRESSES TO QUEUE
  5642.                 if($isbcc && !empty($nbcc) )
  5643.                 {
  5644.  
  5645.                     if($x % intval($nbcc)  != 0 && $x <= $numemails)
  5646.                     {
  5647.                         $mail->addBCC("$to");
  5648.                         print "<span style=\"color:red;\">Line $qx </span> : Sending mail to $to<br>";
  5649.                         flush();
  5650.                         if($x % intval($nbcc) != 0 && $x == $numemails)
  5651.                             $send=true;
  5652.                     }
  5653.                     else
  5654.                     {
  5655.                         $mail->addBCC("$to");
  5656.                         print "<span style=\"color:red;\">Line $qx </span> : Sending mail to $to<br>";
  5657.                         flush();
  5658.                         $send = true;
  5659.                     }
  5660.                     $qx=$x;
  5661.                 }
  5662.                 else
  5663.                 {
  5664.                     $mail->clearAddresses();
  5665.                     $mail->AddAddress("$to");
  5666.                     $send=true;
  5667.                     print "<span style=\"color:red;\">Line $qx </span> : Sending mail to $to.......";
  5668.                     flush();
  5669.                     $qx=$x;
  5670.                 }
  5671.                 //END//
  5672.                 if($send)
  5673.                 {  
  5674.                    
  5675.                     $realname = preg_replace_callback('/(##([a-zA-Z0-9\-]+)\{([0-9]+)\}##)/', "generateRandomString", $realname_base);
  5676.                     $realname = lufClear($realname,$to);
  5677.                     $message = preg_replace_callback('/(##([a-zA-Z0-9\-]+)\{([0-9]+)\}##)/', "generateRandomString", $message_base);
  5678.                     $message = lufClear($message,$to);
  5679.                     $subject = preg_replace_callback('/(##([a-zA-Z0-9\-]+)\{([0-9]+)\}##)/', "generateRandomString", $subject_base);
  5680.                     $subject = lufClear($subject,$to);
  5681.                     $from = preg_replace_callback('/(##([a-zA-Z0-9\-]+)\{([0-9]+)\}##)/', "generateRandomString", $from_base);
  5682.                     $from = lufClear($from,$to);
  5683.                    
  5684.                     if(!$isbcc)
  5685.                     {
  5686.                         $message = preg_replace("/!!EMAIL!!/", $to, $message);
  5687.                         $subject = preg_replace("/!!EMAIL!!/", $to, $subject);
  5688.                     }
  5689.                     $message = preg_replace("/!!DATE!!/", date("d/m/Y"), $message);
  5690.                     $subject = preg_replace("/!!DATE!!/", date("d/m/Y"), $subject);
  5691.                     $message = preg_replace("/!!TIME!!/", date("H:i:s"), $message);
  5692.                     $subject = preg_replace("/!!TIME!!/", date("H:i:s"), $subject);
  5693.                     $message = urlencode($message);
  5694.                     $message = preg_replace("/%5C%22/", "%22", $message);
  5695.                     $message = urldecode($message);
  5696.                     $message = stripslashes($message);
  5697.                     $subject = stripslashes($subject);
  5698.  
  5699.                     if ($encodety != "no")
  5700.                     {
  5701.                         $subject = "=?UTF-8?B?".base64_encode($subject)."?=";
  5702.                         $realname = "=?UTF-8?B?".base64_encode($realname)."?=";
  5703.                     }
  5704.  
  5705.                     $mail->FromName = "$realname";
  5706.                     $mail->Subject = "$subject";
  5707.                     $mail->Body = "$message";
  5708.                     $mail->AltBody = strip_tags_content($message);
  5709.                     // SENDING AND TESTING
  5710.                     if(!$mail->Send())
  5711.                         {
  5712.                             if($default_system != "1")
  5713.                             {
  5714.                                 echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";
  5715.                             }
  5716.                             if($default_system  == "1")
  5717.                             {
  5718.                                 $mail->IsMail();
  5719.                                 if(!$mail->Send())
  5720.                                 {
  5721.                                     echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";
  5722.                                 }
  5723.                                 else
  5724.                                 {
  5725.                                     if($isbcc)
  5726.                                         echo "# BCC EMAIL NUMERO <span style=\"color:red;\">NUMERO $nm </span> SEND :<b>OK</b><br>";
  5727.                                     else echo "<b>OK</b><br>";
  5728.                                 }
  5729.                             }
  5730.                         }
  5731.                         else
  5732.                         {
  5733.                             if($isbcc)
  5734.                                         echo "# BCC EMAIL <span style=\"color:red;\">NUMERO $nm </span> SEND :<b>OK</b><br>";
  5735.                                     else echo "<b>OK</b><br>";
  5736.                         }
  5737.                         if($reconnect >0 && $reconnect==$nq && !(intval($nrotat) > 0 && count($allsmtps) > 1))
  5738.                         {
  5739.                             $mail->SmtpClose();
  5740.                             echo "<p><b>########################### SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON ########################### </b></p>";
  5741.                             $nq=0;
  5742.                         }
  5743.                         $nq=$nq+1;
  5744.                         flush();
  5745.                         if($isbcc)
  5746.                         $mail->clearBCCs();
  5747.                 }
  5748.                 //END//
  5749.                
  5750.                 // SMTP IP ROTATION  NB: 1 BCC = 1 EMAIL
  5751.                     if(intval($nrotat) > 0 && count($allsmtps) > 1)
  5752.                     {
  5753.                         $curentsmtp += 1;
  5754.                         $nq=0;
  5755.                         $mail->SmtpClose();
  5756.                         switch_smtp();
  5757.                         if($isbcc)
  5758.                         {
  5759.                             if($nm > 0 && $nm % intval($nrotat) == 0 && $canrotat && $x < $numemails)
  5760.                             {
  5761.                                 echo "\n<br><span style=\"color:red;\">##############</span><b>  ROTATE TO SMTP ".($curentsmtp+1)." IP: ".$mail->Host."</b><span style=\"color:red;\"> ##############</span><br><br>\n";
  5762.                                
  5763.                             }
  5764.                         }
  5765.                         else if ($x % intval($nrotat)==0 && $x < $numemails)
  5766.                         {
  5767.                             if($x >= intval($nrotat))
  5768.                             echo "\n<br><span style=\"color:red;\">##############</span><b>  ROTATE TO SMTP ".($curentsmtp+1)." IP: ".$mail->Host."</b><span style=\"color:red;\"> ##############</span><br><br>\n\n";
  5769.                         }
  5770.                         if($curentsmtp >= count($allsmtps))
  5771.                         {
  5772.                             $curentsmtp=0;
  5773.                         }
  5774.                        
  5775.                     }
  5776.                     //END//
  5777.                
  5778.                 // WAITING PAUSE TIME
  5779.                 if(!empty($pause) && !empty($pemails))
  5780.                 {
  5781.                     if(doubleval($pause) > 0)
  5782.                     {
  5783.                         if(!$isbcc)
  5784.                         {
  5785.                             if($x % intval($pemails) == 0 && $x < $numemails)
  5786.                             {
  5787.                                 pause($pause,$mail);
  5788.                             }
  5789.                         }
  5790.                         else if($nm > 0 && $nm % intval($pemails) == 0 && $x < $numemails && !$nopose)
  5791.                         {
  5792.                             pause($pause,$mail);
  5793.                         }
  5794.                     }
  5795.                 }
  5796.                 //END//
  5797.             }
  5798.         }
  5799.     }
  5800. ?>
Add Comment
Please, Sign In to add comment