Gossamer Forum
Home : Products : DBMan : Installation :

Help on Email notification

Quote Reply
Help on Email notification
I've used the "S E N D E M A I L A F T E R R E C O R D I S A D D E D" by JP DENI and also read the "Email notification" (Thead reference: 000639 Forum 12) and after user added a new records, the email message still doesn't appear the adding fields.
I have added the following code in uf_html.pl
sub html_add_success {
at the beginning of the sub :
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);
The Code :
foreach $col ($db_cols) {
print MAIL "$col -- $rec{$col}\n";
DOESN'T WORK !
Ok, so I replace it with a 1 field:
print MAIL "Your Code is : $rec{$ID}\n";
But the $rec{$ID} print out a blank message.
Could anyone help me about this ?
PS : I have already using the "Send Email Mod" and it's fine.
Thanks.


Quote Reply
Re: Help on Email notification In reply to
Try changing:

print MAIL "Your Code is : $rec{$ID}\n";

to:

print MAIL "Your Code is : $rec{'ID'}\n";

and see if that solves the blank message.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Help on Email notification In reply to
Thanks for your quick response.
Yes, I have change the code into :

print MAIL "Your Code is : $rec{'ID'}\n";

But still don't work.

From JP DENI responses on a similar questions, I also change the top code :
from :
my (%rec) = &get_record($in{$db_key});
open (MAIL, "$mailprog") || &cgierr("Can't start mail program");

To :
my (%rec) = &get_record($in{$db_key});
open (MAIL, "|/usr/lib/sendmail -t") || print "Can't start mail program";

Still I receives only the email header without the field descriptions.
Is it possible that the db.cgi code must also be replaced ? or perhaps from the default.cfg ?
Please, give me a hint !
PS : I also try it by adding the code to the db.cgi in the sub add_record {
Outcome it works just the same as the uf_html.pl, but still with blank fields.

Quote Reply
Re: Help on Email notification In reply to
I'm not quite sure what the problem is.

You are getting an email, right?

Does the email list the field names, but not the values, or is it completely empty?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Yep, your quite right.

I receive only the name fields without the values, and also it's funny that
on the subject line it prints the html_title.

I try installing from the password look up mod, send mail, get mail, send member, and
all other email stuff, they works fine !.

Maybe the problems come from to many email mods ? ( well just kidding ! )

Only just this "add_record" I'm really stuck !,
please help me out.
BTW, Thanks JPD for your responses.

Quote Reply
Re: Help on Email notification In reply to
Does the record print out correctly in the add success page?

Try changing

print MAIL "$col -- $rec{$col}\n";

to

print MAIL "$col -- $in{$col}\n";



JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Yes, it does print correctly in the add success page.

I have exactly change the code :

to

print MAIL "$col -- $in{$col}\n";

Still the same outcome -- no Values in the email.

Do you have another Ideas ?

or is there any debugging code ?

Thanks, JPD.


Quote Reply
Re: Help on Email notification In reply to
Can you post your entire sub html_add_success here?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Thanks JPD ! yes, of course.

sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.

my (%rec) = &get_record($in{$db_key});
open (MAIL, "|/usr/lib/sendmail -t") || print "Can't start mail program";
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title New Job\n\n";
print MAIL "The following new job has been added to the database.\n\n";
foreach $col ($db_cols) {
print MAIL "$col -- $in{$col}\n";
}

# This is only just to check the individual fields :

print MAIL "Date : $rec{'$Date'}\n";
print MAIL "ID : $rec{'$ID'}\n";
print MAIL "Job Title : $rec{'$Title'}\n";
print MAIL "Category : $rec{'$Category'}\n";
print MAIL "User ID : $rec{'$Userid'}\n";
close (MAIL);

$page_title = "Job Added";
&html_page_top;

# < -- Start page text -- >
print qq|
<P><$font>The following job was successfully added to the database:</FONT>
|;
# < -- End page text -->

&html_record_long(&get_record($in{$db_key}));
&html_footer;
&html_page_bottom;
}

#########################################

I've tried also put all the entire code to the end of the

sub html_add_success ( after the "}" sign ) and still no results.

Quote Reply
Re: Help on Email notification In reply to
I don't know why it's not working, but there's lots of different things to try. Give this a shot:

Code:
sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.

$page_title = "Job Added";
&html_page_top;

# < -- Start page text -- >
print qq|
<P><$font>The following job was successfully added to the database:</FONT>
|;
# < -- End page text -->

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

&html_footer;
&html_page_bottom;

open (MAIL, "|/usr/lib/sendmail -t") || print "Can't start mail program";
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title New Job\n\n";
print MAIL "The following new job has been added to the database.\n\n";
foreach $col ($db_cols) {
print MAIL "$col -- $rec{$col}\n";
}

# This is only just to check the individual fields :

print MAIL "Date : $rec{'$Date'}\n";
print MAIL "ID : $rec{'$ID'}\n";
print MAIL "Job Title : $rec{'$Title'}\n";
print MAIL "Category : $rec{'$Category'}\n";
print MAIL "User ID : $rec{'$Userid'}\n";
close (MAIL);

}
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Thanks JPD, for your attention.

I'm sorry to tell you that your code doesn't work.

It give me the same result, that is a blank fields

after :

"The following new job has been added to the database."

it prints only " -- "

That's all what I get.

PS : I've worked in a relational database, but I think ( logical ) it doesn't effect the blank outcome since no swicth code at all. ( or maybe it does ? )


