【发布时间】:2016-02-10 05:45:29
【问题描述】:
我为我的网站创建的联系表有问题。我不是 PHP 专家,但我认为适当的联系表格会比简单的 href mailto 链接更专业。 我设法收到了电子邮件,它告诉我发件人,但没有主题,而且都是空白的,没有文字。此外,我每天都会收到 2 封没有发件人的电子邮件。
这是我在名为contact.php 的页面中在PHP 中所做的。 希望能帮到你:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$form1_services = $_POST['form1_services'];
$msg = $_POST['msg'];
$formcontent="From: $name \n Message: $message";
$recipient = "dandrea.alessandro81@gmail.com";
$subject = "Customer Inquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Keep in touch soon!" . " -" . "<a href='index.html' style='text-decoration:none;font-family: 'gooddogregular';color:#009999;'> Return Home</a>";
?>
这是 HTML 中的实际形式:
<form action="contact.php" method="post">
<fieldset>
<legend></legend>
<div class="controlgroup">
<label for="form1_name">Name *</label>
<input type="text" placeholder="Enter your full name*" name="name" value>
</div>
<div class="controlgroup">
<label for="form1_email">Email *</label>
<input type="text" placeholder="Enter a valid email address*" name="email" value>
</div>
<div class="controlgroup">
<label for="form1_services">Services Required</label>
<select id="form1_services" name="services">
<option value="Website Design"> Website Design (from scratch) </option>
<option value="Resposive Design"> Responsive Design </option>
<option value="Customize a Site"> Customize a Site </option>
<option value="Quotation"> Quotation </option>
</select>
</div>
<div class="controlgroup">
<label>Project Info*</label>
<textarea placeholder="Ciao Alessandro, I am contacting you because...*" id="msg" name="msg" required aria-required="true"></textarea>
</div>
<input type="submit" name="submit_btn" id="send" value="Hit me up!" class="wow rubberBand animated" data-wow-delay="2s">
</fieldset>
</form>
提前非常感谢。 亚历山德罗
【问题讨论】:
-
将
echo('<p>'.$_POST['name'].'</p>');添加到您的 php 以确保您实际上是从表单中获取数据。 -
作为一个警示故事,正如@samlev 所提到的,您需要实施验证,以免有人劫持您的表单发送垃圾邮件。
-
还要注意您正在使用来自
namehtml 属性的索引。您要求$_POST['form1_services'],但它实际上是以services发送的。