有一个"联系页面"在我的网站中,我将以下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>
&#13;
我的问题是:如果有人尝试发送邮件,他将会重定向到404错误页面而我却收不到该邮件。如何修复并在我的电子邮件中收到消息?
答案 0 :(得分:0)
这只是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';
}
答案 1 :(得分:0)
问题在于你没有理解基础知识。
首先,您需要了解有关表单的更多信息: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>