2015-06-20 10 views
-1

我一直在试图让论坛工作。我的老师对我以前的3个版本不满意,于是我决定向我的侄子请求帮助。在他帮助我之后,我只剩下一个问题,那就是电子邮件功能。每次有人发布问题答复时,我都希望提问的用户收到一封包含答案的电子邮件。只要他得到答案,布局就无关紧要。 2天后,我仍然没有得到它的工作,所以我决定在这里问我的问题,并希望得到答案。顺便说一句,文本的语言是荷兰人,如果你想知道。代码是英文的。 。回复后得到电子邮件功能在论坛上工作

<?php 
//create_cat.php 
include 'connect.php'; 
include 'header.php'; 

if($_SERVER['REQUEST_METHOD'] != 'POST'){ 
    //het kan niet direct worden opgeroepen, dit geeft een error 
    echo 'Dit bestand is niet manueel bereikbaar.'; 
}else{ 
    //status effe checken 
    if(!$_SESSION['signed_in']){ 
     echo 'Je moet aangemeld zijn om een antwoord te geven'; 
    }else{ 
     $sql = "INSERT INTO posts(post_inh,post_datu,post_topic,post_door) 
      VALUES ('" . $_POST['reply-content'] . "', 
        NOW(), 
        " . mysql_real_escape_string($_GET['id']) . ", 
        " . $_SESSION['geb_id'] . ")"; 

     $result = mysql_query($sql); 
     if(!$result){ 
      echo 'Je antwoord is niet opgeslagen probeer later opnieuw'; 
     }else{ 
      echo 'Je antwoor is opgeslagen, bekijk <a href="topic.php?id=' . htmlentities($_GET['id']) . '">het</a>.'; 
     } 
    } 
} 

include 'footer.php'; 
?> 

这就是我想要把它放在代码 谁问这个问题的人的电子邮件ADRES是在数据库中,被称为: geb_email

我真的很感激一些帮助因为我以前的7次尝试失败了,我失去了希望。

对不起英文不好,英文不是我的主要语言。

编辑:

<?php 
error_reporting(E_ERROR | E_PARSE); 
//create_cat.php 
include 'connect.php'; 
include 'header.php'; 

$sql = "SELECT 
     topic_id, 
     topic_onderwerp 
    FROM 
     topics 
    WHERE 
     topics.topic_id = " . mysql_real_escape_string($_GET['id']); 

$result = mysql_query($sql); 

if(!$result) 
{ 
echo 'Het onderwerp kan nu niet worden weergegeven, probeer later opnieuw'; 
} 
else 
{ 
    if(mysql_num_rows($result) == 0) 
{ 
    echo 'Dit onderwerp bestaat niet.'; 
} 
else 
{ 
    while($row = mysql_fetch_assoc($result)) 
    { 

     echo '<table class="topic" border="1"> 
       <tr> 
        <th colspan="2">' . $row['topic_onderwerp'] . '</th> 
       </tr>'; 


     $posts_sql = "SELECT 
        posts.post_topic, 
        posts.post_inh, 
        posts.post_datu, 
        posts.post_door, 
        gebruikers.geb_id, 
        gebruikers.geb_naam 
       FROM 
        posts 
       LEFT JOIN 
        gebruikers 
       ON 
        posts.post_door = gebruikers.geb_id 
       WHERE 
        posts.post_topic = " . mysql_real_escape_string($_GET['id']); 

     $posts_result = mysql_query($posts_sql); 

     if(!$posts_result) 
     { 
      echo '<tr><td>De posts kunnen niet worden weergegeven. Probeer later opnieuw.</tr></td></table>'; 
     } 
     else 
     { 

      while($posts_row = mysql_fetch_assoc($posts_result)) 
      { 
       echo '<tr class="topic-post"> 
         <td class="geb-post">' . $posts_row['geb_naam'] . '<br/>' . date('d-m-Y H:i', strtotime($posts_row['post_datu'])) . '</td> 
         <td class="post-inhoud">' . htmlentities(stripslashes($posts_row['post_inh'])) . '</td> 
         </tr>'; 
      } 
     } 

     if(!$_SESSION['signed_in']) 
     { 
      echo '<tr><td colspan=2>je moet <a href="signin.php">aangemeld zijn</a> om te antwoorden. Je kunt ook <a href="signup.php">een account </a> maken.'; 
     } 
     else 
     { 
      //de reply cell/box of hoe je het ook wil noemen 
      echo '<tr><td colspan="2"><h2>Reply:</h2><br /> 
       <form method="post" action="reply.php?id=' . $row['topic_id'] . '"> 
        <textarea name="reply-content"></textarea><br /><br /> 

        <input type="submit" value="Finish" /> 
       </form></td></tr>' 

      ; 
     } 

$email_to="[email protected]"; //edited this quicly to prevent spam :p 
$email_subject="Antwoord vraag forum"; 

$headers = "Van: forum"; 
mail($email_to, $email_subject, $email_message, $headers); 

     //en mijn grote fout hier was natuurlijk de tabel niet afsluiten 
     echo '</table>'; 
    } 
} 
} 

include 'footer.php'; 
?> 

这是topic.php代码。我在这里尝试了一些东西(删除了破坏代码的东西)。现在需要发生的是将用户,电子邮件和文本放入$ email变量中。 非常感谢。

回答

0

您不应该使用MySQL驱动程序,因为它已被弃用 - 请改用MySQLi或PDO!

您可以使用此功能发送电子邮件:

mail("[email protected]", "Subject", "Message (simple use enter for new line)", "From: Sender name <[email protected]>"); 

如果它不工作,你应该使用一个图书馆一样PHPMailer通过SMTP发送(库由我,如果你只是推荐也用邮件发送)。

你不应该使用!$_SESSION[...],因为它可以抛出通知/甚至警告。改为使用empty()!isset()

+0

我已经变得更远一点,但我仍然卡住了。在邮件中获取正确的文本非常困难;无论如何感谢您的帮助。 – Wolfeh

+0

@沃尔夫:你的文章有什么问题? – Richard

+0

那么问题在于reply.php是由topic.php访问的。 reply.php从topic.php获取所有信息,如topic_id = 1 topic_door(谁发布它)= 1等等。我试图将其链接到用户,然后再链接到用户的电子邮件。这没关系。主要问题是,回复的文本被放入回复内容文本区域,我无法从该文本区域获取信息中的信息。如果你想,我可以把所有的代码放在这里,以便你可以看到它。我可能没有提供足够的数据。我很抱歉,这是我第一次在这里发布内容,我有点绝望。 – Wolfeh