Gossamer Forum
Home : Products : DBMan : Customization :

More on email to admin....

(Page 1 of 2)
> >
Quote Reply
More on email to admin....
After re-evaluating my needs, I still need a method of sending all records from an application form to an email address (mine). However, not all the records on the form will go into the database......

I think I have a pretty good idea how I can get it to send the email.... make a new sub, put the code to send the email in there (based from formmail), and include a call to it in sub add_record.....

But how would I limit the database entry to just the fields I need in the database, and still send all fields to the email? Any ideas? Is this even possible?
Quote Reply
Re: More on email to admin.... In reply to
You would not have to create a new sub-routine for the email routine. It can be placed as a part of the sub add_record routine.

For example:

(This example is used with the sub add_record routine in conjunction with the Validate records mod.)

Code:

open (MAIL, "$mailprog") | | &cgierr("unable to open mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Record Added to $html_title\n\n";
print MAIL "The following Record is waiting to be validated:\n\n";
print MAIL "Record ID: $rec{'ID'}\n";
print MAIL "Organization:
$rec{'Organization'}\n";
print MAIL "Job Title: $rec{'Position'}\n\n";
print MAIL "---------------------------------------------------\n";
print MAIL "You can use the Validation Form to validate or delete\n";
print MAIL "this Job Posting.\n";
print MAIL "----------------------------------------------\n\n";
print MAIL "Environmental Variables for Tracking Purposes:\n\n";
print MAIL "Remote Host: $ENV{REMOTE_HOST}\n";
print MAIL "Remote Addr: $ENV{'REMOTE_ADDR'}\n";
print MAIL "Referer: $ENV{'HTTP_REFERER'}\n";
print MAIL "Submitted Using: $ENV{'HTTP_USER_AGENT'}\n";
close (MAIL);

Place these after &html_add_success;.

You would have to add these variables to your default.cfg file:

Code:
$mailprog = "|/usr/lib/sendmail -t -oeq";
$admin_email = 'youraccount@yourserver.com";

Of course, you would have to change the path to your sendmail program and also change the email address.

In terms of selecting certain fields in the forms to be added to your database, that would need to be thought of more in-depth. In terms of emailing all the fields, you can add all the fields between the print MAIL ""; statments in your database which would be sent to you. Make sure that you put $rec{'FieldName'} for each field that you want to be sent to you.

Regards,



------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited September 06, 1999).]
Quote Reply
Re: More on email to admin.... In reply to
Well, putting the mail thing in its own sub would keep it cleaner I think.... but I'll try it this way.....

And, I suppose it wouldn't hurt too badly to put all the fields from the actual application form into the database, and just hide the extra fields..... (I have my own application form, and search form which already works....) Only thing is it'll use up more disk space.....
Quote Reply
Re: More on email to admin.... In reply to
I think you have to add a '\' in the admin-emailadress:
Quote:
$admin_email = 'youraccount\@yourserver.com";
Quote Reply
Re: More on email to admin.... In reply to
Ok, I tried it that way.....
Using PFE32, making sure everything was saved in unix text format..... (as I'm supposed to... or does dbman require DOS text format?)

Now, I get the following 500 error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@kirenet.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

Premature end of script headers: /home/svcbots/public_html/cgi/dbman/db.cgi

what did I do here? Besides screw it up... Wink
Quote Reply
Re: More on email to admin.... In reply to
Nope..... Still no go....
Quote Reply
Re: More on email to admin.... In reply to
If you are setting an email value for a variable, you do not have to use the \ character.

How do you have the $mailprog variable set-up?

Also, How did you set-up the mail routine? Did you make sure that the $rec{'FieldNames'} are between the print MAIL " "; statements?

Regards,



------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: More on email to admin.... In reply to
I actually have it set to send 2 emails, but the second one is directly copied from the first, so the second one should be almost identical...

Code:
open (MAIL, "$mailprog") | | &cgierr("Unable to open mail program!");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_from_email\n";
print MAIL "Subject: $EmailSubject\n";
print MAIL "The following application was submitted for review:\n";
print MAIL "---------------------------------------------------\n\n";
print MAIL "Time: &get_time\n";
print MAIL "Date: &get_date\n";
print MAIL "-----\n");
print MAIL "Application ID: $rec{'ID'}\n\n";
print MAIL "Channel: $rec{'Channel'}\n";
print MAIL "Name: $rec{'Name'}\n";
print MAIL "Email: $rec{'Email'}\n\n";
print MAIL "IRC Nick: $rec{'IRCNick'}\n";
print MAIL "Hostmask: $rec{'Hostmask'}\n";
print MAIL "Description: $rec{'Description'}\n";
print MAIL "CService Registration Active: $rec{'CServiceReg'}\n";
print MAIL "Comments:\n";
print MAIL "$rec{'Comments'}\n\n";
print MAIL "----------------------------------------------------\n";
print MAIL "Tracking Information:\n";
print MAIL "Remote Host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote Address: $ENV{'REMOTE_ADDR'}\n";
print MAIL "Referer: $ENV{'HTTP_REFERER'}\n";
print MAIL "Submitted using: $ENV{'HTTP_USER_AGENT'}\n";
close (MAIL);

