【发布时间】:2013-07-17 08:44:27
【问题描述】:
我想使用 PHP 邮件功能 创建一个联系表单。我正在通过在免费的网络托管服务提供商上开发来学习这个过程。这是我的文件:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 Contact Form</title>
<link rel="stylesheet" media="screen" href="styles.css">
</head>
<body>
<div id="contact">
<form class="contact_form" action="contact.php" method="post" name="contact_form">
<ul>
<li>
<h2>Contact Us</h2>
<span class="required_notification">* Denotes Required Field</span>
</li>
<li>
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="John Doe" required />
</li>
<li>
<label for="email">Email:</label>
<input type="email" name="email" id="email" placeholder="john_doe@example.com" required /> <span class="form_hint">Proper format "name@something.com"</span>
</li>
<li>
<label for="message">Message:</label>
<textarea name="message" id="message" cols="40" rows="6" required></textarea>
</li>
<li>
<button class="submit" id="submit_btn" type="submit">Submit Form</button>
</li>
</ul>
</form>
</div>
</body>
</html>
contact.php
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'babloopuneeth@gmail.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) {
?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'sample.html';
</script>
<?php
} else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon@template-help.com');
window.location = 'sample.html';
</script>
<?php
}
?>
我还有一个 styles.css 文件。我收到警告框说Thank you for the message。但我没有收到邮件。
谁能帮帮我?我哪里错了?
【问题讨论】:
-
你检查过你的垃圾文件夹吗?
-
签入
Spam folder。您是否从contact.php收到else part警报? -
@RohanKumar:我只注意到 if 部分。我什至检查了垃圾邮件文件夹。我没有收到。
-
看看mailq可能你的服务器没有配置
-
我们的答案是否解决了您的问题?如果有,请采纳! :)