PHP联系方式是';首次安装时不工作
我刚刚安装了一个新的PHP联系人表单,但它不起作用。我已经试过修了,但我不知道怎么修。谁能看一下给我修一下吗? PHP代码:PHP联系方式是';首次安装时不工作,php,Php,我刚刚安装了一个新的PHP联系人表单,但它不起作用。我已经试过修了,但我不知道怎么修。谁能看一下给我修一下吗? PHP代码: $to = 'email@hotmail.com'; $subject = 'Contact'; $contact_submitted = 'Your message has been sent.'; function email_is_valid($email) { return preg_match(
$to = 'email@hotmail.com';
$subject = 'Contact';
$contact_submitted = 'Your message has been sent.';
function email_is_valid($email) {
return preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i',$email);
}
if (!email_is_valid($to)) {
echo '<p style="color: red;">You must set-up a valid (to) email address before this contact page will work.</p>';
}
if (isset($_POST['contact_submitted'])) {
$return = "\r";
$youremail = trim(htmlspecialchars($_POST['your_email']));
$yourname = stripslashes(strip_tags($_POST['your_name']));
$yourmessage = stripslashes(strip_tags($_POST['your_message']));
$contact_name = "Name: ".$yourname;
$message_text = "Message: ".$yourmessage;
$user_answer = trim(htmlspecialchars($_POST['user_answer']));
$answer = trim(htmlspecialchars($_POST['answer']));
$message = $contact_name . $return . $message_text;
$headers = "From: ".$youremail;
if (email_is_valid($youremail) && !eregi("\r",$youremail) && !eregi("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
mail($to,$subject,$message,$headers);
$yourname = '';
$youremail = '';
$yourmessage = '';
echo '<p style="color: blue;">'.$contact_submitted.'</p>';
}
else echo '<p style="color: red;">Please enter your name, a valid email address, your message and the answer to the simple maths question before sending your message.</p>';
}
$number_1 = rand(1, 9);
$number_2 = rand(1, 9);
$answer = substr(md5($number_1+$number_2),5,10);
?>
<form id="contact" action="contact.php" method="post">
<div class="form_settings">
<p><span>Name</span><input class="contact" type="text" name="your_name" value="<?php echo $yourname; ?>" /></p>
<p><span>Email Address</span><input class="contact" type="text" name="your_email" value="<?php echo $youremail; ?>" /></p>
<p><span>Message</span><textarea class="contact textarea" rows="5" cols="50" name="your_message"><?php echo $yourmessage; ?></textarea></p>
<p style="line-height: 1.7em;">To help prevent spam, please enter the answer to this question:</p>
<p><span><?php echo $number_1; ?> + <?php echo $number_2; ?> = ?</span><input type="text" name="user_answer" /><input type="hidden" name="answer" value="<?php echo $answer; ?>" /></p>
<p style="padding-top: 15px"><span> </span><input class="submit" type="submit" name="contact_submitted" value="send" /></p>
</div>
</form>`
$to='1!'email@hotmail.com';
$subject='Contact';
$contact_submitted='您的邮件已发送';
功能电子邮件\u有效($email){
返回preg_match('/^[A-Z0-9.\%+-]+@[A-Z0-9.-]+\[A-Z]{2,4}$/i',$email);
}
如果(!email_有效($to)){
echo'您必须设置一个有效的(to)电子邮件地址,此联系人页面才能正常工作。
;
}
如果(isset($_POST['contact_submitted'])){
$return=“\r”;
$youremail=trim(htmlspecialchars($_POST['your_email']);
$yourname=stripslashes(strip_标签($_POST['your_name']);
$yourmessage=stripslashes(strip_标记($_POST['yourmessage']);
$contact_name=“name:”.$yourname;
$message\u text=“message:”.$yourmessage;
$user\u answer=trim(htmlspecialchars($\u POST['user\u answer']);
$answer=trim(htmlspecialchars($_POST['answer']);
$message=$contact_name.$return.$message_text;
$headers=“From:”.$youremail;
如果(电子邮件有效($youremail)&&&!eregi(“\r”,$youremail)&&!eregi(“\n”,$youremail)&&$yourname!=”“&&&$yourmessage!=”“&&substr(md5($user\u answer),5,10)==$answer){
邮件($to、$subject、$message、$headers);
$yourname='';
$youremail='';
$yourmessage='';
echo'。$contact_已提交。
”;
}
else echo'在发送邮件之前,请输入您的姓名、有效的电子邮件地址、邮件以及简单数学问题的答案。
;
}
$number_1=兰特(1,9);
$number_2=兰特(1,9);
$answer=substr(md5($number_1+$number_2),5,10);
?>
Name页面中显示的PHP命令清楚地表明PHP要么没有安装,要么没有正确配置。确保它已启动并正在运行,并且您的文件具有.php
扩展名
另外,您的源代码缺少开头的您缺少开头的PHP标记
只需添加:
<?php
再安装一次怎么样?“不起作用”,“试图修复它”和指向错误消息图片的链接是一个非常糟糕的问题描述……这也可能表明缺少大括号或额外的大括号。@patricksweeney你是对的,我在回答中添加了这种可能性。