Created
January 5, 2017 11:38
-
-
Save kirwebpr/51024b0d3bf39e9be2baf5d195410774 to your computer and use it in GitHub Desktop.
Форма обратной связи
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| session_start(); | |
| if(isset($_POST["send"])){ | |
| $from = htmlspecialchars ($_POST["from"]); | |
| $to = htmlspecialchars ($_POST["to"]); | |
| $subject = htmlspecialchars ($_POST["subject"]); | |
| $message = htmlspecialchars ($_POST["message"]); | |
| $_SESSION["from"] = $from; | |
| $_SESSION["to"] = $to; | |
| $_SESSION["subject"] = $subject; | |
| $_SESSION["message"] = $message; | |
| $error_from=""; | |
| $error_to=""; | |
| $error_subject=""; | |
| $error_message=""; | |
| $error = false; | |
| // Реализация ошибок | |
| if ($from == "" || !preg_match("/@/", $from)) { | |
| $error_from = "Введите корректный e-mail"; | |
| $error = true; | |
| } | |
| if ($to == "" || !preg_match("/@/", $to)) { | |
| $error_to = "Введите корректный e-mail"; | |
| $error = true; | |
| } | |
| if (strlen($subject)==0) { | |
| $error_subject = "Введите тему сообщения"; | |
| $error = true; | |
| } | |
| if (strlen($message)==0) { | |
| $error_message = "Введите сообщение"; | |
| $error = true; | |
| } | |
| if (!$error){ | |
| $subject = "=?utf-8?B?".base64_encode($subject)."?="; | |
| $headers = "From: $from\r\rReply-to: $from\r\nContent-type: text/plain; charset=utf-8\r\n"; | |
| mail ($to, $subject, $message, $headers); | |
| header ("Location: sent_success.php?send=1"); // переадресация при успешной отправке сообщения | |
| exit; | |
| } | |
| } | |
| ?> | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Обратная связь</title> | |
| </head> | |
| <body> | |
| <h2>Форма обратной связи</h2> | |
| <form name = "feedback" action="" method="post"> | |
| <lable>От кого:</lable><br> | |
| <input type="text" name="from" value="<?php echo $_SESSION["from"]?>"><span style="color: red"><?=$error_from?></span> <br> | |
| <lable>Кому:</lable><br> | |
| <input type="text" name="to" value="<?php echo $_SESSION["to"]?>"><span style="color: red"><?=$error_to?></span><br> | |
| <lable>Тема:</lable><br> | |
| <input type="text" name="subject" value="<?php echo $_SESSION["subject"]?>"><span style="color: red"><?=$error_subject?></span><br> | |
| <lable>Сообщение:</lable><br> | |
| <textarea name = "message" cols = "20" rows="5"><?=$_SESSION["message"]?></textarea><span style="color: red"><?=$error_message?></span><br> | |
| <input type="submit" name="send" value="Отправить"> | |
| </form> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| session_start(); | |
| if($_GET["send"]==1) | |
| echo "Вы успешно отправили сообщение на электронный адрес ".$_SESSION["to"]."."; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment