【发布时间】:2017-11-28 17:00:37
【问题描述】:
我正在尝试制作我的第一个联系表。我已经完成了 HTML & CSS 部分。可能 HTML 标记中有一些错误。
现在我的 HTML/CSS 看起来不错,我需要使其正常工作,以便将提交的内容发送到我的电子邮件,并且页面会显示感谢消息或重定向到感谢页面。
有人可以帮我编写为表单创建安全功能以使其工作的代码吗?
我还想在表单中添加验证码以避免垃圾邮件提交。
表单的实时链接-http://wishamemory.com/makeawish/index.html
表单的HTML代码是这样的:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Quick Minimal Contact Form</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<form id="contact-form">
<p>WISH A MEMORY!</p>
<p>I
<label for="your-wish">wish</label> for
<input type="text" name="your-wish" id="wish" minlength="3" placeholder="(describe your wish here)" required></p>
<p>
<label for="your-location">in</label>
<input type="text" name="your-location" id="location" minlength="3" placeholder="(location in Goa only)" required>
<label for="your-date">on</label>
<input type="text" name="your-date" id="date" minlength="3" placeholder="(dates)" required></p>
<p>***********</p>
<p>
<label for="your-credits">Is this wish for yourself or dedicated to someone else?</label>
<input type="text" name="your-credits" id="credits" minlength="3" placeholder="Who is the lucky one?" required></p>
<p>
<label for="your-budget">Preferred budget to make this wish a reality:</label>
<input type="text" name="your-budget" id="budget" minlength="3" placeholder="(amount in INR)" required></p>
<p>
<label for="your-maxbudget">Maximum you can spend to make the experience even more memorable:</label>
<input type="text" name="your-maxbudget" id="maxbudget" minlength="3" placeholder="(let's make it special)" required></p>
<p>
<label for="your-reason">Why do you think this wish deserves becoming a memory?</label>
<textarea name="your-reason" id="your-reason" placeholder="(Not all wishes come true. Share some background and the importance of this wish)" class="expanding" required></textarea>
</p>
<p>Personal details</p>
<p>
<label for="your-name">Name</label>
<input type="text" name="your-name" id="name" minlength="3" placeholder="(full name)" required></p>
<p>
<label for="email">Email address</label>
<input type="email" name="your-email" id="email" placeholder="(your email address)" required>
</p>
<p>
<label for="phone">Mobile number</label>
<input type="text" name="your-phone" id="phone" placeholder="(mobile number)" required>
</p>
<p>
<button type="submit">
<svg version="1.1" class="send-icn" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="36px" viewBox="0 0 100 36" enable-background="new 0 0 100 36" xml:space="preserve">
<path d="M100,0L100,0 M23.8,7.1L100,0L40.9,36l-4.7-7.5L22,34.8l-4-11L0,30.5L16.4,8.7l5.4,15L23,7L23.8,7.1z M16.8,20.4l-1.5-4.3
l-5.1,6.7L16.8,20.4z M34.4,25.4l-8.1-13.1L25,29.6L34.4,25.4z M35.2,13.2l8.1,13.1L70,9.9L35.2,13.2z" />
</svg>
<small>send</small>
</button>
</p>
</form>
<small class='website'>Powered by <a href='http://wishamemory.com/' target='_blank'>wishamemory.com</a></small>
</body>
</html>
我尝试按如下方式制作mail.php进行测试。并在我的 HTML 文件中更改了
<form id="contact-form">
为此
<form action="mail.php" method="POST">
mail.php 文件
<?php
$your-wish = $_POST['your-wish'];
$your-location = $_POST['your-location'];
$your-date = $_POST['your-date'];
$formcontent="From: $your-name \n Message: $wish";
$recipient = "arminbaig@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $your-email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
但我在此网址上收到以下错误 - http://wishamemory.com/makeawish/mail.php
此页面无法正常工作
wishamemory.com 目前无法处理此请求。 HTTP 错误 500
我哪里错了?
【问题讨论】:
-
您的表单需要一个 PHP 部分,到目前为止您尝试过什么?
-
很高兴看到您为自己解决此问题而尝试了什么,这将向我们表明您在发布问题之前已经对此进行了研究。当你尝试时,你也会学习。如果有人只是给你一个答案/解决方案,那一切都是徒劳的,我这样说是为了/你的未来。然后,您可以编辑您的帖子以包含可能失败的内容;即使这表明你的努力。请记住,我们总是很乐意提供帮助。
-
你知道这里有很多类似的答案,还有谷歌搜索这个主题的教程?到目前为止你有没有尝试过?
-
这些是一些简单但不那么简单(也非常笼统)的问题,您应该首先自己研究。如果您进行了研究但仍有特定问题/疑问,那么您可以在此处提问。
-
联系表单是您在学习 PHP 时首先要做的基本练习之一。那里有字面意思,我的意思是字面意思,成千上万的例子。但是……你无视这些,直接来这里要求我们为你做这件事?