2016-09-09 85 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