我被一個客戶要求使用鏈接他們的聯繫表單到谷歌文檔。我有一個一步步顯示我做了什麼的視頻,但是當我提交表單時,有一個重定向到正在處理的頁面,並且沒有響應發送到表單文件。我會後的代碼的代碼:在大小寫爲您分配所有的POST陣列我試過了 - 單頁html與PHP與谷歌formscontact形式
<div class="col-md-9 col-xs-12 forma">
<!--<form id="form" action="MWSContact.php" method="POST" enctype="text/plain">-->
<!--
<fieldset>
<input type="text" class="col-md-6 col-xs-12 name" name='name' placeholder='Name *'/>
<input type="text" class="col-md-6 col-xs-12 Email" name='Email' placeholder='Email *'/>
<input type="text" class="col-md-12 col-xs-12 Subject" name='Subject' placeholder='Subject'/>
<textarea type="text" class="col-md-12 col-xs-12 Message" name='Message' placeholder='Message *'></textarea>
</fieldset>
<div class="cBtn col-xs-12">
<fieldset>
<input class="send" type="submit" value="Send" />
<input class="reset" type="reset" value="Reset" />
</fieldset>
</div> -->
<!-- </form>-->
</div>
<?
if (isset($_POST['email'])){
//Here is the email to info
$emial_to = 'email';
$email_subject = "MWS Contact";
$email_from = "Client";
//Error Code
function died ($error){
echo "We are sorry, but there were error (s) in your submitted form.";
echo "These errors appear below.<br/><br/>";
echo $error. "<br/><br/>";
echo "Please check your information again.<br/>";
die();
}
//Validation
if (!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message']) ||
!isset($_POST['subject'])){
died ('We are sorry but there appears to be a probem with your form submitted.');
}
//values
$name = $_POST['name'];
$email = $_POST['email'];
$message= $_POST['message'];
$subject = $_POST['subject'];
//error messages
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if (!preg_match($email_exp, $email)){
$error_message .= 'The Email address you entered does not appear to be valid. <br/>';
}
$string_exp = "/^[A-Za-z.'-]+$/";
if (!preg_match($string_exp, $name)){
$error_message .= 'The name you endtered does not appear to be valid. <br/>';
}
if (strlen($message) <2){
$error_message .= 'The comment you entered does not appear to be valid.<br/>';
}
if (strlen($email_message) >0){
died($error_message);
}
//Sanitize
$email_message = "Form Details Below\n\n";
function clean_string($string){
$bad = array("content-type", "bcc:", "to:", "cc:", "href");
return str_replace($bad," ", $string);
}
$email_message .="Name:" . clean_string($name) . "\n";
$email_message .="Email:" . clean_string($email) . "\n";
$email_message .="Subject:" . clean_string($subject) . "\n";
$email_message .="Message:" . clean_string($message) . "\n";
"\n";
//headers
$headers = 'From: ' .$email_From . "\r\n". 'Reply-To:' . $email. "\r\n" . 'X-Mailer: PHP/' .phpversion();
@mail ($email_to, $email_subject, $email_message, $headers);
}
?>
Thank you for contacting us. We will be in contact with you shortly.
'電子郵件'和'電子郵件'是兩個不同的動物,檢查所有的輸入和POST數組。錯誤報告是你的朋友http://php.net/manual/en/function.error-reporting.php - 並刪除'@'符號,這是一個錯誤抑制器。 –
另外,您的表單的代碼已被註釋掉,*爲什麼? –
因爲我從這個代碼中測試了Google表單方法,但是使用電子郵件或帶有gmail的電子郵件會有所不同嗎? –