-1
我一直在淘汰過去五個小時的無數其他php聯繫表單問題,並且無法爲我的生活弄清楚爲什麼我的工作不正常。除了來自Codecademy的一些「課程」外,我是PHP的總新手。所以 - 這就是我們所擁有的。單頁HTML文件。這裏的形式:簡單的PHP聯繫表格失敗
<div id="contact-form-section">
<div class="status alert alert-success" style="display: none"></div>
<form id="contact-form" class="contact" name="contact-form" method="post" action="send-mail.php">
<div class="form-group">
<input type="text" name="name" class="form-control name-field" required="required" placeholder="Your Name"></div>
<div class="form-group">
<input type="email" name="email" class="form-control mail-field" required="required" placeholder="Your Email">
</div>
<div class="form-group">
<input type="text" name="tel" class="form-control" required="required" placeholder="Your Phone Number">
</div>
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
</div>
而這裏的PHP,用電子郵件,我想送由[email protected]更換。試圖從其他一些教程中弄清楚它們是如何工作的。想要讓提交按鈕觸發警報,然後返回索引頁面。
<?
$name=$_POST['name'];
$Email=$_POST['email'];
$tel=$_POST['tel']
$website=$_POST['url'];
$message=$_POST['message'];
$body .= "Name: " . $name . "\n";
$body .= "Email: " . $Email . "\n";
$body .= "Telephone: " . $tel . "\n";
$body .= "Website: " . $website . "\n";
$body .= "Message: " . $message . "\n";
//Receiving email
mail("[email protected]","New email",$body);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>alert("Your message has been sent successfully. We will contact you shortly.");</script>
<meta HTTP-EQUIV="REFRESH" content="0; url=index.html">
</head>
我在做什麼錯在這裏?每當我點擊提交按鈕,它將我帶到我的send-mail.php頁面,但沒有通知出現,並且電子郵件不發送。我非常感謝任何幫助,我知道這些問題在Stack中出現得太頻繁 - 就像我說的,我花了五個小時篩選聯繫表單問題,試圖弄清楚我在這裏弄了些什麼。
* *「在你有<那一刻,它應該是
另一個問題是$ body。=「Name:」。 $名稱。 「\ n」 個;應該是$ body =「Name:」。 $名稱。 「\ n」 個;第一個等號不應該在它前面有一個點。 – Kobbe
@Fred cos其良好的做法 - 如此處所述:(php.net/manual/en/language.basic-syntax.phptags.php) - PHP也允許短打開標籤<? (因爲它只有在使用short_open_tag php.ini配置文件指令啓用時纔可用,或者使用--enable-short-tags選項配置了PHP),因此這是不鼓勵的。 – gavgrif