2017-05-03 30 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

謝謝。它有點工作,只是把我送到一個寫有代碼的頁面。那是什麼應該發生的? –