Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
电子邮件表单显示PHP内容,而不是执行和发送电子邮件_Php_Html Email - Fatal编程技术网

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

电子邮件表单显示PHP内容,而不是执行和发送电子邮件,php,html-email,Php,Html Email,我正试图在我的网站上创建一个“联系我们电子邮件表单”,但当我按下“发送”按钮时,它不会发送电子邮件,并且显示了应该发送的.php文件的全部内容?有人能帮我吗?我的html页面名为“Contact_Us.html”,PHP文件名为“Contact.PHP” 这是HTML <form action="contact.php" method="post"> Your name<br> <input type="text" name="cf_

我正试图在我的网站上创建一个“联系我们电子邮件表单”,但当我按下“发送”按钮时,它不会发送电子邮件,并且显示了应该发送的.php文件的全部内容?有人能帮我吗?我的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
}
?>

警报('谢谢,我们已收到您的消息。我们将很快与您联系!');
window.location='Contact_Us.html';
警报('消息失败。请发送电子邮件至thenewmostonclub@outlook.com抱歉给您带来不便);
window.location='Contact_Us.html';

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

似乎php没有正确配置。同意@ShankarDamodaran,它看起来像是您的
。php
没有被任何php解释器处理,因此它被视为静态文件(
.html
或纯文本文件),并按原样传递到浏览器。我明白了!唯一的问题是我对PHP还不熟悉,我从来没有真正研究过它我只想让一个电子邮件表单正常工作,现在我被它弄得不知所措!