That's exactly what I added for email #1... the second is simply copied/pasted with a couple more lines added.... Added directly after &html_add_success.

[This message has been edited by StoneC0ld (edited September 07, 1999).]
Quote Reply
Re: More on email to admin.... In reply to
Okay...so, the mail routine is set-up properly. How are you setting up the $mailprog variable? Where is your sendmail program located?

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: More on email to admin.... In reply to
hehehe.. that was quick....

Code:
# Email stuff
$mailprog = "/usr/bin/sendmail -t";
$admin_email = "servicebots.admin@listbot.com";
$admin_from_email = "davec@megalinks.net";
$EmailSubject = "#Service-Bots application for services";
Quote Reply
Re: More on email to admin.... In reply to
Two problems:

1) Your sendmail program. Try this (as I originally wrote):

Code:
$mailprog = "|/usr/lib/sendmail -t -oeq";

2) The # character is a special character in Perl and UNIX that rems out statements or lines. Using it in the your $EmailSubject variable is problematic. Try taking the # character out.

Hope this helps.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited September 07, 1999).]
Quote Reply
Re: More on email to admin.... In reply to
are you sure the | is necessary in the $mailprog = line?
The same line in the formmail script does not have a | in it... nor the -oeq flag for that matter....
before I use -oeq, what does that option do, anyway? sendmail's man page doesn't help me.....
Quote Reply
Re: More on email to admin.... In reply to
But I suppose that doesn't matter, because that didn't work.....
Quote Reply
Re: More on email to admin.... In reply to
Yes the | is necessary. I have tested not using it and the sendmail program does not work. Oops...I made a mistake with the codes
I gave you in the most recent post. It should be:

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

Do you have the sendmail routine right after the &html_add_success; line in the sub add_record routine in the db.cgi file?

And you took the pound character (#) out of the EmailSubject line?

What error message are you receiving, if any?

Please set the $db_debug variable to 1 in your default.cfg, which will show a more comprehensive bug report. Try the script again with the debug variable activated. Then come back to the Forum and post the complete bug report you get in your web browser.

Thanks.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited September 07, 1999).]

[This message has been edited by Eliot (edited September 07, 1999).]
Quote Reply
Re: More on email to admin.... In reply to
 
the open (MAIL..... line is directly on the next line from the add_success line....

I changed the $mailprog in the open lines to
open (MAIL,"|/usr/bin/sendmail") | | .....;

and set the debug variable to 1.

Until I say otherwise, I'm getting:

Code:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@kirenet.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

Premature end of script headers: /home/svcbots/public_html/cgi/dbman/db.cgi
Quote Reply
Re: More on email to admin.... In reply to
Oops...another syntax error...MAKE sure that the | | are together with no spaces. OR you could replace the two | | with or. Sorry about that.

The error message you are receiving refers to an internal syntax error in the script. DID you turn on the debug variable in default.cfg?? That will explain a lot more than the standard server error message.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited September 07, 1999).]
Quote Reply
Re: More on email to admin.... In reply to
I did try removing the space between the |'s..... to no effect....

