我正在嘗試爲使用Movable Type平臺的公司編寫聯繫表單。我正在創建頁面模板供他們使用。我95%確定我的php代碼和我的html對於表是正確的,並且引用對方 - 這不是問題的根源。但MT不會自動渲染php。相反,我得到了所有我的php文本的巨大塊。 HTML呈現很好。我不確定如何強迫MT識別php。我無法找到直接解決此問題的設置或任何內容。我可以在MT幫助/常見問題區域找到最接近的地方是here。但我嘗試過使用他們提供的代碼<$MTEntryText encode_php="here"$>
,但它完全不會改變頁面的呈現方式。下面是我嘗試使用的PHP,但我不認爲它是問題的根源。我想我應該包括它以防萬一。我只是想知道如何爲MT標記東西?我正在第一次使用Movable Type平臺,並且在第三個時間使用php,所以當解釋我失蹤的時候,請隨時與我談談,就像我是嬰兒一樣。php代碼中的可移動類型頁面模板
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "Web Contact Response";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
你猜對了我把php和.html文件擴展名放在哪裏。我即將離職,但我會明天嘗試解決第一件事,看看會發生什麼。 – ulalu