dongyi5070 2015-12-21 01:50
浏览 138
已采纳

PHP抓取内容 - 电子邮件

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!



This is a message to inform you that


Username: '" . $usr . "' 


 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();

?>
  • 写回答

1条回答 默认 最新

  • dsft8327 2015-12-21 01:56
    关注

    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!
    
    
    
    This is a message to inform you that
    
    
    Username: '" . $usr . "' 
    
    
     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();
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分