这是交易: 我设法通过创建重定向到索引的2个html页面来使这个sendmail.php工作。 但我想要的是(if($ sent)== true)在html表单页面上显示已发送消息的警报。但是当我改变时
{echo "<script language=javascript>window.location = '/sent.html';</script>";}
到
{echo "<script language=javascript>window.alert = 'Message Sent';</script>";}
页面重定向到... url ... com / sendmail.php为空白
现场直播@ www.aroundgalaxy.pt/NEW
这里是表格html
<form action="sendmail.php" method="post">
<div>
<div class="row half">
<div class="6u">
<input type="text" class="text" name="name" placeholder="Nome" />
</div>
<div class="6u">
<input type="text" class="text" name="email" placeholder="E-mail" />
</div>
</div>
<div class="row half">
<div class="12u">
<input type="text" class="text" name="subject" placeholder="Assunto" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Messagem"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Enviar" />
</div>
</div>
</div>
</form>
和sendmail.php
<?php
$to = "info@aroundgalaxy.pt";
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
//$site = $_REQUEST['site'] ;
$subject = "Message from: $name";
$message = $_REQUEST['message'] ;
$headers = "noreply@aroundgalaxy.pt";
$body = "From: $name \n\n Email: $email \n\n Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = '/sent.html';</script>";}
else
{echo "<script language=javascript>window.location = '/notsent.html';</script>";}
?>
答案 0 :(得分:2)
alert()not alert =。
{echo "<script language=javascript>window.alert('Message Sent');</script>";}
答案 1 :(得分:1)
如果您想要替代方案,请尝试以下方法:
在sendmail.php中添加以下内容:
sendmail.php:
setcookie("msg","Mail Successfully Sent",time()+5,"/");
header("location:htmlpage.php");
并在htmlpage.php
<?php if(isset($_COOKIE['msg'])){?>
<div>
<?php echo $_COOKIE['msg'];setcookie("msg","",time()-5,"/");?>
</div>
<?php }?>