B
B
Bulat Faizrakhmanov2016-07-09 13:27:00
PHP
Bulat Faizrakhmanov, 2016-07-09 13:27:00

Why is the form not being sent by email?

There is a code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
<meta name='author' content='Дмитрий Давыдов' />
<meta name='copyright' content='2015 - Smartlanding.biz' />

 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="css/remodal.css">
 <link rel="stylesheet" href="css/remodal-default-theme.css">
 <link href='https://fonts.googleapis.com/css?family=Roboto:400,300,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
 <link rel="stylesheet" type="text/css" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/remodal.min.js"></script>
<script src="js/script.js"></script>

</head>
<body>

<div class="home">
  <p><a class="mainButton" href="#modal">Оставить заявку</a></p>
</div>

<div class="remodal" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
 <div class="remodalBorder">
  <p><img src="img/sendico.png"></p>
  <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
      <form id="form">
        <h2 id="modal1Title">Оставьте ваши контактные данные и наш консультант свяжется <br>с вами</h2>
        <input type="text" class="putName" name="name" placeholder="Ваше ваше имя" required>
        <input name="phone" type="tel" class="putPhone" placeholder="Введите номер телефона" required>



          <script type="text/javascript">

 var australia = new Array("HSU-07HEK303R2 HSU-07HUN103R2","HSU-09HEK203R2 / HSU-09HUN03R2","HSU-12HEK203R2 HSU-12HUN03R2","HSU-18HEK203R2 HSU-12HUN03R2");
 var bagams= new Array("RS-07AST1","RS-09AST1","RS-12AST1","RS-18AST1");
 var egi= new Array("KSGMA21HFAN1","KSGMA26HFAN1","KSGMA35HFAN1","KSGMA53HFAN1");
 var cen= new Array("5807","5809","5812","5818");
 var selIndex= 0;
 var len;

 function Remove_option_from_select()
 {
  var len= document.getElementById("resort").options.length;

  if(len>0)
  {
         var ResortObj_r = document.getElementById("resort");

            for (var n = len-1; n>-1; n--)
        {

              // получаем индекс выбранного элемента
           if (ResortObj_r.options[n].selected==true)
           {
                ResortObj_r.remove(n);
           }

           }

  }else
       {
         alert("Удалять нечего - список пуст");
       }

 }




  function Add_option_to_select()
  {
     var CountryObj = document.getElementById("SelectMyLove");
     var ResortObj = document.getElementById("resort");
     var selind = CountryObj.options.selectedIndex;

   switch (selind)
    {
    case 0:
       ResortObj.options.length = 0;
      break;
    case 1:
         ResortObj.options.length = 0;

      len= australia.length;
     // alert(len);
      for (var n = 0; n < len; n++)
      {
         ResortObj[n] = new Option(australia[n], n);
      }


      break;
    case 2:
         ResortObj.options.length = 0;

         len= bagams.length;

      for (var n = 0; n < len; n++)
      {
         ResortObj[n] = new Option(bagams[n], n);
      }
      break;
      case 3:
             ResortObj.options.length = 0;

        len= bagams.length;

      for (var n = 0; n < len; n++)
      {
         ResortObj[n] = new Option(egi[n], n);
      }

      break;
      case 4:
      	ResortObj.options.length = 0;

        len= bagams.length;
      break;
      for (var n = 0; n < len; n++)
      {
         ResortObj[n] = new Option(cen[n], n);
      }
 		var selIndex=selind;
   }



 }

  function Present()
 {
    var ResortObj_Pres = document.getElementById("resort");
    var len= ResortObj_Pres.options.length;

   if(len>0)
   {
        ResortObj_Pres.options[len] = new Option("Вы едете бесплатно!", len);

       ResortObj_Pres.options[len].style.color="red";

   }else
         {
         	alert("Сейчас список курортов пуст элемент добавляется в конец списка!");
         }


 }

  </script>

 <FORM id="country" name="country" method="GET" action="select_b.php" >
<table>
<tr><td valign="top" id="select_cond">
Выберете кондиционер
<br /><br />
<SELECT name="SelectMyLove" id="SelectMyLove" onChange="Add_option_to_select();">
<OPTION VALUE="1">Выберете марку</OPTION>
<OPTION VALUE="2">Haier</OPTION>
<OPTION VALUE="3">Rovex</OPTION>
<OPTION VALUE="4">Kentatsu</OPTION>
<OPTION VALUE="5">Centek</OPTION>
</SELECT>
</td>
<td valign="top" id="select_cond">
Список кондиционеров:
<br /><br />
<SELECT name="resort[]" id="resort" multiple size="5" style="width:250px;"></SELECT>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</FORM>
        <input type="submit" name="submit" class="btn" value="ОТПРАВИТЬ">
        <input type="hidden" name="formData" value="Заявка с сайта">
    </form>
</div>
</div>


</body>
</html>

and php code
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['name'])) {$name = $_POST['name'];}
    if (isset($_POST['phone'])) {$phone = $_POST['phone'];}
    if (isset($_POST['formData'])) {$formData = $_POST['formData'];}
    if (isset($_POST['SelectMyLove']))  {$SelectMyLove = $_POST['SelectMyLove'];}
    if (isset($_GET['selIndex'])){$selIndex = $_GET['selIndex'];}


    $to = "[email protected]"; /*Укажите адрес, га который должно приходить письмо*/
    $sendfrom   = "[email protected]"; /*Укажите адрес, с которого будет приходить письмо, можно не настоящий, нужно для формирования заголовка письма*/
    $headers  = "From: " . strip_tags($sendfrom) . "\r\n";
    $headers .= "Reply-To: ". strip_tags($sendfrom) . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html;charset=utf-8 \r\n";
    $subject = "$formData";
    $message = "$formData<br> <b>Имя пославшего:</b> $name <br><b>Телефон:</b> $phone <br><b>Марка кондиционера</b> $SelectMyLove <br><b>Номер (см.табличку)</b> $selIndex";
    $send = mail ($to, $subject, $message, $headers);
    if ($send == 'true')
    {
    echo '<center><p class="success">Спасибо за отправку вашего сообщения!</p></center>';
    }
    else 
    {
    echo '<center><p class="fail"><b>Ошибка. Сообщение не отправлено!</b></p></center>';
    }
} else {
    http_response_code(403);
    echo "Попробуйте еще раз";
}
?>

using it to send. But for some reason nothing comes up. I think it doesn't even reach php, because.
if ($send == 'true')
    {
    echo '<center><p class="success">Спасибо за отправку вашего сообщения!</p></center>';
    }
    else 
    {
    echo '<center><p class="fail"><b>Ошибка. Сообщение не отправлено!</b></p></center>';
    }
} else {
    http_response_code(403);
    echo "Попробуйте еще раз";
}

Nothing comes out here.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Dubrovin, 2016-07-09
@z3apa3a

You have trouble with <form> tags, you get two forms nested one inside the other. At the same time, action and method are not set (by default, the GET method, and your script expects POST). Remove the extra <form> and </form> tags and set an action (unless the form is submitted by the same script that processes it) and method="post".

T
ThunderCat, 2016-07-09
@ThunderCat

Vladimir Dubrovin , of course, is a handsome man who was not too lazy to unwind all these footcloths, but in general you have a mess in your code, take a normal idea that understands the syntax, and organize the code a little more modern, and not like in the 90s. Then there will be fewer such errors due to sloppy input.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question