I have been trying to get a forum to work. My teacher wasn't satisfied with my previous 3 versions so I decided to ask my nephew for some help. After him helping me I only have one problem left and that is the e-mail function. Every time someone posts a reply to a question I want the user who asked the question to recieve an e-mail with the answer in it. The lay-out doesn't matter as long as he gets the answer. After 2 days I still haven't gotten it to work so I decided to ask my question here and hope to get an answer. Btw the language of the text is dutch if you are wondering. The code is in english.
<?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';
?>
This is the code where I want to put it in. The email adres of the person who asked the question is in the database and is called: geb_email
I would really appreciate some help because my previous 7 attempts failed and I'm losing hope.
I'm sorry for the bad english, English is not my main language.
edit:
<?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="fakemail@mail.com"; //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';
?>
This is the topic.php code. I tried some thing here (removed the code breaking ones). All that needs to happen now is get the user, email and text into the $email variable. A lot of thanks.