UBB.Dev
Posted By: Lunatik Email to Subscribes for New Posts - 06/20/2002 6:10 PM
I added some code that will allow for people to use the subscription option to get email on new posts when they get submitted instead of the daily report.

Modify your addpost.php and goto
// ---------------------------------------------
// Update the total post if the post is Approved
if ($Approved == "yes") {


and add this code right above
code:

// Send an Email to the Subscribers if they are Subscribed to this board
if ($Approved == "yes") {
$query = "
SELECT U_Email,
U_Language
FROM w3t_Users
LEFT JOIN w3t_Subscribe ON U_Username = S_Username
WHERE S_Username = U_Username
AND S_Board = '$Board_q'
";

$sth = $dbh -> do_query($query);

while ( list($Mailto,$Language) = $dbh -> fetch_array($sth) ) {
// -------------------------------------------=
// We need to make sure this user still exists
if ($Mailto) {

// -----------------------------------------------------------------
// Now if this user has a pre-selected language we use that language
// for the message we send out
if (!$Language) { $Language = $config['language'];}
require "{$config['path']}/languages/$Language/addpost.php";

$EmailBody = $Body;
if ($config['stripcodes']) {
$EmailBody = preg_replace("/<([^>])*>/","",$EmailBody);
}

$newline = "\n";
if (stristr(PHP_OS,"win")) {
$newline = "\r\n";
}

$to = $Mailto;
$mailer = new mailer;
$header = $mailer -> headers();
$subject = "New Post To $Title from $postername";
$msg = "$postername has posted a message to $Title: $newline{$config['phpurl']}/showthreaded.php?Cat=$Cat&Board=$Board&Number=$Mnumber$newline${newline}------Message Below------${newline}Subject: $FormSubject${newline}${newline}Message:$newline$EmailBody";

mail("$to","$subject",$msg,$header);

// --------------------------------------------------
// Now, we need to switch back to this users language
$Language = $user['U_Language'];
if (!$Language) { $Language = $config['language']; }
require "{$config['path']}/languages/$Language/addpost.php";
}
}
}

Posted By: Lunatik Re: Email to Subscribes for New Posts - 06/20/2002 6:34 PM
Also you might want to modify the editemail.php in the languages directory and change the line

$ubbt_lang['SUB_STAT'] = "Subscription status for the following forums. (Receive a daily archive of all posts to this forum via your Real email address.)";

to

$ubbt_lang['SUB_STAT'] = "Subscription status for the following forums. (Receive an email on all posts to this forum via your Real email address.)";
Posted By: AllenAyres Re: Email to Subscribes for New Posts - 06/20/2002 11:46 PM
good one Often requested...

question, can it be turned off? Would hate to subscribe to a question/answer thread and it go on for 3-400 pages
Posted By: Lunatik Re: Email to Subscribes for New Posts - 06/21/2002 8:31 AM
The way it is designed the user can go to "My Home" and unsubscribe to the board at anytime. Or if you wish to shut the whole thing down just edit your config and turn off subscriptions.

The only thing I have to check on is if you turn off subscriptions does it clear the subscription table. Might have to look into that one.
Posted By: AllenAyres Re: Email to Subscribes for New Posts - 06/21/2002 6:46 PM
ok, sounds good then
Posted By: Lunatik Re: Email to Subscribes for New Posts - 06/22/2002 5:46 AM
I did some testing. When you turn off subscriptions in the config settings it does not remove the users from the subscribe table, however it still sends an email to the people who are subscribed to the board.

I will add something to the code so that if the subscriptions is turned off it will quit sending emails on all posts.
Posted By: Lunatik Re: Email to Subscribes for New Posts - 06/24/2002 7:05 PM
Here is the updated code for the subscriptions. If you globally disable subscriptions it will not send an email out.

code:

// Send an Email to the Subscribers if they are Subscribed to this board
if (($Approved == "yes") && ($config['subscriptions'] == 1)){
$query = "
SELECT U_Email,
U_Language
FROM w3t_Users
LEFT JOIN w3t_Subscribe ON U_Username = S_Username
WHERE S_Username = U_Username
AND S_Board = '$Board_q'
";

$sth = $dbh -> do_query($query);

while ( list($Mailto,$Language) = $dbh -> fetch_array($sth) ) {
// -------------------------------------------=
// We need to make sure this user still exists
if ($Mailto) {

// -----------------------------------------------------------------
// Now if this user has a pre-selected language we use that language
// for the message we send out
if (!$Language) { $Language = $config['language'];}
require "{$config['path']}/languages/$Language/addpost.php";

$EmailBody = $Body;
if ($config['stripcodes']) {
$EmailBody = preg_replace("/<([^>])*>/","",$EmailBody);
}

$newline = "\n";
if (stristr(PHP_OS,"win")) {
$newline = "\r\n";
}

$to = $Mailto;
$mailer = new mailer;
$header = $mailer -> headers();
$subject = "New Post To $Title from $postername";
$msg = "$postername has posted a message to $Title: $newline{$config['phpurl']}/showthreaded.php?Cat=$Cat&Board=$Board&Number=$Mnumber$newline${newline}------Message Below------${newline}Subject: $FormSubject${newline}${newline}Message:$newline$EmailBody";

mail("$to","$subject",$msg,$header);

// --------------------------------------------------
// Now, we need to switch back to this users language
$Language = $user['U_Language'];
if (!$Language) { $Language = $config['language']; }
require "{$config['path']}/languages/$Language/addpost.php";
}
}
}

Posted By: Lunatik Re: Email to Subscribes for New Posts - 07/05/2002 3:46 PM
I tested this with Version 6.0.2 and everything appears to be working the same without any furter modifications.
© UBB.Developers