【发布时间】:2015-10-22 05:43:30
【问题描述】:
我有一个网页保存为contact_us.php,但是当我加载它(托管)它只是返回空白。
我在这里使用了代码(用绿色勾号和 23 票回答): Send email with PHP from html form on submit with the same script
我的代码(在页面顶部)是:
<?php
if(isset($_POST['submit'])){
$to = "abc123@hotmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
和(在体内):
<form action="" method="post">
First Name: <input type="text" name="first_name"><br><br>
Last Name: <input type="text" name="last_name"><br><br>
Email: <input type="text" name="email"><br><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br><br>
<input type="submit" name="submit" value="Submit">
</form>
有人可以看到任何错误吗?
我在 XAMPP 中对其进行了测试,它运行良好 - 发送 2 封电子邮件并说谢谢等,但是当我将它“激活”时,我得到了白屏死机?
【问题讨论】:
-
您是否为您的 PHP 代码开启了错误报告?
-
白屏死机通常意味着某处出现问题。如果您有权访问它们,请检查您的日志,和/或...在您的打开 PHP 标记之后立即将错误报告添加到文件顶部,例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);,然后是其余代码,以查看它是否产生任何东西。 -
代码没有问题,所以问题是基于主机的。检查服务器的错误日志。
标签: php html xampp contact-form