我想使用php邮件功能创建联系表单。我正在使用Xampp。我在htdocs中有这两个文件。
sample.html
<html>
<form action="contact.php" method="post">
Your name
<input type="text" name="cf_name"/>
Your e-mail
<input type="text" name="cf_email"/>
Message
<input type="text" name="cf_message"/>
<input type="submit" value="Send"/>
<input type="reset" value="Clear"/>
</form>
</html>
contact.php
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_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
}
?>
我没有收到电子邮件。任何人都可以在我出错的地方帮助我吗?