【问题标题】:PHP Contact form issue - works in XAMPP not hostedPHP 联系表单问题 - 在未托管的 XAMPP 中工作
【发布时间】: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 标记之后立即将错误报告添加到文件顶部,例如 &lt;?php error_reporting(E_ALL); ini_set('display_errors', 1);,然后是其余代码,以查看它是否产生任何东西。
  • 代码没有问题,所以问题是基于主机的。检查服务器的错误日志。

标签: php html xampp contact-form


【解决方案1】:

我现在已经设法让它工作了(并且浪费了大量时间打电话给 Go Daddy 却无处可去)。

  • 我创建了一个新的.php文件名contact.php
  • 一步一步将代码从contact_us.php复制到contact.php,并在Go Daddy的服务器上对其进行测试以确保其正常工作。

唯一的区别是:

<!DOCTYPE html>
<html>

代替

<?xml version=”1.0” encoding=”UTF-8”?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

我还将 php 代码放在正文中,而不是放在文档顶部,但我怀疑这有什么不同。

那会有那么大的不同吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    相关资源
    最近更新 更多