【发布时间】:2019-09-10 16:56:30
【问题描述】:
我是 PHP 新手,我正在为我的网站制作联系表格。但是,每当我填写并提交表格时,它都会将我带到一个空白页面,并且我从未收到过电子邮件。当我的网站上线时,我已经对其进行了测试。如果重要的话,我的主机是无限免费的。
我尝试了故障排除,例如对代码进行小幅修改(更改一些名称等),但没有任何效果。
<html>
<section id="contact">
<div class="container-contact">
<div style="text-align:center">
<h3> Contact Me </h3>
<p> I will get back to you shortly. </p>
</div>
<div class="row">
<div class="column">
<form id="contact-form" method="post" action="contactform.php">
<label for="firstname">First Name</label>
<input type="text" id="firstname" placeholder="Your first name..." required>
<label for="lastname">Last Name</label>
<input type="text" id="lastname" placeholder="Your last name..." required>
<label for="email">Email Address</label>
<input type="email" id="email" placeholder="Your email..." required>
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Write your message..." style="height:170px" required></textarea>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
</div>
</section>
</html>
<?php
$firstname = $_POST['firstname']
$lastname = $_POST['lastname']
$user_email = $_POST['email'];
$message = $_POST['message']
$email_from = 'myemail@domain.com'
$email_subject = "New Form Submission from $firstname.\n";
$email_body = "First Name: $firstname.\n".
"Last Name: $lastname.\n".
"Email: $user_email.\n".
"Message: $message.\n";
$to = "myemail@domain.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply To: $user_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: contact.html");
?>
HTML 文件名为contact.html,PHP 文件名为contactform.php
表单没有提交,我也没有收到电子邮件。难道我做错了什么?我需要设置其他东西吗?
提前致谢,
托马斯
【问题讨论】:
-
您检查浏览器控制台是否有错误?您是否检查过 Web 服务器日志是否有错误?是否在服务器上设置了邮件服务来发送邮件?