基本上下面的代码是一个查询表单,当网站用户填写时,它会将电子邮件发送到我的电子邮件地址。但是有些东西不起作用...
这是php:
<?php
$field_name = $_POST['efName'];
$field_email = $_POST['efEmail'];
$field_phone = $_POST['efPhone'];
$field_date = $_POST['efTravelDate'];
$field_duration = $_POST['efLengthOfStay'];
$field_otherInfo = $_POST['efOtherInfo'];
$mail_to = 'James_Burnside94@hotmail.com';
$subject = 'Enquiry Applicant-'.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'Date: '.$field_date."\n";
$body_message .= 'Duration: '.$field_duration."\n";
$body_message .= 'otherInfo: '.$field_otherInfo."\n";
$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('Enquiry Sent.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Enquiry form failed to send. \n Please try again, or send an email to enquiry@cannes-rental-apartment.com');
window.location = 'index.html';
</script>
<?php
}
?>
这是 HTML 正文:
<body>
<fieldset style="display:block; width:500px;">
<form action="enquiry.php" method="post">
<table>
<tr> <td> <span class="enquiryFormHeader"> Enquiry Form </span> <p> </p></td> </tr>
<tr> <td> Name: </td> <td> <input type="text" name="efName" id="efName"> </td> </tr>
<tr> <td> Email: </td> <td> <input type="text" name="efEmail" id="efEmail"> </td> </tr>
<tr> <td> Phone or Moblie: </td> <td> <input type="text" name="efPhone" id="efPhone"> </td> </tr>
<tr> <td> Intended travel date: </td> <td> <input type="text" name="efTravelDate" id="efTravelDate"> </td> </tr>
<tr> <td> Intended length of stay: </td> <td> <input type="text" name="efLengthOfStay" id="efLengthOfStay"> </td> </tr>
<tr> <td valign="top"> Any other information: </td> <td> <textarea name="efOtherInfo" id="efOtherInfo"> </textarea> <p> </p> </td> </tr>
<tr> <td><input type="submit" value="Send Form" class="submitButton"> </td> </tr>
</table>
</form>
</fieldset>
</body>
如果我这样做 $mail_status = mail($mail_to, 'subject', 'body_message', 'headers');
它完美地发送了一封基本的电子邮件。
在所有情况下都会出现查询已发送警报。
有谁知道为什么它不起作用?