以下是處理: 我設法通過創建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>";}
?>
合併爲H TML和PHP合併爲一個文件,然後將表單發佈到自身 – meda
@meda將php代碼放置在html文件中? – willier
爲什麼不使用'header('Location:/sent.html')'作爲重定向? – sjagr