Hello! I can not understand why sending mail with automatic reply is not working correctly. (Initial sending works without problems, auto-answer does not work)

$ send - tried and with the point and without a point, and another variable and stuff, but still: (

And, and in the $ sendfrom variable, for some reason, spaces are always removed from the text. Why? In the rest of the places the spaces everywhere work norms, not here :( and \ r \ n does not help ...

<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!empty($_POST['uname']) && (!empty($_POST['uemail']) && (!empty($_POST['umessage'])))){ if (isset($_POST['uname'])) { if (!empty($_POST['uname'])){ $uname = strip_tags($_POST['uname']) . "<br>"; $unameInput = "<b>Имя:</b><br>"; } } if (isset($_POST['uemail'])) { if (!empty($_POST['uemail'])){ $uemail = strip_tags($_POST['uemail']) . "<br>"; $uemailInput = "<b>Почта:</b><br>"; } } if (isset($_POST['umessage'])) { if (!empty($_POST['umessage'])){ $umessage = strip_tags($_POST['umessage']) . "<br>"; $umessageInput = "<b>Сообщение:</b><br>"; } } if (isset($_POST['uphone'])) { if (!empty($_POST['uphone'])){ $uphone = strip_tags($_POST['uphone']) . "<br>"; $uphoneInput = "<b>Телефон:</b><br>"; } } $to = "mail@skgs.su" . ", "; /*адрес, на который должно приходить письмо*/ $to .= "angel-nwn@yandex.ru" . ", "; $sendfrom = "Comfort System"; /*адрес, с которого будет приходить письмо */ $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"; $headers .= "Content-Transfer-Encoding: 8bit \r\n"; $subject = "Сообщение с сайта"; $subject2 = "Автоответ на письмо"; $body2 = 'Здравствуйте, $name\r\n.<br> Пожалуйста, не отвечайте на это письмо. Оно сформировано автоматически.<br> Вы написали нам письмо, со следующим текстом:'; $message = "$unameInput $uname $uemailInput $uemail $uphoneInput $uphone $umessageInput $umessage"; $send = mail ($to, $subject, $message, $headers); $send .= mail ($uemail, $subject2, $message, $headers); if ($send == 'true'){ echo '<p class="success">Спасибо за отправку вашего сообщения!</p>'; } else { echo '<p class="fail"><b>Ошибка. Сообщение не отправлено!</b></p>'; } } else { echo '<p class="fail">Ошибка. Вы заполнили не все обязательные поля!</p>'; } } else { header ("Location: http://skgs.su"); // главная страница } 

    1 answer 1

    Hello

    In my opinion, the problem is in the string:

     $send .= mail ($uemail, $subject2, $message, $headers); 

    First, you are trying to attach the result of the second function to the bool result of the first mail() function, so the check will no longer work correctly.

    Secondly, the $uemail variable when assigned:

     $uemail = strip_tags($_POST['uemail']) . "<br>"; 

    gets <br> , i.e. if $_POST['uemail'] contains test@site.com , then the result of the assignment will be $uemail = 'test@site.com<br>' , therefore the mail() function will not send anything to this email.

    PS On account of $sendfrom , most likely problems due to the fact that the From header is not quite correctly formed.

    Try these changes:

     $sendfrom = "Comfort System"; $mailfrom = "no-reply@domain.com"; // domain.com замените на ваш домен $header = "From: ".$sendfrom." <".$mailfrom."> \r\n"; 
    • I understand you, but the question is that I found a similar code in my time on the Runet’s open spaces, naturally modified it quite a lot. And everything worked. When I wanted to add an auto answer, using the same code (or rather the second line of send), it stopped working. Although the source worked all is well. - Gwai
    • And how then will it be easier to add a transfer to a new line in such a code? :) - Gwai
    • So, well, I figured out the code. I can not figure out why the $ sendfrom variable works crookedly. - Gwai