简体   繁体   中英

submit form and load new page

I'm trying to get a JQM page to send an email via a form and then redirect to a new page. I have the mail part working fine, but the redirect not so much! After the form has been submitted and mail sent, the page basically just refreshes instead of loading the new page. I've tried many different things using the code header('Location:myredirectpage'); but nothing works.

The following php code is located below my closing HTML tag at the bottom of my page.

<?php

if(isset($_POST['mr'])) { 

    $to = "myemailaddress";
    $subject = "Subject";
    $content = ""
                    ."Survey Details"."\n\n"
                    ."How did you hear about us: ".$_POST['mr']."\n";

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "From: <myemailaddress>\r\n";

    mail($to, $subject, $content, $headers);

    $sendit= @mail($to, $subject, $content, $headers);

    if($sendit){

      header('Location:myredirectpage');

    }else{ echo "Email failed to send";}
}

?>

To redirect your page after it has been sent, you need something in the following format:

header('Location: index.php');

Change index.php to the FILENAME of what you want to get to.

This can be a full URL such as http://google.com

You are sending the mail twice : mail(...) then @mail(...) . Also using @mail(...) with @ is considered bad practice.

Instead of header('Location:myredirectpage'); use

echo '<script>window.location = 'yourpage'</script>'

Try this

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