Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Dec 2002
Posts: 67
Power User
Power User
Joined: Dec 2002
Posts: 67
Hi All,
As an administrator I want an email from every new post>
In Threads version 6.1 I used this blok in bleu wich I found on this board.
When I paste it in to Version 6.2 it works fine but every time when the mail is send out I see a MySqL error for a few seconds.
What can I do to fix it?
Thanks in advance,
Pim Foppen
[:"blue"] /*
# This code snippet will email every new post to the moderator(s) of the
# forum the post is in, *and* the main administrator of the whole board (user #2).
#
# It mimics the behavior of UBB.Classic.
#
# In addpost.php, insert the code block below directly above the lines:
#
# // ---------------------------------------------
# // Update the total post if the post is Approved
#
#
# Disclaimer: I cobbled this together from existing code,
# I'm using it on my busy board and it works fine for me. I can't and
# won't be responsible if it doesn't work properly for you, or
# for any possible data loss or any incidental damages that may occur,
# etc etc etc legalese. Backup your original files first.
# In other words, use at your own risk, or "modify at your own peril".
#
# I doubt I'll be doing any other work on this since it now does exactly what
# I need it to do, so I'll leave improvements and enhancements to PHP gurus.
#
# That being said, I hope you find it useful, and that someone will
# clean it up and find a way to make it configurable from the Admin
# area, perhaps on a per-forum basis.
#
# This could be made shorter and more efficient by changing prior
# blocks of code, but I decided to make it a snippet to be dropped in,
# so no other modifications are necessary, getting ease of implementation
# but sacrificing a little brevity and efficiency.
#
#
# Helice, http://foolmoon.com
# mailto:[email protected]
#
# June 16, 2002
*/


//-------------Fool Moon Modified-------------------------
$EmailBody = $Body;
$EmailBody = preg_replace("/<([^>])*>/","",$EmailBody);
$newline = "\n";
if (stristr(PHP_OS,"win")) {
$newline = "\r\n";
}

// Find the moderators to notify
$query = "
SELECT Mod_Username
FROM w3t_Moderators
WHERE Mod_Board = '$Board_q'
";
$sth = $dbh -> do_query($query);

$mailer = new mailer;
$header = $mailer -> headers();
$blurb = "has just posted in : ";
// Construct the message body
$msg = "$postername $blurb $Title $newline{$config['phpurl']}/showthreaded.php?Cat=$Cat&Board=$Board&Number=$Mnumber$newline$newline$EmailBody";

// Find the email address for each moderator
while ( list($Mod) = $dbh -> fetch_array($sth)) {
$Mod_q = addslashes($Mod);
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Username = '$Mod_q'
";
$sti = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sti);
// Mail the package out
mail("$to","$Subject",$msg,$header);
}

// Then find the email address for the main administrator
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Number = 2
";
$sth = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sth);
// Mail the package out
mail("$to","$Subject",$msg,$header);

//-------------Fool Moon Modified------------------------- [/]

Sponsored Links
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
What error are you seeing?

Is the prefix to your tables "w3t_"? Or do you use a custom database prefix.

Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
Code
SELECT Mod_Username<br />FROM w3t_Moderators<br />WHERE Mod_Board = '$Board_q'


That won't work, because Mod_Username has been replaced by Mod_Uid. Do you need the email sent to all the moderators, or only to user #2?


Joined: Apr 2001
Posts: 3,266
Member
Member
Offline
Joined: Apr 2001
Posts: 3,266
Like Dave said the Mod_Username column is invalid now. Below is the proper code. I tested this on my test forum and it works.

//-------------Fool Moon Modified-------------------------
$EmailBody = $Body;
$EmailBody = preg_replace("/<([^>])*>/","",$EmailBody);
$newline = "\n";
if (stristr(PHP_OS,"win")) {
$newline = "\r\n";
}

// Find the moderators to notify
$query = "
SELECT Mod_Uid
FROM w3t_Moderators
WHERE Mod_Board = '$Board_q'
";
$sth = $dbh -> do_query($query);

$mailer = new mailer;
$header = $mailer -> headers();
$blurb = "has just posted in : ";
// Construct the message body
$msg = "$postername $blurb $Title $newline{$config['phpurl']}/showthreaded.php?Cat=$Cat&Board=$Board&Number=$Mnumber$newline$newline$EmailBody";

// Find the email address for each moderator
while ( list($Mod) = $dbh -> fetch_array($sth)) {
$Mod_q = addslashes($Mod);
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Username = '$Mod_q'
";
$sti = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sti);
// Mail the package out
mail("$to","$Subject",$msg,$header);
}

// Then find the email address for the main administrator
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Number = 2
";
$sth = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sth);
// Mail the package out
mail("$to","$Subject",$msg,$header);

//-------------Fool Moon Modified-------------------------


Joined: Dec 2002
Posts: 173
Member
Member
Offline
Joined: Dec 2002
Posts: 173
Hi Chuck

Does the above do this........

Admin receives ALL new posts.

Mods only the forums that they moderate.

Just what I need


Thanks

Liahona
Sponsored Links
Joined: Dec 2002
Posts: 67
Power User
Power User
Joined: Dec 2002
Posts: 67
I just woke up this morning and I found the suprise on the board.
It works great, thanks a lot, it gives me more and more insight how things work....
Regards,
Pim Foppen

Joined: Dec 2002
Posts: 173
Member
Member
Offline
Joined: Dec 2002
Posts: 173
Hi Chuck

That didn't work for me.

Gave me an 500 internal server error.

So I took OUT .....this part

===============================================
// Find the email address for each moderator
while ( list($Mod) = $dbh -> fetch_array($sth)) {
$Mod_q = addslashes($Mod);
$query = "
SELECT U_Email
FROM w3t_Users
WHERE U_Username = '$Mod_q'
";
$sti = $dbh -> do_query($query);
list($to) = $dbh -> fetch_array($sti);
// Mail the package out
mail("$to","$Subject",$msg,$header);
}
========================================

This worked and just emailed the admin but not the moderator.

So is there something needing changed in that part? lol


Thanks

Liahona
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
$Mod is a user number, not a user name. Try this:

Code
// Find the email address for each moderator <br />while ( list($Mod) = $dbh -> fetch_array($sth)) { <br />$query = " <br />   SELECT U_Email <br />   FROM w3t_Users <br />   WHERE U_Number = $Mod <br />";


(The addslashes() isn't needed, and the quotes around $Mod aren't needed, since $Mod is a number, not a string.)

Joined: Apr 2001
Posts: 3,266
Member
Member
Offline
Joined: Apr 2001
Posts: 3,266
LOL weird it worked for me and I have 6.2 well its not like I am using it anyway. I just tested it with the Uid to check it out and see if it worked.

Joined: Aug 2002
Posts: 2
Lurker
Lurker
Offline
Joined: Aug 2002
Posts: 2
Same thread over at infopop:
http://community.infopop.net/2/OpenTopic?a=tpc&s=729094322&f=5163077913&m=7963092986

That code works on <6.2 but its trivial to change to adding a join for the UIDs now.
(one minor bug in it, 3rd last line should read:
$dbh -> finish_sth($sth_mod);
)

Paul

Sponsored Links

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Posts: 70
Joined: January 2007
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)