View Full Version : Automatic "Send Email" redirect
Revan
03-21-2005, 10:00 PM
Do you run a large forum, and need to send emails to all your users? Do you have to set the email per batch to a low number because of PHP limitations? And most importantly; would you have liked to see the emails work their magic while you go attend other duties?
If your answer to the aboves is yes, then this hack is for you!
What this hack does, is cache the email you are trying to send in a temporary SQL table, then instead of having a form with hidden fields and forcing you to hit submit, it reads this table at reload.
After the mail is sent, the table is emptied.
Thanks goes to DeMiNe0 for telling me to make this, and for helping me test it :)
Files modified: 1
DB Tables added: 1
Difficulty: Easy
nexialys
03-22-2005, 10:54 AM
good thing Revan, but there is a missing Replace, line WHEN searching FOR if (!$_POST['test'])... line 177 and on...
we replace it with what here?!
Revan
03-22-2005, 12:54 PM
Fix'd.
Cheers :)
oztrack
03-24-2005, 12:42 PM
I did all the changes to the php file
But I am a newby and dont know what exactly is meant by this. I ran the qery but i dont know what is meant by the final words in the text below. Remember to add a prefix if you use it. - What prefix.
I ran the query - but it said it changed 0 rows .
Help!!
Run this query:
_________________
CREATE TABLE `mailtemp` (
`test` tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
`message` mediumtext NOT NULL,
`subject` mediumtext NOT NULL,
`from` mediumtext NOT NULL,
`serializeduser` mediumtext NOT NULL
) TYPE=MyISAM;
Remember to add a prefix if you use it.
Revan
03-24-2005, 12:45 PM
Well in your config.php, if you have the "$tableprefix" set to anything, that is what you needed to add.
And even if you do not have a prefix, you ran the query correctly, because it is not supposed to change any rows ;)
As long as you don't get errors when sending a mail using this redirect, you did everything correctly :)
oztrack
03-24-2005, 12:46 PM
When i go to 'send email to users' now in the control panel - above the blue - i have the text over a white background saying
if ($_REQUEST['do'] == 'dosendmail' OR $_POST['do'] == 'makelist') { if (!$_GET['isredirect']) { $message = $_POST['message']; $perpage = $_POST['perpage']; $startat = $_POST['startat']; $subject = $_POST['subject']; $from = $_POST['from']; $serializeduser = $_POST['serializeduser']; } else { $perpage = $_GET['perpage']; $startat = $_GET['startat']; $mailtemp = $DB_site->query_first("SELECT * FROM `" . TABLE_PREFIX . "mailtemp`"); $message = $mailtemp['message']; $subject = $mailtemp['subject']; $from = $mailtemp['from']; $serializeduser = $mailtemp['serializeduser']; $test = $mailtemp['test']; } if (isset($serializeduser)) { $_POST['user'] = @unserialize($serializeduser);
Also
at the generate email list page i have the text
if ($_REQUEST['do'] == 'dosendmail' OR $_POST['do'] == 'makelist') { if (!$_GET['isredirect']) { $message = $_POST['message']; $perpage = $_POST['perpage']; $startat = $_POST['startat']; $subject = $_POST['subject']; $from = $_POST['from']; $serializeduser = $_POST['serializeduser']; } else { $perpage = $_GET['perpage']; $startat = $_GET['startat']; $mailtemp = $DB_site->query_first("SELECT * FROM `" . TABLE_PREFIX . "mailtemp`"); $message = $mailtemp['message']; $subject = $mailtemp['subject']; $from = $mailtemp['from']; $serializeduser = $mailtemp['serializeduser']; $test = $mailtemp['test']; } if (isset($serializeduser)) { $_POST['user'] = @unserialize($serializeduser);
Revan
03-24-2005, 12:49 PM
Are you sure you did the file changes correctly?
Because it seems to me like it echo's the entire script... :P
oztrack
03-24-2005, 12:52 PM
My table prefix is not set to anything. I just checked config.php
oztrack
03-24-2005, 12:54 PM
I will reload the default page and do the changes again - tomorrow. Thanks
Raptor
03-25-2005, 03:16 PM
i get an error on the first attempt at an auto re direct to next page - code has been applied 1:1 as per instructions
using vb 3.07 - query successfully executed and checked in phpmyadmin with no errors
Database error in vBulletin 3.0.7:
Invalid SQL:
INSERT INTO `mailtemp`
(`test`, `serializeduser`, `from`, `subject`, `message`)
VALUES
('0',
'a:26:{s:8:"username";s:0:"";s:11:"usergroupid";a:13:{i:0;s:1:"4";i:1;s:2:"87";i:2;s:2:"89";i:3;s:2:"79";i:4;s:1:"6";i:5;s:2:"61";i:6;s:1:"5";i:7;s:2:"80";i:8;s:1:"2";i:9;s:2:"91";i:10;s:2:"84";i:11;s:1:"1";i:12;s:1:"3";}s:10:"adminemail";s:1:"1";s:5:"email";s:0:"";s:11:"parentemail";s:0:"";s:9:"coppauser";s:2:"-1";s:8:"homepage";s:0:"";s:3:"icq";s:0:"";s:3:"aim";s:0:"";s:5:"yahoo";s:0:"";s:3:"msn";s:0:"";s:9:"signature";s:0:"";s:9:"usertitle";s:0:"";s:13:"joindateafter";s:0:"";s:14:"joindatebefore";s:0:"";s:17:"lastactivityafter";s:0:"";s:18:"lastactivitybefore";s:0:"";s:13:"lastpostafter";s:0:"";s:14:"lastpostbefore";s:0:"";s:13:"birthdayafter";s:0:"";s:14:"birthdaybefore";s:0:"";s:10:"postslower";s:0:"";s:10:"postsupper";s:0:"";s:15:"reputationlower";s:0:"";s:15:"reputationupper";s:0:"";s:9:"ipaddress";s:0:"";}',
'raptor@digital-forums.com',
'topic of email',
'email subject
Revan
03-25-2005, 03:34 PM
Is that all? You seem to have cut the error message in half.
Raptor
03-26-2005, 09:40 AM
yep thats verbatim
Revan
03-26-2005, 12:49 PM
Well you must understand that I can't diagnose a problem when you obviously cut out of the message exactly WHAT the error is, and WHERE it is.
It's 100 % impossible that that is a verbatim copy of the error, because vB doesn't output mySQL errors without the MySQL error code and message.
Raptor
03-26-2005, 11:36 PM
Database error in vBulletin 3.0.7:
Invalid SQL:
INSERT INTO `mailtemp`
(`test`, `serializeduser`, `from`, `subject`, `message`)
VALUES
('0',
'a:26:{s:8:"username";s:0:"";s:11:"usergroupid";a:8:{i:0;s:2:"87";i:1;s:2:"89";i:2;s:1:"6";i:3;s:2:"61";i:4;s:1:"5";i:5;s:2:"80";i:6;s:1:"2";i:7;s:2:"91";}s:10:"adminemail";s:1:"0";s:5:"email";s:0:"";s:11:"parentemail";s:0:"";s:9:"coppauser";s:2:"-1";s:8:"homepage";s:0:"";s:3:"icq";s:0:"";s:3:"aim";s:0:"";s:5:"yahoo";s:0:"";s:3:"msn";s:0:"";s:9:"signature";s:0:"";s:9:"usertitle";s:0:"";s:13:"joindateafter";s:0:"";s:14:"joindatebefore";s:0:"";s:17:"lastactivityafter";s:0:"";s:18:"lastactivitybefore";s:0:"";s:13:"lastpostafter";s:0:"";s:14:"lastpostbefore";s:0:"";s:13:"birthdayafter";s:0:"";s:14:"birthdaybefore";s:0:"";s:10:"postslower";s:0:"";s:10:"postsupper";s:0:"";s:15:"reputationlower";s:0:"";s:15:"reputationupper";s:0:"";s:9:"ipaddress";s:0:"";}',
'raptor@digital-forums.com',
'80 FREE 8X DVD-R @ WWW.NEODISCS.COM !',
'As a Digital-Forums member you are entitled to 80 FREE 8X DVD-R when you spend ?50 or more at www.neodiscs.com
Go get 'em !')
mysql error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'em !')' at line 8
mysql error number: 1064
Date: Sunday 27th of March 2005 03:35:06 AM
Script: http://www.digital-forums.com/admincp/email.php
Referer: http://www.digital-forums.com/admincp/email.php?do=start
Username: Raptor
IP Address: xx.xx.xx.xx
Raptor
03-26-2005, 11:44 PM
screen shot
Revan
03-27-2005, 12:21 AM
Yep see now I can determine the error... try replacing one of the edits with this: if (!$_GET['isredirect'])
{
$DB_site->query("
INSERT INTO `" . TABLE_PREFIX . "mailtemp`
(`test`, `serializeduser`, `from`, `subject`, `message`)
VALUES
('" . intval($_POST['test']) . "',
'" . serialize($_POST['user']) . "',
'" . mysql_real_escape_string($_POST['from']) . "',
'" . mysql_real_escape_string($_POST['subject']) . "',
'" . mysql_real_escape_string($_POST['message']) . "')
");
}
Might also want to take this bit and replacing into the first edit:
$message = stripslashes($mailtemp['message']);
$subject = stripslashes($mailtemp['subject']);
H2k_Coder
03-27-2005, 12:32 AM
WooooW very nice Hack i have other board use IPB and they have Something like this hack ..
Thankyou For Released this great hack going to Install it :)
Marco van Herwaarden
03-27-2005, 05:51 AM
In your email.php, find:
'" . mysql_real_escape_string($_POST['from']) . "',
'" . mysql_real_escape_string($_POST['subject']) . "',
'" . mysql_real_escape_string($_POST['message']) . "')
And replace with: '" . addslashes(mysql_real_escape_string($_POST['from'])) . "',
'" . addslashes(mysql_real_escape_string($_POST['subject'])) . "',
'" . addslashes(mysql_real_escape_string($_POST['message'])) . "')
Not tested.
Revan
03-28-2005, 02:39 PM
Btw, mysql_real_escape_string is a function more powerful than addslashes, but it does the same. Do not perform the above edit. Double escaping should be avoided, afaik :P
Marco van Herwaarden
03-28-2005, 09:24 PM
Actually you are right, must still have been sleeping. Double quoting should not be done.
Hmm strange that he stil got that error then.
Dennis Olson
03-29-2005, 02:49 PM
Copied from a Google search....
Why do i get a query syntax error 1064 from MySQL when the syntax seems correct?
You will get a MySQL query syntax error number 1064 when you incorrectly use a reserved word in your query such as "when" or "order".
MySQL 4 has additional reserved words that you cannot use and the full list of them is at http://www.mysql.com/doc/en/Reserved_words.html.
Revan
03-30-2005, 04:32 AM
In short, BALLS :p
Okay I will rename the stuff, and email people instructions on how to update :)
Thanks Dennis :)
SilverBoy
05-13-2005, 09:28 AM
I tried this hack, but it doesn't work good with me
my vb version is 3.0.7
when I select a specific user group, the first page goes ok, but the second will send the emails to all groups withous selection
other situation I send an email to 520 320 members for example (by selection) when it finished the first page and pressing next page link, it began sending to all members.
what's wrong exactly?
Master Computer
05-21-2005, 09:26 PM
Isn't it working in the test email mode?
quipster
06-01-2005, 01:36 AM
im running vb-3.06 right now and running a html hack so email.php was edited for that as well.. it seems to be working fine but in test mode it sends out emails as well.. the html email hack im running i got from here -- https://vborg.vbsupport.ru/showthread.php?t=72105 im sure other users will want both of these combined.
jb605
07-08-2005, 02:15 AM
Thanks for this great hack. As noted above, it does send out email in test mode actually. I tried the following change, which I believe fixed the problem so that it will ONLY test and not actually send email in test mode.
if (!$_POST['test'] OR !$test)
{
echo $vbphrase['emailing']." \n";
vbmail($user['email'], $subject, $sendmessage, true, $from);
Should be
if (!$_POST['test'] AND !$test)
{
echo $vbphrase['emailing']." \n";
vbmail($user['email'], $subject, $sendmessage, true, $from);
There also might be a bug that if you force close a email batch that is being processed (either by closing your browser, or restarted web server) , for whatever reason (I noticed I put in the wrong from address and all mail is rejected by MTA), then that mail batch is left over in the mailtemp table, and next time when you try to send mass email, the previous left-over batch will likely be the one being actually ran, instead of the new one you just created.
jb605
07-08-2005, 11:22 AM
After waiting for one whole night for this mass email to finish, I only get up to find that the email.php page becomes blank. So I don't even know where it left off. The mailtemp table was left with that email batch, with nowhere it indicates where it left off.
I will have to either dig my apache log or my maillog to find out where it left off, then modify my mass email search creteria to reflect that, otherwise I will have to start again, which will bother my members again, and might or might not work.
Does anybody else experience this timeout / blank page and left-over mail batch problem?
I think it might be a better idea for the email.php program to check if there is a mail batch left over, and let the admin to decide whether to continuue it or drop it. Also, the mail batch should store where it stopped (how many email sent, how many to go, perpage etc), this way it can easily pickup if the program timed out.
ahmedbehiry
10-17-2005, 07:16 PM
is there going to be a vbulletin 3.5 version of this hack?
kommuni
12-31-2005, 08:14 AM
is there going to be a vbulletin 3.5 version of this hack?
would also be interested in a 3.5 solution... will try to test this in 3.5
Malke
01-03-2006, 12:05 AM
best hack ever
tpearl5
05-26-2006, 03:06 AM
Any word on this for 3.5?
Revan
06-04-2006, 10:49 AM
Converted it real quick, here (https://vborg.vbsupport.ru/showthread.php?t=117608).
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.