这是发送电子邮件的电子邮件
mail($ToID,$subject,$urltoemail,$headers);
发送后,用户被重定向
header("Location:".$_SERVER['SCRIPT_NAME']);
我必须在重定向的页面中显示“已成功发送邮件”的提醒。我怎么能?
代码摘录:
if(isset($_POST['submitbtn'])) {
$flag=true; $error="";
/*Getting Values**********************/
$ToID=$_POST['ToID'];
$fromID=$_POST['fromID'];
$subject=$_POST['subject'];
$URL=$_POST['URL'];
$message=$_POST['message'];
/*Validating the data*****************/
if(strlen($ToID)==0) {
$flag=false;
$error.="Enter To email address field";
} elseif(!preg_match_all("|^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$|U", $ToID, $arr)) {
$flag=false; $error.="Invalid To email address";
}
if($flag) {
$urltoemail = "<html><head><title>Forgot Password</title></head><body> <table><tr><td>".$message."</td></tr><tr><td><a href='{$URL}'>Click here for viewing map</a></td></tr></table></body></html>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
if(strlen($fromID)==0)
$fromID = 'info@cimaps.co.uk';
$headers .= 'From: '.$fromID. "\r\n";
mail($ToID,$subject,$urltoemail,$headers);
//$_SESSION['m'] = "item successfully deleted";
header("Location:".$_SERVER['SCRIPT_NAME']);
}
}
答案 0 :(得分:0)
您可以尝试在重定向的网址中包含变量,从而在页面上触发警报。使用
header("Location: ".$_SERVER['SCRIPT_NAME']. "?sent=1");
然后将其包含在某处:
if ($_GET["sent"]) {
echo '<script>alert("The email has been sent successfully.");</script>';
}
如果您愿意更改代码的结构,可以