2013-12-20 55 views
3

以下是處理: 我設法通過創建2個重定向到索引的html頁面來獲得此sendmail.php。 但我想要的是(if($ sent)== true)在html表單頁面上顯示該消息已發送的警報。但是,當我改變在不更改url的情況下發送表格

{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/新

這裏是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 = "[email protected]"; 
$email = $_REQUEST['email'] ; 
$name = $_REQUEST['name'] ; 
//$site = $_REQUEST['site'] ; 
$subject = "Message from: $name"; 
$message = $_REQUEST['message'] ; 
$headers = "[email protected]"; 
$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

合併爲H TML和PHP合併爲一個文件,然後將表單發佈到自身 – meda

+0

@meda將php代碼放置在html文件中? – willier

+2

爲什麼不使用'header('Location:/sent.html')'作爲重定向? – sjagr

回答

2

alert()not alert =。

{echo "<script language=javascript>window.alert('Message Sent');</script>";} 
+0

謝謝,讓它工作。語法錯誤hehe {echo'「;} – willier

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 }?> 
相關問題