Quote Reply
Re: Help on Email notification In reply to
Oh, I know what the problem is. I should have seen this before.

foreach $col (@db_cols) {

It was only when you said that the script just printed out " -- " that I realized what was going on. I had thought it was printing the field labels. Knowing it didn't print the field labels told me where to look.

This should fix it.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Well JPD we're one step ahead !

You are Amazing !!!

Now I receive the email with all the fields.

Here are the results :
The following records has been modified to the database.

Userid --
ID --
FirstName --
LastName --
Email --
Company --
URL --
Phone --
HandPhone --
Fax --
Address1 --
Address2 --
City --
State --
Zip --
Country --
Position --
Profile --
Date --
Subscribe --
Validated --

OK, I think now the problems come from reading the values, isn't it right ?

- Tommy -

Quote Reply
Re: Help on Email notification In reply to
"The following records has been modified to the database."

Modified or added? Which subroutine are we talking about here?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Sorry JPD, I've installed on both subroutines

with the same " Subject " line.

Recently I'm trying to add a new subroutine in the db.cgi

for the modified subroutines :

sub send_modified_email {
my (%rec) = @_;
%rec = &get_record($in{$db_key});
open (MAIL, "|/usr/sbin/sendmail -t -oeq") or &cgierr("Can't open sendmail!\n");
print MAIL "To: admin\@psynetid.com\n";
print MAIL "From: admin\@psynetid.com\n";
print MAIL "Subject: $html_title Database Update Information\n\n";
print MAIL "The following records has been modified to the database.\n\n";
foreach $col (@db_cols) {
print MAIL "$col -- $rec{$col}\n";
}
close (MAIL);
}

And it works perfectly, I receive all the fields value.

Next thing, I make another subroutine for the "Add" records.

The outcome still the same as above.

Might it be a missing code in the db.cgi ?

Thanks JPD

PS : Sorry for this late response, there was trouble in my
telephone line.

Quote Reply
Re: Help on Email notification In reply to
Is your sub html_add_success the way I wrote it several posts up? If so, do the values print out on the success page?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Yes, I don't make any changes to your code of the sub html_add_success, and still doesn't print out the values.

So I try another subroutine for the "Modified Record" which the code are installed in the db.cgi. ( see my prev. message )

Add a line at the sub html_modify_success {

&send_modified_email(&get_record($in{$db_key}));

Results :
It works perfectly !.

By this result, I added a line in the sub html_add_success and do the same configuration, and still doesn't print out.

Any Ideas ?

- Tommy -


Quote Reply
Re: Help on Email notification In reply to
It tells me that your $in{$db_key} variable is having a problem. I don't know what it is.

Do you get the record to print out after you have added a record? I need to know this because the printing of the record depends also on a &get_record($in{$db_key}) command.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Thanks JPD.

Maybe I should better explain how the results of the adding record is:

After I complete the form (Add_Records), I get the Success Page ( Add_Succes ) with all values in the html long format.

At the same time I receive an email from admin that there
was a new record being submitted.

The messages what I get is the same as my prev. message which is "only fields with no print out value".

Print Out blank values : " -- "

What you have mentioned about the "$in{$db_key}", are there any other phrase of command just for debugging the " Add Success" function ?


Quote Reply
Re: Help on Email notification In reply to
Again, I'm confused. Smile

I need you to (again) post your sub html_add_success and a copy of what prints out. Maybe we can get this figured out.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Help on Email notification In reply to
Thanks JPD,

I have a good news for you, after rebuilding again all the script file from scracth, now it's working !

The working code are by adding to the db.cgi :

sub send_add_email {
my (%rec) = @_;
%rec = &get_record($in{$db_key});
open (MAIL, "|/usr/sbin/sendmail -t -oeq") or &cgierr("Can't open sendmail!\n");
print MAIL "To: admin\@psynetid.com\n";
print MAIL "From: admin\@psynetid.com\n";
print MAIL "Subject: $html_title New Add Records\n\n";
print MAIL "The following records has been modified to the database.\n\n";
foreach $col (@db_cols) {
print MAIL "$col -- $rec{$col}\n";
}
close (MAIL);
}

Well about what your asking for :

sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.

$page_title = "Job Added";
&html_page_top;

# < -- Start page text -- >
print qq|
<P><$font>The following job was successfully added to the database:</FONT>
|;
# < -- End page text -->

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

&html_footer;
&html_page_bottom;

open (MAIL, "|/usr/lib/sendmail -t") || print "Can't start mail program";
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title New Job\n\n";
print MAIL "The following new job has been added to the database.\n\n";
foreach $col ($db_cols) {
print MAIL "$col -- $rec{$col}\n";
}

# This is only just to check the individual fields :

print MAIL "Date : $rec{'$Date'}\n";
print MAIL "ID : $rec{'$ID'}\n";
print MAIL "Job Title : $rec{'$Title'}\n";
print MAIL "Category : $rec{'$Category'}\n";
print MAIL "User ID : $rec{'$Userid'}\n";
close (MAIL);

}

Since I added to the db.cgi, it turns to :

sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.
$page_title = "Job Added";
&html_page_top;
&html_nav;
# < -- Start page text -- >
print qq|<P><$font>The following job was successfully added to the database:</FONT>
|;
# < -- End page text -->
%rec = &get_record($in{$db_key})
&html_record_long(%rec);
&html_short_search;
&html_nav;
&html_page_bottom;
&send_add_email(&get_record($in{$db_key})); }

- Tommy -