php - 提交按钮进入白屏
问题描述
我已经制作了一个联系表格,当点击提交并填写完整的表格时,屏幕只是变白,页面上的链接从contact.html变为contactform.php。
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "email@outlook.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
?>
<div>
<img src="images/contact.jpg" alt="" class="background-contact">
<div class="contact-box">
<br>
<p class="contact-text-tp">Email</p>
<form class="contact-form" action="contactform.php" method="post">
<br>
<input type="text" name="name" placeholder="Full name">
<br>
<input type="text" name="mail" placeholder="Your email">
<br>
<input type="text" name="subject" placeholder="Subject">
<br>
<textarea name="message" placeholder="Message"></textarea>
<br>
<button type="submit" name="Submit">Send email</button>
</form>
<br>
<p class="contact-text-btm">If you would like to directly email please use; <br> email@outlook.com</p>
</div>
</div>
解决方案
因此,首先您需要将页面从 to 重命名contact.html
并contact.php
更改您的代码,如下所示
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "email@outlook.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an email from ".$name.".\n\n".$message;
if(mail($mailTo, $subject, $txt, $headers)){
echo 'success';
}else{
echo 'failure';
}
}
?>
<div>
<img src="images/contact.jpg" alt="" class="background-contact">
<div class="contact-box">
<br>
<p class="contact-text-tp">Email</p>
<form class="contact-form" action="" method="post">
<br>
<input type="text" name="name" placeholder="Full name">
<br>
<input type="text" name="mail" placeholder="Your email">
<br>
<input type="text" name="subject" placeholder="Subject">
<br>
<textarea name="message" placeholder="Message"></textarea>
<br>
<button type="submit" name="Submit">Send email</button>
</form>
<br>
<p class="contact-text-btm">If you would like to directly email please use; <br> email@outlook.com</p>
</div>
</div>
推荐阅读
- html - HTML
- c# - 如何在 Xamarin.Forms 中使用 ContentProperty?
- sql - 将连接中的逗号分隔值插入特定列
- javascript - 对象数组中的特定数据
- wordpress - woocommerce REST API 请求购买单品
- sympy - 为什么 sympy count_ops() 因集成而失败?
- php - 仅使用 PHP 列出来自 FTP 服务器的文件夹
- python-3.x - TensorFlow 中更快的 K-Means 聚类
- sql - SQL 查询未返回预期结果
- php - 未定义函数 mssql_connect() Codeigniter 3.0 + Azure 数据库 + 000webhost + PHP 5.6