嘿那裏:)第一次使用本網站。Php聯繫表格問題
我是新來的php,DW和我在Imac上工作。我一直在努力工作兩天以獲得一個concact表單。我希望它在我們收到郵件時向我的Gmail或我們的公司電子郵件發送一封電子郵件。
我把它上傳到FTP服務器,但是當我在數據類型我得到這個:
服務器錯誤 405 - HTTP動詞用於訪問此頁面是不允許的。 您正在查找的頁面無法顯示,因爲使用了無效方法(HTTP動詞)來嘗試訪問。
我真的希望你們能幫助我,在一些容易理解的術語:P
我的HTML:
<h2>Kontakt os</h2>
<form class="form" name="contactform" method="post" action="php/send_form_email.php">
<p class="name">
<input type="text" name="first_name" maxlength="50" size="30" placeholder="Fornavn:">
<label for="first_name"></label>
</p>
<div class="seperator1"></div>
<p class="lastname">
<input type="text" name="last_name" maxlength="50" size="30" placeholder="Efternavn:">
<label for="last_name"></label>
</p>
<div class="seperator1"></div>
<p class="email">
<input type="text" name="email" maxlength="80" size="30" placeholder="Email:">
<label for="email"></label>
</p>
<div class="seperator1"></div>
<p class="phone">
<input type="text" name="telephone" maxlength="30" size="30" placeholder="Tlf:">
<label for="telephone"></label>
</p>
<div class="seperator1"></div>
<p class="text">
<textarea name="text" placeholder="Skriv til os her" /></textarea>
<label for="text"></label>
</p>
<p class="submit">
<input type="submit" value="Submit">
</p>
</form>
我的PHP代碼:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "Mysole";
function died($error) {
// your error code can go here
echo "Undskyld, men det ser ud til der er sket en fejl.";
echo "Fejl står nedeunder.<br /><br />";
echo $error."<br /><br />";
echo "Gå venligst tilbage for at rette fejlen.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['text'])) {
died('Undskyld, men det ser ud til der er sket en fejl.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['text']; // required
$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_from)) {
$error_message .= 'Forkert email adresse.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'Forkert fornavn.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'Forkert efternavn.<br />';
}
if(strlen($text) < 2) {
$error_message .= 'Den tekst du har skrevet er ikke gyldig.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Text: ".clean_string($text)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Klik her <a href="../kontakt.html"></a> at komme tilbage til forsiden.
<?php
}
?>
名稱是什麼是'死()'功能? – samayo
@Simon_eQ據我所知,它是一個錯誤函數 – Perry
重命名你的HTML頁面,使其具有'.php'文件擴展 – AlexP