【发布时间】:2013-12-12 07:08:34
【问题描述】:
我正在尝试为一家使用 Movable Type 平台的公司编写联系表格。我正在创建页面模板供他们使用。我 95% 确信我的 php 代码和我的 html 对于表格是正确的并且相互引用——这不是问题的根源。但是 MT 不会自动渲染 php。相反,我得到了一大块我所有的 php 文本。 html 渲染得很好。我不确定如何强制 MT 识别 php。我找不到直接解决此问题的设置或任何内容。我在 MT 帮助/常见问题解答区域中找到的最接近的是 here。但我已经尝试使用他们提供的代码<$MTEntryText encode_php="here"$>,但它对页面的呈现方式完全没有任何改变。下面是我正在尝试使用的 php,但我认为这不是问题的根源。我想我应该包括它以防万一。我只是错过了如何为 MT 标记事物的要点吗?我是第一次在 Movable Type 平台上工作,第三次使用 php,所以在解释我所缺少的东西时,请随时像婴儿一样与我交谈。
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "blank@mydomain.com";
$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._%-]+@[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 movabletype