2015-12-21 73 views
1

在我的網站上,我有一個reportpost.php代碼段。我已經設置好了,所以當你點擊報告按鈕時,這個代碼就會啓動。在電子郵件部分,我沒有收到帖子內容。PHP抓取內容 - 電子郵件

<?php 

session_start(); 

$con = mysql_connect("---","---","---"); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 
mysql_select_db("ecerca", $con); 

//$result = mysql_query("SELECT Content FROM Entries ORDER BY id"); 
$result = mysql_query("SELECT * FROM Posts WHERE Username='$_SESSION[Username]' ORDER BY ID"); 

mysql_close($con); 

$row = mysql_fetch_array($result); 

while ($row = mysql_fetch_array($result)) 
{ 

if ($row['ID'] == $_GET['id']){ 
    echo "$row[Content]"; 
} 
} 

$to1 = "[email protected]"; 
$subject = "Reported Post | Ecer Forums"; 

$message = "Someone has reported a post on Ecer Forums!\r\n\r\n\r\n\r\nThis is a message to inform you that\r\n\r\n\r\nUsername: '" . $usr . "' \r\n\r\n\r\n has reported the following post: '" . $row['Content'] . "'"; 

$from = "[email protected]"; 
$headers = "From: $from"; 
mail($to1,$subject,$message,$headers); 
mail($to2,$subject,$message,$headers); 

header("location:http://www.ecer.ca/myposts/?msg=1"); 

exit(); 

?> 

回答

0

有一個在你的代碼的邏輯有問題,我認爲這將解決您的問題:

<?php 

session_start(); 

$con = mysql_connect("---","---","---"); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 
mysql_select_db("ecerca", $con); 

//$result = mysql_query("SELECT Content FROM Entries ORDER BY id"); 
$result = mysql_query("SELECT * FROM Posts WHERE Username='$_SESSION[Username]' ORDER BY ID"); 

mysql_close($con); 

$row = mysql_fetch_array($result); 

if (! $row) 
{ 
    exit(); 
} 

if ($row['ID'] == $_GET['id']){ 
    echo "$row[Content]"; 
} 

$to1 = "[email protected]"; 
$subject = "Reported Post | Ecer Forums"; 

$message = "Someone has reported a post on Ecer Forums!\r\n\r\n\r\n\r\nThis is a message to inform you that\r\n\r\n\r\nUsername: '" . $usr . "' \r\n\r\n\r\n has reported the following post: '" . $row['Content'] . "'"; 

$from = "[email protected]"; 
$headers = "From: $from"; 
mail($to1,$subject,$message,$headers); 
mail($to2,$subject,$message,$headers); 

header("location:http://www.ecer.ca/myposts/?msg=1"); 

exit(); 

?>