1
我用下面的標記:引導提交表單PHP和讀取返回的XML
<form action="http://mysite.com/contactmail.php" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Contact us</legend>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" title="inputName" for="inputName">Name</label>
<div class="controls">
<input type="text" required class="span3" id="Name" placeholder="Name">
</div>
<label class="control-label" title="inputEmail" for="inputEmail">E-mail</label>
<div class="controls">
<input type="email" required class="span3" id="inputEmail" placeholder="E-mail">
</div>
<label class="control-label" title="inputMessage" for="inputMessage">Message</label>
<div class="controls">
<textarea rows="3" required class="span5" id="inputMessage" placeholder="Message"></textarea>
</div>
<button type="submit" class="btn">Send</button>
</div>
</fieldset>
</form>
而下面contactmail.php:
<?php
$Name = htmlspecialchars($_GET['inputName']);
$Email = htmlspecialchars($_GET['inputEmail']);
$Message=htmlspecialchars($_GET['inputMessage']);
$to="[email protected]";
$subject="Contact form";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $Name <$Email>\r\n";
// $headers .= "Reply-To: $to\r\n";
$SendState = mail($to, $subject, $Message, $headers);
if ($SendState) {
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<mailer>
<response>'Success'</response>
<comment>'Message send'</comment>
</mailer>
XML;
}
else {
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<mailer>
<response>'Failed'</response>
<comment>'An unknown error occurred'</comment>
</mailer>
XML;
};
echo $xmlstr;
?>
更新,我調整了PHP文件如下,但我沒有在原始頁面上顯示結果:
if ($SendState) {
print "<html><div class=\"alert alert-success\">Message sent successfully</div></html>";
}
else {
print "<html><div class=\"alert alert-error\">Failed: An Error occured</div></html>";
};
?>
當我點擊提交按鈕時,發送一封電子郵件,但沒有任何數據。我看到了XML,但我希望用戶留在頁面上,並在該頁面發送失敗時向其發送錯誤消息,並在發送時向其發送綠色成功消息。
所以問題是,我做錯了什麼,我該如何傳遞數據? 如何處理返回的XML?
謝謝,任何線索爲什麼數據不發送? – Diego
仍然沒有數據,我在聯繫人頁面上沒有收到錯誤消息,但帶有消息「消息已成功發送」的新頁面打開。 – Diego
我可以知道您期待的數據嗎?您是否在談論郵件或屏幕輸出?對於您的上述代碼,HTML輸出將只能成功發送消息。 – Saravanan