简体   繁体   English

联系表格获取消息

[英]Contact form get message

There's a "contact page" in my site and I added the following html into it: 我的网站中有一个“联系页面”,我在其中添加了以下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> 

My issue is: if someone tryies to send a message, he'll be redirect to a 404 error page and I don't receive the message. 我的问题是:如果有人尝试发送消息,他将被重定向到404错误页面,而我没有收到消息。 How can I fix it and receive the message in my email? 如何解决它并在电子邮件中接收消息?

this is only html page. 这只是html页面。 to receive message in your email you have to create "action_page.php" file. 要在您的电子邮件中接收消息,您必须创建“ action_page.php”文件。 action_page.php code: action_page.php代码:

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

The problem is that you didnt understood the basics. 问题是您不了解基础知识。

First you have to learn more about forms: https://www.w3schools.com/html/html_forms.asp Then you need to send an email a server-side language, eg PHP. 首先,您必须了解有关表单的更多信息: https : //www.w3schools.com/html/html_forms.asp然后,您需要向电子邮件发送服务器端语言,例如PHP。 Otherwise it will only open your mailprogram. 否则,它只会打开您的邮件程序。

I made an example, but I not recommend to use THIS productive. 我举了一个例子,但我不建议您使用这种高效的工具。 It's to unsecure and has no vaildation, captcha, ... 它是不安全的,没有验证码,验证码,...

<!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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM