Weirdan | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I used to run into this problem using php and had to resort to Dear user,
Which is no good realy.
I send about 8000 newsletters out per week all personalised with Dear NAME, in batches of 1000 (your mail server can probably take more but keep your eye on bandwidth usage).
I scapped php for this though and resorted to perl and postfix (and a reverse MX for my machine).
If anyone has a functioning mail server running then give this a try.
[syntax="perl"]
#!/usr/bin/perl
# email newsletter script
# grabs a list of users in the form of (username, email)
# grabs the current newsletter
use Time::Local;
use Mail::RFC822::Address qw(valid validlist);
$port = 25;
$them = 'localhost';
$subject = 'Newsletter';
$to = '';
$name = '';
$from = 'webmaster@host.com';
$AF_INET = 2;
$SOCK_STREAM = 1;
$i = 0;
$SIG{'INT'} = 'dokill';
$sockaddr = 'S n a4 x8';
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);
@Days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
@Months = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$day = $Days[$wday];
$date = $mday + 0;
$year = 1900 + $year;
$month = $Months[$mon];
$tmp='';
sub dokill { kill 9,$child if $child; }
sub read_file {
my ( $f ) = @_;
open F, "< $f" or die "Can't open $f : $!";
my @f = <F>;
close F;
return wantarray ? @f : \@f;
}
sub reduce_space {
my $email = shift;
$email =~ s/(\w) @ (\w)/$1\@$2/g;
return $email;
}
# requires a hook up to the user_details and members tables
# to grab a list of usernames and email addresses
# where the user wants a newsletter
($name,$aliases,$proto) = getprotobyname('tcp');
($name,$aliases,$port) = getservbyname($port,'tcp') unless $port =~ /^\d+$/;
($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
$this = pack($sockaddr, $AF_INET, 0, $thisaddr);
$that = pack($sockaddr, $AF_INET, $port, $thataddr);
socket(S, $AF_INET, $SOCK_STREAM, $proto) ? print "socket ok\n" : die $!;
bind(S, $this) ? print "bind \033[31mok\033[0m\n" : die $!;
connect(S,$that) ? print "connect \033[31mok\033[0m\n" : die $!;
select(S); $| = 1; select(STDOUT);
# grab our list of users
@list = read_file($ARGV[0]);
# how many users is there
$lines = 0;
open(FILE, $ARGV[0]) or die "Can't open `$filename': $!";
while (sysread FILE, $buffer, 4096) {
$lines += ($buffer =~ tr/\n//);
}
close FILE;
# handshake with postfix
#$a=<S>;print "$a";
print S "EHLO localhost\n";
#$a=<S>;print "$a\n";
print "\n-------------------------- Session started ----------------------\n\n";
# start mailing
while ($i < $lines){
#print "$i\n";
# get the newsletter
@newsletter = read_file('/path/to/newsletter'); // make sure your newsletter end with a . on a line of its own
# split current user row on ,
@users = split(',',$list[$i]);
$name = $users[0]; # name
$to = reduce_space($users[1]); # email
if(valid($users[1])){
#print "$users[1] is valid\n";
foreach $value (@newsletter){
# replace newsletter {NAME} with $name (personalisation)
$value =~ s/{NAME}/$name/;
$value =~ s/{DATE}/$month $date $year/;
$value =~ s/{EMAIL}/$to/;
}
print S "MAIL FROM: $from\n";
#$a=<S>;print "$i=> MAIL FROM $a\n";
print S "RCPT TO: $to\n";
#$a=<S>;print "$i=> RCPT TO $a\n";
print S "DATA \n";
print S "Subject: $subject\n";
print S "MIME-Version: 1.0\n";
print S "Content-Type: text/html; charset=\"iso-8859-1\"\n";
print S "From: $from\n";
print S "To: $to\n";
foreach $value (@newsletter){
print S $value;
}
sleep(1);
#$a=<S>;print "$i=> DATA $a\n";
}
#print "\n-------------------------- Done ----------------------\n\n";
$i++;
}
print S "QUIT";
#$a=<S>;print "$a\n";
exit 1;
You need a list of users in the format
<username>, <email>
Then simply run ./pmail list_of_users.txt
And away they will go.
As i have a few servers in house I can run it from the office using a mail server in here but I see no reson why it could not be uploaded to your ISP (providing they have PERL) and a working mail server.
This script opens a socket to the server and uses that socket to acheive true bulk mailing. Something php just cannot do as well.
ibbo
Weirdan | Please use[/syntax]Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]