Контактная форма получить сообщение - PullRequest
0 голосов
/ 23 мая 2018

На моем сайте есть «страница контактов», и я добавил в нее следующий HTML-код:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Roboto, Roboto, sans-serif;}
<form action="mailto:pedroccoutinho@hotmail.com" method="post" enctype="text/plain">

form {
}

input[type=text], select, textarea {
    width: 100%;
    padding: 19px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    margin-top: 6px;
    margin-bottom: 1px;
    resize: vertical;
}

input[type=submit] {
    background-color: #f57c00;
    color: white;
    padding: 16px 90px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

input[type=submit]:hover {
    background-color: #ffad42;
}

.container {
    border-radius: 5px;
    background-color: #ffffff;
    padding: 20px;
}
</style>
</head>
<body>

<h3></h3>

<div class="container">
  <form action="/action_page.php">
    <label 
    {display:block; width:x; height:y; text-align:right;}for="fname"></label>
    <input type="text" id="fname" name="firstname" placeholder="Seu nome">
    <label for="subject"></label>
    <textarea id="subject" name="subject" placeholder="Deixe sua mensagem aqui" style="height:200px"></textarea>

    <input type="submit" value="Enviar">
  </form>
</div>

</body>
</html>

Моя проблема: если кто-то попытается отправить сообщение, он будет перенаправлен на страницу ошибки 404, и я не получу сообщение.Как я могу это исправить и получить сообщение в моем письме?

Ответы [ 2 ]

0 голосов
/ 23 мая 2018

Проблема в том, что вы не поняли основ.

Сначала вы должны узнать больше о формах: https://www.w3schools.com/html/html_forms.asp Затем вам нужно отправить электронное письмо на серверный язык, например, PHP.В противном случае он откроет только вашу почтовую программу.

Я сделал пример, но я не рекомендую использовать ЭТО продуктивно.Это небезопасно и не имеет vaildation, капча, ...

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Roboto, Roboto, sans-serif;}
form {
}

input[type=text], select, textarea {
    width: 100%;
    padding: 19px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    margin-top: 6px;
    margin-bottom: 1px;
    resize: vertical;
}

input[type=submit] {
    background-color: #f57c00;
    color: white;
    padding: 16px 90px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

input[type=submit]:hover {
    background-color: #ffad42;
}

.container {
    border-radius: 5px;
    background-color: #ffffff;
    padding: 20px;
}
</style>
</head>
<body>

<h3></h3>
<?php 
if(isset($_POST['submit']))
{
    mail('pedroccoutinho@hotmail.com', 'new contact message', $_POST['message']);
}
?>

<div class="container">
  <form action="" method="post">
    <label style="display:block; text-align:right;" for="fname"></label>
    <input type="text" id="fname" name="firstname" placeholder="Seu nome">
    <label for="message"></label>
    <textarea id="message" name="message" placeholder="Deixe sua mensagem aqui" style="height:200px"></textarea>

    <input name="submit" type="submit" value="Enviar">
  </form>
</div>

</body>
</html>
0 голосов
/ 23 мая 2018

это только HTML-страница.чтобы получить сообщение на свою электронную почту, вы должны создать файл "action_page.php".код action_page.php:

<?php
    if(isset($_POST['subject']) && !empty($_POST['subject'])){
        mail("yourmail@example.com","Message from ".$_POST['firstname'],$_POST['subject']);
        echo 'success';
    }
...