-1

我创建了一些 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
}
?>
4

1 回答 1

0

我不太确定为什么 if/else 对您不起作用,但可能发生的一件事是解释器在遇到 else 时忘记了 if 语句。解决此问题的一种方法是在条件块中回显您的 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>";
    }
?>
于 2012-11-17T22:39:01.913 回答