2015-07-02 62 views
0

我正在订阅部分的html页面上工作。用户将他/她的电子邮件放入输入字段并提交。然后该控件被转移到一个php页面,该页面将订阅消息通过电子邮件发送给网站管理员,如果消息成功发送,它将导航回index.html。现在在这一点上,我想显示一条警告消息,订阅成功或不成功。我怎么能做到这一点,而不使我的index.html index.php。如何在提交表单后从php页面重定向时在html页面中显示提醒消息

<?php 

$to = "@gmail.com"; 
$from = "[email protected]"; 
$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'); 
} 

?> 
+0

使用Ajax。通过这种方式,您可以将表单数据发送到您的php文件并根据响应显示警报。 – icecub

+0

*它导航回index.html成功或不成功的任何方式* –

+0

你能给我一小段代码吗? 因为我对阿贾克斯一无所知。 并且我可以通过ajax发送对html页面的响应吗? –

回答

相关问题