尝试修复代码。我在3号,5号和9号线上拉错了。我很难过。看起来不错,但不是:/
<?php
if($_POST['submit']) {
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST[$_POST['comments'])) {
$error = true;
}else{
$to = "theloregame@gmail.com"
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$comments = trim($_POST['comments']);
$subject = "Contact Form";
$messages = "name: $name \r\n Email: $email \r\n Comments: $comments";
$headers = "From:" . $name;
$mailesent = mail($to, $subject, $messages, $headers);
if($mailsclient) {
$sent = true;
}
}
}
?>
答案 0 :(得分:1)
缺少半结肠
$to = "theloregame@gmail.com"
应该是
$to = "theloregame@gmail.com";
^
和
empty($_POST[$_POST['comments'])
应该是
empty($_POST['comments'])
答案 1 :(得分:1)
错误为空($ _ POST [$ _ POST ['comments'])
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments']))
并且缺少分号:
$to = "theloregame@gmail.com";
答案 2 :(得分:0)
尝试这个
<?php
if($_POST['submit'])
{
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments']))
{
$error = true;
}
else{
$to = "theloregame@gmail.com";
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$comments = trim($_POST['comments']);
$subject = "Contact Form";
$messages = "name:".$name."\r\n Email:".$email."\r\nComments:".$comments;
$headers = "From:" . $name;
$mailesent = mail($to, $subject, $messages, $headers);
if($mailsclient)
{
$sent = true;
}
}
}
?>
错误及其解决方案:
//最后一个条件附近的语法错误$ _POST [$ _ POST
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST[$_POST['comments']))
更改为:
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST[$_POST['comments']))
//分号丢失
$to = "theloregame@gmail.com"
更改为:
$to = "theloregame@gmail.com";
//级联
$messages = "name:".$name."\r\n Email:".$email."\r\nComments:".$comments;
答案 3 :(得分:0)
$to = "theloregame@gmail.com";
//你需要;有
一个好的方法是评论代码块,只留下2-3行,看看你是否有错误。如果是,您可以轻松找到它们,如果不是,请再添加2-3行,然后重试。