Gossamer Forum
Home : Products : DBMan : Customization :

Email upon adding a record

Quote Reply
Email upon adding a record
Hi!

I have added mod for sending an email to admin when record is added. Problem is that it just send a message:
"The following record was added to the database:"
and then no data of the record. This is the code I have put in html.pl:

Code:
my (%rec) = &get_record($in{$db_key});

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title New Record\n\n";
print MAIL "The following new record has been added to the database:.\n\n";
foreach $col ($db_cols) {
print MAIL "$col -- $rec{$col}\n";
}
close (MAIL);

It doesn't fetch the records data.
Any idea ?

And I would also like to have the name of the user who add this record. How do I do that ?

Sasa
Quote Reply
Re: [atomant] Email upon adding a record In reply to
OK, I have solve the issue about blank email. But still I would like to see who added this record.Wink
Quote Reply
Re: [atomant] Email upon adding a record In reply to
$db_cols should be @db_cols - you can't loop a scalar.

However I'd change:

Code:
foreach $col ($db_cols) {
print MAIL "$col -- $rec{$col}\n";
}

to:

Code:
print MAIL map { qq|$col -- $rec{$_}\n| } @db_cols;
Quote Reply
Re: [Paul] Email upon adding a record In reply to
Is this change going to print out the user who added the record ?

Sasa
Quote Reply
Re: [atomant] Email upon adding a record In reply to
It will print out the whole record which I assume the original code wasn't doing?
Quote Reply
Re: [atomant] Email upon adding a record In reply to
If you have the email address of the submitter as a field (let us say it is named 'email'), then replace the line:

print MAIL "The following new record has been added to the database:.\n\n";

with:

print MAIL "The following new record has been added to the database by $mail:.\n\n";

I think that should do the trick.
-------------
David Olley
Anglo & Foreign International Limited,
http://www.firehelmets.co.uk

There are 10 types of people in the world: those who understand binary, and those who don't.