Gossamer Forum
Home : Products : DBMan : Customization :

Send E-mail with new record to admin

Quote Reply
Send E-mail with new record to admin
Oh my. I've spent hours trying to get it so an email containing a new record gets sent to the admin. I have scoured the posts, boards, and sites. Wonderful! But it won't work. When the new record is created, mail gets sent and everything works up until the part where the record data should be. Then nothing.

Here's what I have in html.pl, in the sub html_add_success:

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;

My .cfg file includes
$mailprog = "|/usr/sbin/sendmail -t -oeq";

which must at least be the right path, since mail is sent, to the right address etc. The headers are right, the Subject includes the name of my database. Just no data. None!

Please, o brilliant and generous thinkers of dbman, help this poor soul!

Quote Reply
Re: Send E-mail with new record to admin In reply to
There's a typo in the FAQ, which I just fixed:

foreach $column (@db_cols) {

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Send E-mail with new record to admin In reply to
Thank you for your prompy reply. Unfortunately, it still is not working. Here is the e-mail I received, from the subject line down:

Subject: The Database New Record Added


---------------------------------------------------------------------------


The following record was added to The Database


:

I wondered about the placement of the code; I have it as the first thing after the comments in
sub html_add_success {
#blah blah blah
###send admin email when record added##
code

That's correct, isn't it?
Also since the FAQ calls qmail and I use sendmail, it's hard to feel confident that the -t -oeq are the correct switches; I have no clue what they do. So could there be a problem there??

Thanks.

Quote Reply
Re: Send E-mail with new record to admin In reply to
Ok. Believe it or not, there was an extra space in that line. So
foreach $column(@db_cols) {

worked!

JDP, you da person!

Quote Reply
Re: Send E-mail with new record to admin In reply to
Hi and good morning

I found this feature very useful and I tried a bit more but...

In my config file I have got a field called "Email" that must be filled out. When the record is added and the e-mail is send to the admin-email I would like to show this "Email" in the FROM entry of the e-mail send to the admin-email.

I tried it with:

print MAIL "From: $column: $in{4}\n";

The "Email" field is in position 4.

But what comes up shows only ":" in the FROM entry in the email that I receive.

Is there a way to show the content of the "Email" field in the FROM entry?

Sincerely Michaels

Quote Reply
Re: Send E-mail with new record to admin In reply to
print MAIL "From: $in{$db_cols[4]}\n";


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Send E-mail with new record to admin In reply to
Thank you, it works perfect..

Michaels :)

Quote Reply
Re: Send E-mail with new record to admin In reply to
JP, I've been searching the fourm on doing something almost exactly as you have described (I'm acutally using it in the "TO" section). I've been searching and searching but nothing found, then low and behold the message I'm searching for appears!!! :) Although I didn't ask for this, it is a HUGE deal that I got it. thank you so much for all your efforts with DBMan, I do lurk in the shadows and learn what I can.

Thanks again,


Conor Treacy
-----
www.HandsonWebDesign.com
Quote Reply
Re: Send E-mail with new record to admin In reply to
Hi and good morning!

I discovered something that brings me in troubles!

I am using hidden fields in html_record_form and I discovered that these fields are not send by e-mail.

Is there a way to go around this problem?

Sincerely michaels

Quote Reply
Re: Send E-mail with new record to admin In reply to
Sorry I was wrong!!!

The hidden fields are send by e-mail. There was another problem in the database!

Sincerely michaels

Quote Reply
Re: Send E-mail with new record to admin In reply to
Good Morning,

I have been working on getting the Send Record mod up and running since my Aug 8 post. You answered some questions that have since been resolved, Thank You. I am still getting an error "unable to open mail program". It has taken me the last two weeks to get the correct path name from my ISP, they gave me /usr/bin/sendmail and /usr/sbin/sendmail (neither works). After reading this post I am wondering if something is wrong in the script. mlustig mentions code being in the html.pl:

"Here's what I have in html.pl, in the sub html_add_success:

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;"

I don't see this in the send record mod. Is this from a different mod? I put something like this in the db.cgi file.


