2017-05-03 48 views
0

所以,我试了一下。硬。 并没有找到答案。 所以,这是我的问题。 我对我一直在努力的HTML项目有以下代码。Sublime文本如何用HTML编译php?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head> 
 
<title>Feedback Form</title> \t 
 
</head> 
 
<body> 
 
<h1>Send Us Your Feedback!</h1> 
 
<form action="send_mail.php" method="post"> 
 
<table> 
 
<tr> 
 
<td>Email Adress:</td> 
 
<td> 
 
<input type="text" name="email_address" value="" maxlength="100" /> 
 
</td> 
 
</tr> 
 
<tr> 
 
<td>Comments:</td> 
 
<td> 
 
<textarea rows="10" cols="50" name="comments"></textarea> 
 
</td> 
 
</tr> 
 
<tr><td>&nbsp;</td> 
 
<td> 
 
<input type="submit" value="Submit" /> 
 
</td> 
 
</tr> 
 
</table> 
 
</form> 
 
</body> 
 
</html>

而且,(即使你不能看到实际的页面),我尝试添加在PHP这样它会送我发邮件,每当有人估算所需的元素。我把所有的代码,

<?php 
 
/* 
 
This first bit sets the email address that you want the form to be submitted to. 
 
You will need to change this value to a valid email address that you can access. 
 
*/ 
 
$webmaster_email = "[email protected]"; 
 

 
/* 
 
This bit sets the URLs of the supporting pages. 
 
If you change the names of any of the pages, you will need to change the values here. 
 
*/ 
 
$feedback_page = "feedback_form.html"; 
 
/* 
 
This next bit loads the form field data into variables. 
 
If you add a form field, you will need to add it here. 
 
*/ 
 
$email_address = $_REQUEST['email_address'] ; 
 
$comments = $_REQUEST['comments'] ; 
 

 
/* 
 
The following function checks for email injection. 
 
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list. 
 
*/ 
 
function isInjected($str) { 
 
\t $injections = array('(\n+)', 
 
\t '(\r+)', 
 
\t '(\t+)', 
 
\t '(%0A+)', 
 
\t '(%0D+)', 
 
\t '(%08+)', 
 
\t '(%09+)' 
 
\t); 
 
\t $inject = join('|', $injections); 
 
\t $inject = "/$inject/i"; 
 
\t if(preg_match($inject,$str)) { 
 
\t \t return true; 
 
\t } 
 
\t else { 
 
\t \t return false; 
 
\t } 
 
} 
 

 
// If the user tries to access this script directly, redirect them to the feedback form, 
 
if (!isset($_REQUEST['email_address'])) { 
 
header("Location: $feedback_page"); 
 
} 
 

 
// If the form fields are empty, redirect to the error page. 
 
elseif (empty($email_address) || empty($comments)) { 
 
header("Location: $error_page"); 
 
} 
 

 
// If email injection is detected, redirect to the error page. 
 
elseif (isInjected($email_address)) { 
 
header("Location: $error_page"); 
 
} 
 

 
// If we passed all previous tests, send the email then redirect to the thank you page. 
 
else { 
 
mail("$webmaster_email", "Feedback Form Results", 
 
    $comments, "From: $email_address"); 
 
header("Location: $thankyou_page"); 
 
} 
 
?>

。但我不知道如何做的是使代码工作的两件一起。帮帮我? (基本上,你如何将PHP文档连接到HTML文件,如js?)

+0

您可以使用AJAX/XHR(JS),或者您可以将您的HTML文档重命名为.php文件,并简单地将该PHP代码添加到'<!DOCTYPE HTML>' –

+0

之前。如果它使用POST请求,或AJAX/XHR是最有可能的必要。 –

+0

问题是,如果我这样做,它只显示代码,而不是页面。 –

回答

-1

您可以复制并粘贴html代码(可能位于顶部的某个位置)的php代码并将文件扩展名从.html更改为.php,然后与任何托管网站与PHP功能主机。

+0

谢谢。它有点工作,只是把我送到一个写有代码的页面。那是什么应该发生的? –