显示电子邮件表单,PHP内容而不是执行和发送电子邮件

时间:2014-03-11 12:35:47

标签: php html-email

我试图联系我们的电子邮件表格'在我的网站上工作,但当我按下发送'按钮,它不发送电子邮件,它显示.sp文件的全部内容,应该发送?有人能帮帮我吗?我的html页面我打电话给' Contact_Us.html'并且PHP文件被称为' contact.php"。

这是HTML

<form action="contact.php" method="post">
        Your name<br>
        <input type="text" name="cf_name"><br>
        Your e-mail<br>
        <input type="text" name="cf_email"><br>
        Message<br>
        <textarea name="cf_message"></textarea><br>
        <input type="submit" value="Send">
        <input type="reset" value="Clear">
        </form>

这是.PHP

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

$mail_to = 'user@domain.com';
$subject = 'Message from a visitor on The New Moston Club Wesbite '.$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, we have received your message. We will contact you shortly!');
        window.location = 'Contact_Us.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to thenewmostonclub@outlook.com sorry for any inconvenience');
        window.location = 'Contact_Us.html';
    </script>
<?php
}
?>

1 个答案:

答案 0 :(得分:0)

是否会在您的浏览器中显示网址栏c:/ user /.../ yourscript.php如果是,请尝试localhost / yourscript.php