The line you mentioned he correct: foreach $column (@db_cols) {

I have in the db.cgi file and it is: foreach $col (@db_cols) {


Is this correct?

Any ideas where I might go from here?

Thanks,
VaLinda


Quote Reply
Re: Send E-mail with new record to admin In reply to
Just wanted to check do you have the $mailprog variable defined within your .cfg file under # Authorization Options?

$mailprog = "|/usr/bin/sendmail -t -oeq";

Without seeing your html.pl or .cfg file it's hard to know what's happening or what exactly you have done.


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Send E-mail with new record to admin In reply to
Yes, I have in my cfg file:

$mailprog = "|/usr/bin/sendmail -t -oeq";

I would be glad to send you the whole file if you could take a look at it. I don't know where to go from here.

Thanks,
VaLinda


Quote Reply
Re: Send E-mail with new record to admin In reply to
What I have in my databases at the beginning of sub html_add_success is:

%rec=&get_record($in{$db_key});
&html_record_long(%rec);

Instead of the original which was:

## &html_record_long(&get_record($in{$db_key}));

If you are not using short/long mod you would change &html_record_long to read &html_record

If this doesn't work you may want to save your html.pl and .cfg file as text files and provide the url where they can be viewed.

Also please say exactly what is happening. Are you getting anything?

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Send E-mail with new record to admin In reply to
LoisC

Thank you for your offer to take a look at my script. I am not sure how to get it into a format for you to view. If I put it into a web page format, it becomes a very large project. I'm embarrassed to say I need direction even here. You can go to the site that does not work and get an idea of the problem.

https://ssl.sonic.net/...fault&add_form=1

I really do need some help. Please give me details on how to get the information to you

Thanks,
VaLinda

Quote Reply
Re: Send E-mail with new record to admin In reply to
Are you able to send email using any script on your server? I'm wondering if it is the code or the path to the mail server.

To make your files available for viewing you need to save them as .txt files and place them on your server. Then provide the url to your file.

We would need to see both your .cfg and html.pl or db.cgi file depending on where you have the codes placed.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Send E-mail with new record to admin In reply to
I have a similar problem, I use:-

# &html_record(&get_record($in{$db_key}));
%rec=&get_record($in{$db_key});
&html_record(%rec);

&html_footer_user;
&html_page_bottom;

# Send email to admin
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "User id $rec{'UserID'} added new user data;\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 sends an email to admin with all the fields listed but the only field with data is the userid field.
Strange huh?!?

Quote Reply
Re: Send E-mail with new record to admin In reply to
G'morning rcrossland, please review back thru this entire post and review the changes/corrections which JPDeni indicated on the following two lines.

foreach $column (@db_cols) {
print MAIL "$column: $in{$column}\n";

If correcting the lines as she has indicated do not work, then repost your sub and indicate what errors & actions result when you try to use the feature.

(PS - It's early, don't really mean to sound grumpy.)


Quote Reply
Re: Send E-mail with new record to admin In reply to
No it's fine to be grumpy in the morning Karen Smile
I being tired at the other end of the day, missed the space bit and hey presto.......no luck Frown
So here we go with da sub:-
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "User id $rec{'UserID'} added new user data;\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";
}

I get an email with all the fields listed but no data aside from userid. I wonder if it's cos I extract the user id first? I'll try with out selecting the userid.


..2 MINS LATER... Sadly it made no difference. It (userid) is still the only value I get.
Quote Reply
Re: Send E-mail with new record to admin In reply to
LoicC,

I have never tried sending an email using script until now. I emailed my ISP numerous times specifically asking for the FULL PATH NAME! They got rather short with me so I assumed the path was correct. I am on a secure server and I did ask them for the name of sendmail for a secure server, that is what I am using.
My files are as text files at the following:
ftp.sonic.net/pub/users/marty
Thanks for the help.

VaLinda

Quote Reply
Re: Send E-mail with new record to admin In reply to
Hi,
I have experienced the same problem as mlustig. I receive my e-mail okay and I receive the field names - but not the data that was added to those fields.

I have checked this full thread and checked my code (listed below) against what was listed here but still no luck.

I'd appreciate any ideas anyonw may have.
Thanks,
Gemstorm.

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: $db_userid\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 $column(@db_cols) {
print MAIL "$column: $in{$column}\n";
}
print MAIL "\n\n";
close (MAIL);





Quote Reply
Re: Send E-mail with new record to admin In reply to
Replace the following:
print MAIL "$column: $in{$column}\n";

with:
print MAIL "$column: $rec{$column}\n";

It should solve your problem.