[英]PHP form processor script not redirecting
我正在用PHP處理器腳本制作html聯系人表格。 這是我的代碼
HTML
<form enctype="multipart/form-data" action="contactprocessor.php" method="post" class="wpcf7-form" onSubmit="return validatePage1();">
<div class="form-row">
<label class="label">Name*</label>
<span class="wpcf7-form-control-wrap name">
<input type="text" id=field_1 name=field_1 value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required text-input" aria-required="true" placeholder="Introduce yourself" />
</span></div>
<div class="form-row">
<label class="label">Company</label>
<span class="wpcf7-form-control-wrap company">
<input type="text" name=field_2 id=field_2 value="" size="40" class="wpcf7-form-control wpcf7-text text-input" placeholder="Fly your company flag" />
</span></div>
<div class="form-row">
<label class="label">Email* </label>
<span class="wpcf7-form-control-wrap email">
<input type="email" name=field_3 id=field_3 value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email text-input" aria-required="true" placeholder="Help us keep in touch" />
</span></div>
<div class="form-row">
<label class="label">Phone</label>
<span class="wpcf7-form-control-wrap phone">
<input type="tel" name=field_4 id=field_4 value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-tel wpcf7-validates-as-tel text-input" placeholder="If you fancy a chat" />
</span></div>
<div class="form-row">
<label class="label">Subject*</label>
<span class="wpcf7-form-control-wrap subject">
<input type="text" name=field_5 id=field_5 value="" size="40" class="wpcf7-form-control wpcf7-text text-input" placeholder="What’s on your mind?" />
</span></div>
<div class="form-row">
<label class="label">Message*</label>
<span class="wpcf7-form-control-wrap message">
<textarea name=field_6 id=field_6 cols="40" rows="14" class="wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required" aria-required="true" placeholder="Share your thoughts and comments"></textarea>
</span></div>
<div class="form-row">
<input id="saveForm" type="submit" value="Get In Touch" class="wpcf7-form-control wpcf7-submit btn--invert" />
</div>
</form>
這是contactprocessor.php代碼
<?php
mail("jen@abhayayks.com",$_POST['field_5'],
"Form data:
Name: " . $_POST['field_1'] . "
\nEmail: " . $_POST['field_3'] . "
\nPhone : " . $_POST['field_4'] . "
\nCompany : " . $_POST['field_2'] . "
\nMessage : " . $_POST['field_6'] . "
");
header("Location: contact.php");
?>
現在,當我提交表單時,我收到確認PHP腳本正在工作的郵件。 但是我沒有重定向回contact.php(我也嘗試過使用index.php甚至http://www.google.com )。 您能指出錯誤嗎?
編輯:現在,我從php.ini文件打開了錯誤日志和錯誤報告,重新啟動了本地服務器,運行了腳本,收到了郵件,再次沒有重定向,錯誤日志文件中沒有錯誤。 我已將文件上傳到在線服務器上。 您可以確認問題。 鏈接
編輯2我只是注意到,除了郵件功能之外,其他任何功能都沒有起作用。 我的意思是嘗試使用
echo '<script type="text/javascript">window.onload = function(){ alert("Thank you");}</script>';
而且這也不起作用。 我也嘗試過使用include(“ confirm.html”);包含其他文件。 並且該文件未包含在內。
標題( “位置:contact.php”); 應該是header(“ Location:contact.php”);
似乎代碼是正確的
您檢查錯誤日志了嗎?
您的文件使用哪種字符集編碼? (當BOM表轉到輸出流后瀏覽器無法發送標頭時,如果文件是帶有BOM表的 UTF-8 ,則會出現問題)
請嘗試下面的代碼,您需要在Location:和Contact.php之間留出空格
<?php
header("Location: contact.php");
exit();
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.