Gossamer Forum
Home : Products : DBMan : Customization :

Massmailer sends to some users only

Quote Reply
Massmailer sends to some users only
I've just added JPDeni's massmailer mod. On testing, the revised script sends to just 14 users, not the remaining 500 or so in my database.

I checked my database - the 14th and 15th records all have the correct number of fields, so no corruption here.

Could a kind soul point me in the right direction for what to check here?



Quote Reply
Re: Massmailer sends to some users only In reply to
My initial (non-technical) reaction, based on painful experience, is to advise you to check your database file again, then again a few more times!



David Olley
Anglo & Foreign International Limited,
Winchester
England
Quote Reply
Re: Massmailer sends to some users only In reply to
Is there anything different between the first 14 records and the 15th?

JPD
Quote Reply
Re: Massmailer sends to some users only In reply to
Thanks David and Carol - yes I checked and rechecked the database. Perhaps I'm blind to something that's clearer to someone with more experience. The start of the database (with actual names removed to protect the innocent!) is copied below. Could it just be the hyphenated prefix to the host name in record 14? Yet record 14 was picked up in my dummy mailshot but not 15.

----Extract from database----

blankrecord|||||||||||||||||||||||||
user1.surname@host1.si|uid1||||||||||||||||||||||||
user2@host2.co.uk|uid2||||||||||||||||||||||||
user3@host3.ca|uid3||||||||||||||||||||||||
user4@host4.co.uk|uid4|name||surname|||||||||||||||||||||
user5@host5.co.uk|uid5||||||||||||||||||||||||
user6@host6.com|uid6||||||||||||||||||||||||
user7@host7.com|uid7||||||||||||||||||||||||
user8.surname@host8.com|uid8|name||surname|||||||||||||||||||||
user9.surname@host9.com|uid9|name||surname|||org||||||||||||||||||
user10.surname@host10.com|uid10|name||surname|||org||||||||||||||||||
user11@yahoo.com|uid11||||||||||||||||||||||||
user12@host12.com|uid12|name||surname|||org||||||||||||||||||
user13_surname@nl.host13.com|uid13|name||surname|||org||||||||||||||||||
user14.surname@abc-company.host14.at|uid14|name||surname|||||||||||||||||||||
user15_surname@hotmail.com|uid15|name||surname|||||||||||||||||||||


Quote Reply
Re: Massmailer sends to some users only In reply to
I don't know. Try taking that record out temporarily and see what happens.


JPD
Quote Reply
Re: Massmailer sends to some users only In reply to
Thanks, Carol. I've now dropped the original records 14 and 15. On re-running my test, it still sends just 14 messages!

I've counted the number of fields in records before and after the 14th - this seems to be consistent. Am at a loss! Any other ideas?!

Quote Reply
Re: Massmailer sends to some users only In reply to
My first guess is that there's a problem with counting the number of records in the database. Try changing

Code:

