0

我在http://www.brisbanediveacademy.com.au有一个使用 php 制作的联系表。在提交表单后,我试图让它重定向到 iframe 内的新页面。我目前无法将其重定向到任何地方。

这是我的PHP

<?php 
$errors = '';
$myemail = 'enquiries@brisbanediveacademy.com.au';
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$contact = $_POST['number'];
$inquiry = $_POST['inquiry'];  
$email_address = $_POST['email']; 
$message = $_POST['message']; 
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
     $errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Website contact Form Enquiry: $inquiry";
    $email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n Email: $email_address \n Contact Number:  $contact \n Message: \n $message"; 
    $headers = "From: $myemail\n"; 
    $headers = "Reply-To: $email_address";"\r\n";
    mail($to,$email_subject,$email_body,$headers);
} 
?>

任何帮助都会很棒。

谢谢

4

2 回答 2

0

在代码中,您应该有一个重定向代码,如下所示,

<?php
/* Redirect browser */
header("Location: http://www.brisbanediveacademy.com.au/");
?>
于 2012-10-18T06:52:17.380 回答
0

我可以看到这个错误报告

Warning: Cannot modify header information - headers already sent by (output started at /home/brisbane/public_html/contact/mail.php:9) in /home/brisbane/public_html/contact/mail.php on line 37

这意味着,之前的代码header('Location:..')具有某种面向输出的代码,例如回声。找到错误日志的设置,检查回显。最好您可以查看 mail.php 的第 37 行。这主要是因为您的 php conf 有 display_errors true 并且 error_reporting 设置为最低级别。因此,即使生成了 NOTICE,它也会在您执行之前设置标题。在之后添加这些行<?php

    error_reporting(E_ERROR);
    ini_set('display_errors','false');

即使只有第二行也可以。

编辑:正如您所问,使用这行代码可以进行重定向。

header("Location: url-to-redirect");

如果您的文件中没有这行代码,请确认您正在为您的要求做正确的事情。

希望这会有所帮助。

于 2012-10-18T06:20:57.060 回答