
<?php
  //инициализируем переменные
  $PswdFile = $_GET['pswdfile'];
  $QuestLength = $_GET['questlength'];
  $EmailAddrFile = "../txt/".str_replace('pswd', 'onepassd_emailaddr', $PswdFile);
  $LetterFile = "../txt/".str_replace('pswd', 'onepassd_letter', $PswdFile);
  $Question = GetQuestion("../txt/".$PswdFile, $QuestLength, 'pswd');

  if(empty($_GET['send']))
  {
    print "<br><br>";
    print "<div align=center>";
      print "{$Cpt_opfa_SendConf}<br><b>{$Question}</b><br><br>";
      print "<a href=index.php?page=changepassword_emailset_send&send=1&pswdfile={$PswdFile}&questlength={$QuestLength}>{$Cpt_Yes}</a>&nbsp;&nbsp;&nbsp;";
      print "<a href=index.php?page=changepassword_emailset&pswdfile={$PswdFile}&questlength={$QuestLength}>{$Cpt_No}</a>";
    print "</div>";
  }
  if($_GET['send'] == 1)
  {
    //получаем тему, обратный адрес и текст сообщения
    $Letter = file($LetterFile);
	  $MessSubject = trim($Letter[0]);
    $EmailFrom = trim($Letter[1]);
    $MessText = base64_decode(trim($MessText[2]));
    $Addresses = file($EmailAddrFile);
    for($i = 0; $i < count($Addresses); $i++)
    {
      $Addresses[$i] = trim($Addresses[$i]);
      if(strpos($Addresses[$i], ' (%%sended%%)') !== false)
        $AddressesCh[] = $Addresses[$i]."\n";
      elseif(@mail($Addresses[$i], $MessSubject, $MessText, $EmailFrom))
      {
        $AddressesCh[] = $Addresses[$i]." (%%sended%%)\n";
      }
      else $AddressesCh[] = $Addresses[$i]."\n";
    }    //for($i = 0; $i < count($Addresses); $i++)
    SaveStringInFile($EmailAddrFile, implode('', $AddressesCh), 'w');
    Refresh("changepassword_emailset&pswdfile={$PswdFile}&questlength={$QuestLength}");
  } //if($_GET['send'] == 1)
?>