Jump to content

automatically generated email notification


Lisa1983

Recommended Posts

I have a very simple forum and need to have it send an email to all of the users in the database notifying them of a new posting or response to a current posting. I am needing help on what code to include and where to include it. Below is my code for adding a forum topic and adding a response to a forum topic:

 

add_topic.php -

 

// get data that sent from form

$topic=$_POST['topic'];

$detail=$_POST['detail'];

$name=$_POST['name'];

$email=$_POST['email'];

 

$datetime=date("d/m/y h:i:s"); //create date time

 

$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')";

$result=mysql_query($sql);

 

if($result){

echo "Successful<BR>";

echo "<a href=main_forum.php>View your topic</a>";

}

else {

echo "ERROR";

}

mysql_close();

 

ob_end_flush();

 

 

add_answer.php -

 

// Get value of id that sent from hidden field

$id=$_POST['id'];

 

// Find highest answer number.

$sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";

$result=mysql_query($sql);

$rows=mysql_fetch_array($result);

 

// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1

if ($rows) {

$Max_id = $rows['Maxa_id']+1;

}

else {

$Max_id = 1;

}

 

// get values that sent from form

$a_name=$_POST['a_name'];

$a_email=$_POST['a_email'];

$a_answer=$_POST['a_answer'];

 

$datetime=date("d/m/y H:i:s"); // create date and time

 

// Insert answer

$sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')";

$result2=mysql_query($sql2);

 

if($result2){

echo "Successful<BR>";

echo "<a href='view_topic.php?id=".$id."'>View your answer</a>";

 

// If added new answer, add value +1 in reply column

$tbl_name2="forum_question";

$sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'";

$result3=mysql_query($sql3);

 

}

else {

echo "ERROR";

}

 

mysql_close();

 

 

Thank you for your help and time.

 

well u want to query all your users

<?php

//mysql connect info should be added

$get_users = mysql_query("GET * FROM users")

while ($users = mysql_fetch_array($get_users)) {

      $subject = "new post in [forum name]";

      $to = $user['email'];

      $message = 'new post check it out blah blah blah';

      mail ('$to','$subject','$message');

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.