简体   繁体   中英

PHP Grab Content - E-mail

On my website, I have a reportpost.php piece of code. I have set it up so that when you click the report button, this code launches. In the e-mail part, I don't get the posts content.

<?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 = "ecerserver@outlook.com";
$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 = "admin@ecer.ca";
$headers = "From: $from";
mail($to1,$subject,$message,$headers);
mail($to2,$subject,$message,$headers);

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

exit();

?>

there's a problem in the logic of your code, I think this will solve your problem:

<?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 = "ecerserver@outlook.com";
$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 = "admin@ecer.ca";
$headers = "From: $from";
mail($to1,$subject,$message,$headers);
mail($to2,$subject,$message,$headers);

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

exit();

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM