首页 > 解决方案 > 执行 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")
}

任何帮助是极大的赞赏。

标签: phphtmlformsreroute

解决方案


代码中有一些语法错误。

=缺少,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");
}

推荐阅读