And yes, I did set the debug variable to 1 in sbapps.cfg..... (and yes, the form I'm calling it from includes "db=sbapps")
Quote Reply
Re: More on email to admin.... In reply to
Does it matter if I upload in ftp with ASCII or BINARY transfer mode?

And the text of it should be in UNIX format, right?

I'm thinking of just deleting it all from the shell and re-uploading it all.... and if that don't work, start it all over again from scratch......
Quote Reply
Re: More on email to admin.... In reply to
The file has to be uploaded in ASCII (text-only) format. If it is on an UNIX
server, then yes, the file should be in
UNIX format. There are some subtle Perl characters that are not allowed on Windows system.

I would recommend NOT working on cgi/perl files in your shell account. There are too many ways to make a syntax errors. Use Notepad or Wordpad.

Wink

Also, there are some editors, like HomeSite that also debugs cgi scripts for errors.

Then upload the db.cgi file in ASCII format and then change the permission of the file to 755.

If this does not work, then please do the following:

1) Post the complete bug report you get from your web browser, including the environmental variables.

2) Save your db.cgi and default.cfg files as text files, like db.txt and default.txt and then upload them to your server. Then post the URL where we can find the files.

Thanks.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited September 08, 1999).]
Quote Reply
Re: More on email to admin.... In reply to
I much prefer to edit it here on my system..... I use Programmer's File Editor, which can save in both DOS and UNIX text formats....

On a hunch, I deleted the section that sends the email..... And I got past that 500 Server error.... But I got a few db.cgi errors instead: 2 "Invalid date format"'s, and a "ID cannot be blank"...

So, I went into sub add_record and added a few lines just before the first call to validate_record:
Code:
# Set the userid to the logged in user.
($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_user$

# insert today's date/time into the proper fields
$in{'DatePosted'} = &get_date;
$in{'TimePosted'} = &get_time;
$in{'DateReviewed'} = &get_date;

# First we validate the record to make sure the addition is ok.
$status = &validate_record;
But, that still leaves the "ID cannot be blank" error.... How would I get it to insert the next ID number into the ID field?
Quote Reply
Re: More on email to admin.... In reply to
Please post your default.cfg file and db.cgi files as text files, so we can look at them.
If you are concerned about breach of security, then send me your files at the following email address: eliot@anthrotech.com.

There seems to be bugs both in your default.cfg and db.cgi. It seems that you have made some major changes to the sub get_date routine that is giving you the invalid date format. The ID problem is probably associated with incorrectly formatting your default.cfg file.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: More on email to admin.... In reply to
The form that will be used is NOT the standard add-record form provided by dbman.... It's a separate form (on a separate server) that I made, using hidden fields to include the rest of the database fields that are not needed on the actual application, as well as the control options (ie, db=blah, uid=default, add_record=1)

I didn't touch the &get_date or &get_time subs... adding those lines in the add_record sub eliminated the "invalid date" errors....

The only db.cgi error I get now is the "ID field cannot be empty" error, because I don't know how to read the current ID# into the $rec{'ID'} field (or $in{'ID}, whichever needs to be updated)
Quote Reply
Re: More on email to admin.... In reply to
Ah...So, you are using a totally different add_record sub-routine. That is large part of the complications that have occurred. To reload the ID, I think you should use $rec{'ID'}.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: More on email to admin.... In reply to
no.....

The form calls the equivelant of
Code:
db.cgi?db=sbapps&uid=default&add_record=1&fieldsgohere=text.....

I found the code in the get_defaults sub anyway... copied/pasted it in with the other $in{'DatePosted'} = &get_date stuff...

So, if I can find the characters in the lines to send the emails, I should logically be set...
Quote Reply
Re: More on email to admin.... In reply to
Well, I have done all I can. It is problematic trying to provide DBMAN codes with a totally different script that you are using. I suggested twice that you should upload the files as text files, so that we can view them. Since you have not done that and you are providing snippets of the codes you are using, I cannot really help you.

Sorry.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
> >