【发布时间】:2015-04-22 11:38:00
【问题描述】:
我有以下代码,取自基本 html 联系表单的 php 端:
<?php
session_start();
if(isset($_POST['fullname_1'])) {
include 'formsettings.php';
function died($error) {
echo "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();
}
if(!isset($_POST['fullname_1']) || !isset($_POST['fullname_1'])) {
died('Sorry, there appears to be a problem with your form submission.');
}
$name_from = $_POST['fullname_1']; // required
$ip = $_SERVER['REMOTE_ADDR'];
$error_message = "";
$email_message = "Form details below.\r\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "Full name is: ".clean_string($name_from)."\r\n";
$email_message .="IP Address: ".clean_string($ip)."\n\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
它采用输入全名的文本框 fullname_1 的值并发送电子邮件。并在点击提交后将用户带到感谢页面。
但是我想添加一个条件,它根据输入的文本的前三个字母来决定感谢页面,所以我有以下代码:
$value = substr($name_from,0,3);
if (strtolower($value) === "abc"){
$thankyou = "../abc.html"; // male
}
elseif($value === "def"){
$thankyou = "../def.html"; // female
}
else{
$thankyou = "../xyz.html"; // no male, no female
}
当我添加此代码时,脚本停止运行。任何帮助,将不胜感激。谢谢。
【问题讨论】:
-
你遇到了什么错误
-
没有错误,联系表单转发到php页面而不是感谢页面。