[英]Contact form: not receiving e-mail
我正在制作唱片公司的官方網站,並且剛剛到達它的聯系頁面。 我曾嘗試以其他方式進行設置,但沒有獲得積極的結果就尋求Google的幫助! 在這里,您可以看到我實際使用的聯系表的php部分:
<?php
$name=$_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$subject = $_REQUEST['subject'];
$from = 'From: my website name';
$to = 'my@email.com';
$subject = 'New message from the Website!';
$body = "From: $name\n Subject:\n $subject E-Mail: $email\n Message:\n $message ";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
//redirect to the 'thank you' page
header('Location: contact.html');
?>
這是HTML表單:
<form role="form" action="send.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="name">name</label>
<input type="name" id="name" placeholder="Your Name *">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" placeholder="Your Email *">
</div>
<div class="form-group">
<label for="subject">Subject</label>
<input type="text" placeholder="Subject" id="subject">
</div>
<div class="form-group">
<label for="message">message</label>
<textarea id="message" cols="30" rows="7" placeholder="Message"></textarea>
</div>
<div class="form-group">
<label for="text" >*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="2 + 2 =">
</div>
<button type="submit" class="btn-default">Send it</button>
</form>
我怎么了
您正在要求從未設置的$_POST['submit']
,因為表單的輸入字段或按鈕都沒有命名為“ submit”。
將按鈕更改為:
<input type="submit" class="btn-default" name="submit" value="Send it">
或設置一個名為Submit的隱藏字段:
<input type="hidden" name="submit" value="value">
然后您的重定向將失敗,並顯示“已發送標頭”錯誤,因為在header()
調用之前您必須沒有輸出。 將header()
調用放在if($_POST['submit'])
的else
部分中
其他所有輸入字段也是如此。 名字不見了。 而是使用名稱作為類型。 類型在任何地方都應該是“文本”。
首先嘗試使用具有對mail()函數的硬編碼參數的普通函數,確保已收到它。
例如:
mail('your@email.com', 'hi', 'hello', 'from@email.com');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.