php - 执行 PHP 脚本后重新路由的问题
问题描述
我有一个使用 php 构建的联系表。
我的域名是 bestsellerprime.com
脚本执行后,应该向 info@bestsellerprime.com 发送任何电子邮件,该页面应该重新路由回主页(index.html),但我收到任何错误。错误说:
“此页面无法正常工作 bestsellerprime.com 目前无法处理此请求。HTTP 错误 500”
如何解决这个问题,代码如下:
<div class="form">
<form id="email-form" name="email-form" data-name="Email Form" class="form" method="post" action="contactform.php"><label for="name">Name:</label><input type="text" class="input" maxlength="256" name="name" data-name="Name" placeholder="Enter your name" id="name"><label for="email-3">Email Address:</label><input type="email" class="input" maxlength="256" name="email" data-name="email" placeholder="Enter your email" id="email-3" required=""><label for="question">Question:</label><input type="text" class="input" maxlength="256" name="question" data-name="question" placeholder="Enter your question" id="question" required=""><input type="submit" value="Submit" data-wait="Please wait..." class="contact-submit-button button" name="submit"></form>
<div class="form-done">
<div>Thank you! Your submission has been received!</div>
</div>
<div class="form-fail">
<div>Oops! Something went wrong while submitting the form.</div>
</div>
</div>
PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$question = $_POST['question'];
$mailTo = "info@bestsellerprime.com";
$headers "From: ".mailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n".$message;
mail($mailTo, $mailFrom, $txt, $headers);
header("Location: index.html")
}
任何帮助是极大的赞赏。
解决方案
代码中有一些语法错误。
=
缺少,mailFrom
应该$mailFrom
在以下行:
$headers "From: ".mailFrom;
此行末尾缺少分号:
header("Location: index.html")
正确代码:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$question = $_POST['question'];
$mailTo = "info@bestsellerprime.com";
$headers = "From: " . $mailFrom;
$txt = "You have received an e-mail from " . $name . ".\n\n" . $message;
mail($mailTo, $mailFrom, $txt, $headers);
header("Location: index.html");
}
推荐阅读
- html - 悬停效果结束后如何完成整个动画png?
- javascript - ASP.NET MVC 中的 GUID 模型绑定
- python - 有没有一种技术可以找到连接组件的厚度?
- django - Django 在模型中创建对象时定义 update_fields
- python - 如何将 Tkinter 条目放入 SQLite 数据库中?
- javascript - 如何下载 VoiceRSS API 请求的返回?
- angular - Ionic 5 角度自定义组件未显示
- r - 如何使用参数组合将 mapply 与长度不等的输入集一起使用?
- python - Python线程:如何限制活动线程数?
- java - 使用 VoiceInteractor 的代码时,应用程序因空指针异常而崩溃