2016-09-09 58 views
1

这里是我的代码表格显示代码中的错误

<?php 
$email=$_POST['email']; 
$name=$_POST['name']; 
$comments=$_POST['comments']; 

$to = "[email protected]"; 
$subject = "Comments"; 
$message = 
" 
Name:-    " . $name .  "\r\n 
Email:-   " . $email . "\r\n 
Comments:-  " . $comments .     

$headers = "From:" . $email . "\r\n"; 

if(@mail($to,$subject,$message,$headers)) 
{ 
    print "<script>document.location.href='http://thesite.org/docs/tkx.html';</script>"; 

} 
else 
{ 
    echo "Error! Please try again."; 
} 

?> 

但对于原因,我无法检测,当数据被发送到我的邮箱就包括再次“电子邮件地址”的数据,在结束了“评论数据

我做了什么错了?

在此先感谢。 OzWaz

+0

你'$ message'声明应该用'结束;','不.',这concats你的'$头部变量。 – roberto06

回答

2

删除最后一个点从这里

Comments:-  " . $comments . 

所以应该

Comments:-  " . $comments; 

现在你要连接另一条线路$消息;)

1
$message = 
" 
Name:-    " . $name .  "\r\n 
Email:-   " . $email . "\r\n 
Comments:-  " . $comments .  

只是删除点(。)从行结尾,因此它不与下面的标题行连接。 应该

$message = 
" 
Name:-    " . $name .  "\r\n 
Email:-   " . $email . "\r\n 
Comments:-  " . $comments; 
+1

@devpro感谢编辑。 –

0
$message = 
" 
Name:-    " . $name .  "\r\n 
Email:-   " . $email . "\r\n 
Comments:-  " . $comments;     

$headers = "From:" . $email . "\r\n"; 

你被contacenating另一条线$headers = "From:" . $email . "\r\n";$message