open (DB, "<$db_file_name") or &cgierr("error in mass_mail. unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;
foreach $line (@lines) {
(/^#/) and next;
(/^\s*$/) and next;
++$count;
}
to

Code:

open (DB, "<$db_file_name") or &cgierr("error in mass_mail. unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;
$count = scalar(@lines) + 1;
See if that does any better.

JPD
Quote Reply
Re: Massmailer sends to some users only In reply to
Ah! The change led to mail being sent, correctly picking out email addresses from the first 113 of 521 records. A further 419 emails were generated (against the expected 408) but a blank entry - or the contents of another field - was picked out for these 419 mails in place of the email address.

Again, the 113th and 114th records both have the specified 26 fields and nothing unusual in them. Sorry, but I don't understand enough of the script itself to see what else I could tweak. I'd really appreciate any futher help you can give.

Quote Reply
Re: Massmailer sends to some users only In reply to
It seems you aren't getting the correct number of hits, for one thing. Did you do a search before sending out the mailing to be sure of how many you should get?

We're going to rearrange some code in order to see what's going on. Change

Code:

my ($status, @hits) = &query("view");
unless ($status eq 'ok') {
$message .= "$status<BR>";
}
if ($message) {
chomp($message);
&html_mass_mail_form($message);
return;
}
my ($numhits) = ($#hits+1) / ($#db_cols+1);
to

Code:

my ($status, @hits) = &query("view");
my ($numhits) = ($#hits+1) / ($#db_cols+1);
$message .= "Number of hits -- $numhits<BR>";
unless ($status eq 'ok') {
$message .= "$status<BR>";
}
if ($message) {
chomp($message);
&html_mass_mail_form($message);
return;
}
Nothing will be sent out. You'll get an "error" message with the number of records the search returned.

JPD
Quote Reply
Re: Massmailer sends to some users only In reply to
Carol, yes I get:

"There was a problem: Number of hits -- 527.076923076923"

Yes, I did a count using "View" before. Repeating this now produces a count of 528 records (I guess the difference of one is accounted for by the first header record which doesn't contain an e-mail address).

Does this result tell you what's happening?

I changed the script back and re-tested. I spotted that the server returns a "Cannot find server" message (in place of the screen telling me how many mails were sent). Is this a clue?

Looking at the resulting emails sent, it looks like the email field was picked out accurately for the first 189 records, then it seems the contents of another (blank or non-blank field) are picked out for the rest of 527 emails. Does the fact that 189 were picked correctly this time, and 113 last time, give any clues?

Quote Reply
Re: Massmailer sends to some users only In reply to
Carol - I've built up the confidence to play around a little. Would you mind checking that what I've done is OK? It generates emails picking out the correct email field (the first in each record) for all records in my database. Running the script still produces a "cannot find server" page in place of the notification of the number of mails sent.

Thanks as ever,


sub mass_mail {
# --------------------------------------------------------
#
my ($i,$message,@lines,$line,$count,%rec,$mail_count);

unless ($admin_email) { $message = "Admin email has not been entered in the .cfg file<BR>"; }
unless ($admin_email =~ /.+\@.+\..+/) { $message = "Admin email address is not in the correct format.<BR>"; }
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }

open (DB, "<$db_file_name") or &cgierr("error in mass_mail. unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;

foreach $line (@lines) {

@fields = split (/\|/, $line);

open (MAIL, "$mailprog") || &cgierr("unable to open mail program");

print MAIL "To: $test_email\n";
print MAIL "From: $admin_email ($admin_name)\n";
# print MAIL "Bcc: $bulletin_bcc (Bulletin distribution)\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL "\n";
print MAIL "Test for picking out email field: $fields[0]\n";
print MAIL $in{'emailmessage'};
close (MAIL);
++$mail_count;
}
&html_mass_mail_success($mail_count);
}

Quote Reply
Re: Massmailer sends to some users only In reply to
Looks like that will work, if you want to send mail to every one in your database. The mass mailer script was set up so that you could set search terms to send to selected people.

In Reply To:
Running the script still produces a "cannot find server" page in place of the notification of the number of mails sent.
I must have missed this when you mentioned it before. Is this a 404 error? What exactly does the page say?


JPD
Quote Reply
Re: Massmailer sends to some users only In reply to
Thanks Carol - I can live without the searching.

The error I get is - in Netscape - a "! Document contains no data" box and - in MSIE - the standard window that's thrown at you if your script has an error in it.

Quote Reply
Re: Massmailer sends to some users only In reply to
I use MSIE so rarely that I don't know what the page is that you get when the script has an error in it.

In sub html_mass_mail_success, are you sure you have the line

&html_print_headers;

at the top of the subroutine? That's been one cause of a "document contains no data" error.

I may need to see your sub html_mass_mail_success.

JPD
Quote Reply
Re: Massmailer sends to some users only In reply to
Thanks - I'll try to work out what's up.

I really appreciate your help in getting me through the main problem of generating the e-mails.