Gossamer Forum
Home : Products : DBMan : Customization :

Email Notification of new record entry.

Quote Reply
Email Notification of new record entry.
IS there any way for the program to send an email when someone has posted a new record?

I have a database setup that will give users "add only" privlidges. I need to be notified every time they enter something.

Thanks
Quote Reply
Re: Email Notification of new record entry. In reply to
I guess I should write a FAQ for this.

Are you on a Unix system? Do you have sendmail? (That's the only system I know, so I can only give you info for that kind. I'm sure that someone else will be able to help you with a Windows or NT system.)

Find out where sendmail is on your system.

Add the following lines to your .cfg file:

Code:
# Full path to sendmail on your system
$mailprog = "|/usr/lib/sendmail -t -oeq";
# Your email address
$admin_email = 'you@yourserver.com';

changing the path and the email address to match your situation.

In sub html_add_success, right at the beginning, add

Code:
open (MAIL, "$mailprog") or &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 Added\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "The following record was added to $html_title\n\n";
foreach $column ($db_cols) {
print MAIL "$column: $in{$column}\n";
}
close MAIL;

This will give you all of the information that is in the new record.




------------------
JPD






Quote Reply
Re: Email Notification of new record entry. In reply to
Indeed there is, here is what I use. Firstly amend your cfg file of the database you wish to be notified for with the following in the URL and files section :
Code:
# Full path to sendmail on your system
$mailprog = "|/usr/lib/sendmail -t -oeq";
# Your email address
$admin_email = 'address@server.com';
Keep the quotes as stated and change the email addy to match yours.

Next amend the html_pl file of the same database.
In the sub html_add_success section add the following directly after the
Code:
%rec = &get_record($in{$db_key});
line
Code:
open (MAIL, "$mailprog") or &cgierr("Can't start mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Record Added\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "$rec{UserID} added a record";
close (MAIL);
As you can see use the $rec{field name} within the print statement to detail within the body of your email.
The above example assumes the location of sendmail on your server so you may have to sort that.
Modlet courtesy of JPD (of course) Smile
Quote Reply
Re: Email Notification of new record entry. In reply to
My website is hosted on an NT server. The mail program is BLAT.

Any suggestions on how to make it work with BLAT??
Quote Reply
Re: Email Notification of new record entry. In reply to
According to a tutorial I found on blat at http://hjs.geol.uib.no/...-ssi#BlatPerlSample1 , it wouldn't be much different.

$mailprog = 'c:/windows/blat ';

and

open (MAIL, "|$mailprog -t") or &cgierr("Can't start mail program");

The rest of it looks like it would be the same.



------------------
JPD