首页 文章

如何在提交表单后从php页面重定向时在html页面中显示警告消息

提问于
浏览
0

我正在开发一个有订阅部分的html页面 . 用户将他/她的电子邮件放在输入字段中并提交 . 然后将控件转移到php页面,该页面将订阅消息通过电子邮件发送给网站管理员,如果消息发送成功,则导航回index.html . 现在,此时我想显示订阅成功或失败的警告消息 . 如何在不创建index.html index.php的情况下这样做 .

<?php

$to = "@gmail.com";
$from = "edmin.media@gmail.com";
$headers = "From: " . $from . "\r\n";
$subject = "New subscription";
$body = "Dear Admin!\nNew user subscription: " . $_POST['email'];

if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
    if (mail($to, $subject, $body, $headers, "-f " . $from)) {
        @header('location:index.html');
    } else {
        @header('location:index.html');
    }
} else {
    @header('location:index.html');
}

?>

1 回答

相关问题