我是php的初學者,我試圖編寫一個簡單的聯繫表單。我的問題是:我的代碼有什麼問題?我似乎無法找到格式化或什麼什麼錯誤......這是我的代碼:php聯繫表單代碼錯誤?
contact.php:
...page content...
<div class="contact">
<form action="send_mail.php" method="post">
<fieldset>
<label for="name">Name:</label>
<input type="text" name="name" placeholder="Enter your name" />
<label for="email">Email:</label>
<input type="email" name="email" placeholder="Enter your email address" />
<label for="message">Message:</label>
<textarea name="message" placeholder="What's on your mind?"></textarea>
<br>
<input type="submit" name="submit" value="Send message" />
</fieldset>
</form>
</div>
...page content...
send_mail.php:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: My website';
$to = '[email protected]';
$subject = 'My contact form message';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
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>';
}
}
?>
我正在「出錯了「的消息,這意味着郵件()返回false,但我不知道爲什麼。謝謝你的幫助!
您在'else {'底部附近有'反斜槓' – 2013-03-21 13:50:26
我更正了反斜槓,但錯誤仍然存在...但感謝通知 – Smajl 2013-03-21 13:52:09
電子郵件是否正在交付?標準的SMTP服務器是localhost。如果您還沒有更改SMTP服務器,那麼在同一臺計算機上是否有電子郵件服務器? – Joshua 2013-03-21 13:53:06