But we're using phpBB.
So am I.
phpBB sucks at posting code because it destroys tabs. Anyway...
You will need the following MySQL table:
Code: Select all
CREATE TABLE mailer (
id INT UNSIGNED AUTO_INCREMENT,
mailto VARCHAR(255) NOT NULL,
subject VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
extra_headers TEXT NOT NULL,
PRIMARY KEY (id)
);
In includes/emailer.php, add the following function to the class:
Code: Select all
function savemail($db, $to, $subject, $body, $extra_headers)
{
$sql = sprintf("INSERT INTO mailer VALUES(NULL, '%s', '%s', '%s', '%s');",
mysql_escape_string($to),
mysql_escape_string($subject),
mysql_escape_string($body),
mysql_escape_string($extra_headers)
);
$db->sql_query($sql);
return 1;
}
In send(), look for:
Code: Select all
$result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
Replace with:
Code: Select all
$result = $this->savemail($db, $to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
In your shell server's home folder, save the following script as mailer.pl:
Code: Select all
#!/usr/bin/perl -w
use strict;
use DBI;
use Net::SMTP;
my $smtp = 'mail.sourceforge.net';
my $mailfrom = 'themanaworld@themanaworld.sourceforge.net';
my $database = 'themanaworld';
my $user = 'themanaworld';
my $pass = 'your password';
my $host = 'mysql.sourceforge.net';
my $table = 'mailer';
my $dbh=DBI->connect("DBI:mysql:$database:$host", $user, $pass);
my $sql = "SELECT * FROM $table;";
my $sth = $dbh->prepare($sql);
my $rc = $sth->execute;
my @mails;
while (my @r = $sth->fetchrow_array) {
push @mails, \@r;
}
$dbh->do("TRUNCATE TABLE $table");
my $i = 1;
foreach my $r (@mails) {
print "Sending mail $i of " . @mails . "...\n";
my %mail = (
'To' => $r->[1],
'From' => $mailfrom,
'Subject' => $r->[2],
'Message' => $r->[3],
'X-Mailer' => "Openkore Forum Mailer v0.1"
);
sendmail(\%mail);
$i++;
}
sub sendmail {
my $mail = shift;
my $smtp = Net::SMTP->new($smtp);
$smtp->mail($mail->{From});
$smtp->to($mail->{To});
$smtp->data();
$smtp->datasend("Subject: $mail->{Subject}\n");
$smtp->datasend("X-Mailer: $mail->{'X-Mailer'}\n");
$smtp->datasend("From: $mail->{From}\n");
$smtp->datasend("To: $mail->{To}\n");
$smtp->datasend("\n");
$smtp->datasend("$mail->{Message}\n");
$smtp->dataend();
$smtp->quit;
}
Remember to set the password!
Although you're supposed to send the email in a cron job, cron doesn't work because crond is not running! So I wrote a little script that runs mailer.pl every 30 minutes.
Save as mdaemon.pl:
Code: Select all
#!/usr/bin/env perl
# cron doesn't work, bah
use strict;
use POSIX;
if (fork() == 0) {
POSIX::setsid();
open(STDIN, "< /dev/null");
open(STDOUT, "> /dev/null");
open(STDERR, "> /dev/null");
while (1) {
system('perl', '/full/path/to/mailer.pl');
sleep(30 * 60);
}
POSIX::_exit(0);
}
Remember to set the full path to mailer.pl!
Type: mdaemon.pl
Then exit. mdaemon.pl will continue to run in the background.