PHP if / else语句似乎无法通过电子邮件与我们联系

时间:2012-11-17 22:08:49

标签: statements

我创建了一些if / else语句,以便在用户点击时进行下载 但是不行,因为你可以直接下载没有字段名称或电子邮件,请帮助我 联系。我的网站的PHP http://my-easy-woodworking-projects.com

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'lulu@yahoo.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>

var str = "download";
document.write(str.link("http://www.myshedplans.com/12BY8SHED.pdf"));

</script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to gordon@template-help.com');
        window.location = 'contact_page.html';
    </script>
<?php
}
?>

1 个答案:

答案 0 :(得分:0)

我不太确定为什么if / else不能为你工作但是有一件事情可能发生在解释器忘记if语句到达else时。解决这个问题的一种方法是在条件块中回显你的html代码,如下所示:

<?php
    if ($mail_status) {
        echo "<script>";
        echo "var str = \"download\";";
        echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));";
        echo "</script>";
    }
    else {
        echo "<script language=\"javascript\" type=\"text/javascript\">";
        echo "alert('Message failed. Please, send an email to gordon@template-help.com');";
        echo "window.location = 'contact_page.html';";
        echo "</script>";
    }
?>