我正试图获得一个JQM页面,通过表单发送电子邮件,然后重定向到一个新页面。我的邮件部分工作得很好,但重定向没有那么多!提交表单并发送邮件后,页面基本上只是刷新,而不是加载新页面。我使用代码header('Location:myredirectpage');
尝试了许多不同的方法,但都不起作用。
以下php代码位于页面底部的关闭HTML标记下方。
<?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";}
}
?>
要在页面发送后重定向,您需要以下格式的东西:
header('Location: index.php');
将index.php更改为您想要访问的FILENAME。
这可以是一个完整的URL,例如http://google.com
您发送了两次邮件:mail(...)
和@mail(...)
。将@mail(...)
与@
一起使用也被认为是不好的做法。
使用而不是header('Location:myredirectpage');
echo '<script>window.location = 'yourpage'</script>'
试试这个