简体   繁体   中英

Contact Form iframe redirection

I have a contact form at http://www.brisbanediveacademy.com.au made using php. I'm trying to get it to redirect to a new page inside the iframe after the form has being submitted. I'm having trouble gettting it to redirect anywhere at the moment.

Here is my 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);
} 
?>

Any help would be great.

Thanks

I can see this error report

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

This means that, the code before header('Location:..') have some kind of output oriented code like an echo. Find your setting for error logs, check for echo. Preferably you can check on line 37 of mail.php. Mostly this will be because your php conf has display_errors true and error_reporting is set to lowest level. So even if a NOTICE is generated, it will set the header before you do. Add these lines at just after <?php

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

even the second line only will do.

EDIT: as you asked, the redirection is possible with this line of code.

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

if you don't have this line of code in your file, please verify that you are doing the right thing for your requirement.

Hopes this will help some way.

In the code you should have a redirection code something like following,

<?php
/* Redirect browser */
header("Location: http://www.brisbanediveacademy.com.au/");
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM