0

I try to put script to send an email and redirect to main page. yes, it's work! but...

On IE, it doesn't work.

code example:

<?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    //$email_to1 = "[email protected]";
    $email_to2 = "[email protected]";
    $email_subject = "Email from www.abc.com";         
    ................
    ................                  
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    //@mail($email_to1, $email_subject, $email_message, $headers);
    @mail($email_to2, $email_subject, $email_message, $headers);
    header("Refresh: 3; http://www.abc.com/Contact.html");
?>

<!-- include your own success html here -->

    Thank you for contacting us. We will be in touch with you very soon.<br>
    <a href="http://www.abc.com/Contact.html">back to website</a>
<?php
}
?>

How could i solve it?

4
  • Did you try to exit the script after the header function with exit(); ? Mar 21, 2013 at 8:50
  • 1
    use the ones found here: en.wikipedia.org/wiki/Meta_refresh (<meta refresh ... ) . and please place them at the correct place (html header)
    – Najzero
    Mar 21, 2013 at 8:52
  • @Stoyan Dimov yes, try.
    – fronthem
    Mar 21, 2013 at 9:00
  • Then use header: location see the answer of @Praveen kalal Mar 21, 2013 at 12:13

3 Answers 3

2

Please use below code

  header('Location:http://www.abc.com/Contact.html')
    exit;
1
  • As example i shown you a code is already worked on Chrome, Firefox. But didn't work on IE even exit; is added.
    – fronthem
    Mar 21, 2013 at 9:11
0

Use this code instead

die(header('Location:http://www.abc.com/Contact.html'));

You can omit die(), but is useful here, because using it allows to prevent script running after sending redirect header.

2
  • Then you should try to use step-by-step check. Comment header line and put this line in place: die('mail sent with '.(bool)$mailSentRes.' result'); just to be sure that you getting this point in your script.
    – Denis O.
    Mar 21, 2013 at 9:39
  • It's not a good idea to shut up mail() with @. Maybe it have something to say you.
    – Denis O.
    Mar 21, 2013 at 9:45
0

Change

header("Refresh: 3; http://www.abc.com/Contact.html");

into

header("Refresh: 3; URL=http://www.abc.com/Contact.html");

I think that should do the trick

Also take note of this answer: 'Refresh' HTTP header and this comment: 'Refresh' HTTP header

1
  • This helped me fix a problem I was having. Evidently IIS was messing up the redirect for IE browsers. The Refresh method worked while the Location method didn't.
    – dVyper
    Jul 29, 2016 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.