2017-05-03 4 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に接続しますか?)

+0

HTMLドキュメントの名前を.phpファイルに変更して、単に '<!DOCTYPE HTML>'の前にPHPコードを追加することができます –

+0

POSTリクエストを使用している場合、フォーム入力またはAJAX/XHRが最も必要な可能性があります。 –

+0

問題は、そうすると、ページではなくコードだけが表示されることです。 –

答えて

-1

PHPコードをHTMLコードの中にコピーして貼り付けて、ファイル拡張子を.htmlから.phpを実行し、php機能を持つ任意のホスティングサイトでホストします。

+0

ありがとうございます。それはコードを書いたページに私を送るだけの仕事のようなものです。それは何が起こるはずですか? –

関連する問題