0

基本上下面的代码是一个查询表单,当网站用户填写时,它会将电子邮件发送到我的电子邮件地址。但是有些东西不起作用...

这是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');

它完美地发送了一封基本的电子邮件。

在所有情况下都会出现查询已发送警报。

有谁知道为什么它不起作用?

4

2 回答 2

1

运行 avar_dump(get_defined_vars());并确保它们已设置。还要检查PHP 或 Apache 用户/var/mail/user在哪里user,并查看更多操作系统级别引发的错误。

于 2012-08-25T23:30:20.507 回答
0

1-确切地说,你得到了什么?是空邮件还是根本没有邮件?

2-尝试调试你的 $_POST,就像 user1593858 说的那样。在 php 开始标记之后添加以下内容:

echo "<pre>";
print_r($_POST);
echo "</pre>";

看看你的字段是否正确。

3-你说如果你这样做:

$mail_status = mail($mail_to, 'subject', 'body_message', 'headers');

有用; 尝试用 'subject'$subject或 'body_message' 代替,$body_message直到你找出问题所在。

于 2012-08-25T21:09:25.957 回答