简体   繁体   English

将 PHP 文件链接到 HTML

[英]Link a PHP file into HTML

I am a newbie so not very sure about this :)我是新手,所以对此不太确定:)

So I have my project in HTML and a few stuff in a javascript separate file.所以我在 HTML 中有我的项目,在 javascript 单独文件中有一些东西。 All is linked and working.一切都相互关联并正常工作。 However I have created a form in my HTML and would like to be able to use it for the user to get in touch with me and receive the message to my email address.但是,我在我的 HTML 中创建了一个表单,并希望能够使用它让用户与我取得联系并通过我的电子邮件地址接收消息。

I have this code in a separate file called contact.php :我在一个名为contact.php的单独文件中有此代码:

<?php

if($_POST["submit"]) {
    $recipient="your@email.address";
    $subject="Form to email message";
    $sender=$_POST["sender"];
    $senderEmail=$_POST["senderEmail"];
    $message=$_POST["message"];

    $mailBody="Name: $sender\nEmail: $senderEmail\n\n$message";

    mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");

    $thankYou="<p>Thank you! Your message has been sent.</p>";
}

?>

However, I do not know how to link this file into my HTML?但是,我不知道如何将此文件链接到我的 HTML 中? is there anyone able to assist please?有没有人可以提供帮助?

Many thanks :))))非常感谢 :))))

You can't run PHP in .html files because the server does not recognize that as a valid PHP extension unless you tell it to.您不能在 .html 文件中运行 PHP,因为除非您告诉它,否则服务器不会将其识别为有效的 PHP 扩展名。 To do this you need to create a .htaccess file in your root web directory and add this line to it:为此,您需要在根 Web 目录中创建一个 .htaccess 文件并将以下行添加到其中:

AddType application/x-httpd-php .htm .html

This will tell Apache to process files with a .htm or .html file extension as PHP files.这将告诉 Apache 将具有 .htm 或 .html 文件扩展名的文件作为 PHP 文件处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM