PDA

View Full Version : add a send mail to my guestbook script


helper
03-07-2006, 10:10 AM
Hi I currently run a guestbook and would like it to email me when someone posts
how hard is this to do? and would anyone like to help me.

I have posted here before and received alot of help whaich has been greatly appreciated. The guestbook is "guestfriend"

many thanks

Doug

FishMonger
03-07-2006, 05:05 PM
Adding email notification is easy. Most of the the time I use the MIME::Lite module for sending email. http://search.cpan.org/~yves/MIME-Lite-3.01/lib/MIME/Lite.pm

Are you using the original version of the "guestfriend" script or the version that I worked up for you that used HTML::Template? Please post the script that you're using.

FishMonger
03-07-2006, 05:32 PM
If you want the best solution, rather than using your current script, use the guestbook script from the nms project. It's one of the best perl guestbook scripts available and already includes email notification. We would need to import your guestbook entries, but that shouldn't be too difficult. http://nms-cgi.sourceforge.net/scripts.shtml

helper
03-08-2006, 03:48 AM
Thanks for replying to me once again

I am still running the original guestfriend script, I know you said that it is not a good script but I have spent a great deal of time making it look the way I want it to on my site and wonder how hard it will be to emulate this with the script you suggest. I don't doubt its a better script. Also my knowledge is minimal and past a certsain point however hard I try I find it very confusing.

If I can keep the same setup on my site eg the posted letters going onto the same page as the form etc then I would be happy to swap over.

If not then can we add a email notification when someone posts to my site


many thanks

Doug

FishMonger
03-08-2006, 05:14 AM
The script I posted in your prior question needs a couple tweeks but is a drop-in replacement for this messed up script that you're using. However, even though it's far better than what you're using, it's still a very minimal script that doesn't include the level of error handling or security that it should have. You really should look at the nms script that I pointed to.

If you want to stay with your current script, here's one method of handling the email. This uses the MIME::Lite module which is a front end to sendmail. If you don't have this module available, we can open a pipe to sendmail.

Add this line to the beginning of the script.use MIME::Lite;

Add this subroutine.sub send_email {

$msg = <<MSG;
New guestbook posting from:

$fields{'name'}
$fields{'email'}

Comment:
$fields{'comment'}

MSG

$email = MIME::Lite->new(
From => 'guestbook@myhost.com',
To => 'me@myhost.com', # Don't forget to put in your real email address.
Subject => 'Guestbook Posting',
Data => $msg
);
$email->send;

}

Add this line near the end of the post_operation subroutine, just before the print $ml; statement.
send_email();

FishMonger
03-08-2006, 05:33 AM
Here's how to open the pipe to send the email.

open MAIL,"|/usr/lib/sendmail -t -oi" or die "Can not run sendmail $!\n";

print MAIL <<EMAIL;
To: me@myhost.com
From: guestbook@myhost.com
Subject: Guestbook Posting

New guestbook posting from:
$fields{'name'}
$fields{'email'}

Comment:
$fields{'comment'}

EMAIL

close MAIL;

helper
03-08-2006, 06:44 AM
i dont believe I have MIME available with my host

if not where do i addthe pipe to send the email, what point in my script
or have i got the wrong end of the stick. Do IO just add the second of your posts

open MAIL,"|/usr/lib/sendmail -t -oi" or die "Can not run sendmail $!\n";

print MAIL <<EMAIL;
To: me@myhost.com
From: guestbook@myhost.com
Subject: Guestbook Posting

New guestbook posting from:
$fields{'name'}
$fields{'email'}

Comment:
$fields{'comment'}

EMAIL

close MAIL;

Doug

FishMonger
03-08-2006, 07:25 AM
If you're going to use the pipe to sendmail option, that code wiuld be the contents of the send_email subroutine. You will also need to verify the path to sendmail. It could be /usr/sbin/sendmail instead of /usr/lib/sendmail
sub send_email {

open MAIL,"|/usr/lib/sendmail -t -oi" or die "Can not run sendmail $!\n";

print MAIL <<EMAIL;
To: me@myhost.com
From: guestbook@myhost.com
Subject: Guestbook Posting

New guestbook posting from:
$fields{'name'}
$fields{'email'}

Comment:
$fields{'comment'}

EMAIL

close MAIL;
}

helper
03-08-2006, 08:06 AM
ok so where do I place it in the guestbook cgi file

FishMonger
03-08-2006, 08:15 AM
As long as you don't put it inside of another subroutine, it can go anywhere in the script. Easiest would be to put it at the end of the script.

helper
03-08-2006, 08:39 AM
I tried putting it into the script but I cant seem to get it to work
I put it right at the end

and changed the sendmail part to suit my host etc

maybe I have it in the wrong place could you possibly tell me where to put it

I take it i also change the email to my email

FishMonger
03-08-2006, 08:42 AM
Are you receiving an error message? If so, what is it?

Post your script so that I know that I'm workning with the most up to date version and I'll adjust it as needed.

helper
03-08-2006, 08:52 AM
I get no error messages
this is the up to date script
with out the extra sendmail sub routine attached

FishMonger
03-08-2006, 04:55 PM
Try this:

helper
03-09-2006, 01:40 AM
thanks for the changed script

I tried to run it but it would not work I got an internal server error

sub send_email {

open MAIL,"|/usr/lib/sendmail -t -oi" or die "Can not run sendmail $!\n";

print MAIL <<EMAIL;
To: me\@myhost.com
From: guestbook\@myhost.com
Subject: Guestbook Posting

New guestbook posting from:
$fields{'name'}
$fields{'email'}

Comment:
$fields{'comment'}

EMAIL

close MAIL;
}


I take it I change me@myhost.com to my email address?

and lib to sbin to match my server?

FishMonger
03-09-2006, 01:55 AM
I need to know the exact error message. Do you have access to viewing the web server logs, i.e., do you have shell access?

FishMonger
03-09-2006, 02:13 AM
Add this lineuse CGI::Carp qw(fatalsToBrowser);

just before this line&get_env;
Then post the error message.

helper
03-09-2006, 03:17 AM
[Thu Mar 09 13:13:30 2006] [error] [client 58.104.122.206] failed to open log file /var/log/httpd/suexec_log, referer: http://www.lettertogod.net/
[Thu Mar 09 13:13:30 2006] [error] [client 58.104.122.206] fopen: Permission denied, referer: http://www.lettertogod.net/
[Thu Mar 09 13:13:30 2006] [error] [client 58.104.122.206] Premature end of script headers: guestbook.cgi, referer: http://www.lettertogod.net/


this is the error i get

FishMonger
03-09-2006, 03:53 AM
Move
print "Content-type: text/html\n\n";

to just after the CGI::Carp line, and remove the one that's in the &get_setup subroutine. That should get rid of the 'Premature end of script headers' error.

helper
03-09-2006, 05:33 AM
referer: http://www.lettertogod.net/
[Thu Mar 09 15:29:52 2006] [error] [client 58.104.122.206] fopen: Permission denied, referer: http://www.lettertogod.net/
[Thu Mar 09 15:29:52 2006] [error] [client 58.104.122.206] Premature end of script headers: guestbook.cgi, referer: http://www.lettertogod.net/


still got this problem

not sure if i deleted the right part

FishMonger
03-09-2006, 05:51 AM
What does it mean when my CGIs fail with "Premature end of script headers"?

http://httpd.apache.org/docs/1.3/misc/FAQ-F.html#premature-script-headers

helper
03-09-2006, 06:39 AM
sorry fishmonger but you have lost me

i really dont understand the page you sent me to or what i should do with it


hmmm

very puzzled here


Doug:confused:

FishMonger
03-09-2006, 09:09 AM
That page is telling you the most common cause of the error message you're receiving. Basicly it says that the script died (exited) prior to printing the content type header.

Here's a somewhat cleaned up version (I removed some of the garbage code and added a little error handling).

helper
03-09-2006, 10:10 AM
hello

i tried the revised script

and got these errors from the log

[Thu Mar 09 19:58:46 2006] [error] [client 58.104.122.206] failed to open log file /var/log/httpd/suexec_log, referer: http://www.lettertogod.net/
[Thu Mar 09 19:58:46 2006] [error] [client 58.104.122.206] fopen: Permission denied, referer: http://www.lettertogod.net/
[Thu Mar 09 19:58:46 2006] [error] [client 58.104.122.206] Premature end of script headers: guestbook.cgi, referer: http://www.lettertogod.net/
[client 207.46.98.149] script '/home/httpd/vhosts/lettertogod.net/httpdocs/letters/profile.php' not found or unable to stat
[Thu Mar 09 20:01:20 2006] [error] [client 58.104.122.206] failed to open log file /var/log/httpd/suexec_log, referer: http://www.lettertogod.net/
[Thu Mar 09 20:01:20 2006] [error] [client 58.104.122.206] fopen: Permission denied, referer: http://www.lettertogod.net/
[Thu Mar 09 20:01:20 2006] [error] [client 58.104.122.206] Premature end of script headers: guestbook.cgi, referer: http://www.lettertogod.net/
[Thu Mar 09 20:03:03 2006] [error] [client 58.104.122.206] failed to open log file /var/log/httpd/suexec_log, referer: http://www.lettertogod.net/
[Thu Mar 09 20:03:03 2006] [error] [client 58.104.122.206] fopen: Permission denied, referer: http://www.lettertogod.net/
[Thu Mar 09 20:03:03 2006] [error] [client 58.104.122.206] Premature end of script headers: guestbook.cgi, referer: http://www.lettertogod.net/
[Thu Mar 09 20:03:08 2006] [error] [client 58.104.122.206] failed to open log file /var/log/httpd/suexec_log
[Thu Mar 09 20:03:08 2006] [error] [client 58.104.122.206] fopen: Permission denied
[Thu Mar 09 20:03:08 2006] [error] [client 58.104.122.206] Premature end of script headers: guestbook.cgi
[Thu Mar 09 20:03:17 2006] [error] [client 58.104.122.206] failed to open log file /var/log/httpd/suexec_log, referer: http://www.lettertogod.net/
[Thu Mar 09 20:03:17 2006] [error] [client 58.104.122.206] fopen: Permission denied, referer: http://www.lettertogod.net/
[Thu Mar 09 20:03:17 2006] [error] [client 58.104.122.206] Premature end of script headers: guestbook.cgi, referer: http://www.lettertogod.net/


maybe I am doing something wrong
i upload chmod properly

change the email to my email

do I leave the \ in the email

boy this is tuff

many tahnks for your time
i really appreciate it

FishMonger
03-09-2006, 05:38 PM
[Thu Mar 09 20:03:08 2006] [error] [client 58.104.122.206] failed to open log file /var/log/httpd/suexec_log
[Thu Mar 09 20:03:08 2006] [error] [client 58.104.122.206] fopen: Permission deniedThe fopen error is comming from a php script and the other one is either comming from the same php script or is a misconfiguration in the web server. I can't help with that one.

[Thu Mar 09 20:03:08 2006] [error] [client 58.104.122.206] Premature end of script headers: guestbook.cgiThe adjustments I made took care of the most common cause of that error or at least should give additional error details. Since you're still getting it and it doesn't include the addtional details, it would indicate to me that the script was uploaded in binary mode this would prevent the line endings from being translated from Windows to unix which prevents the web server from properly executing the script.

do I leave the \ in the emailYes. Without it, Perl will try to interpolate @myhost.com as an array instead of an email address.

helper
03-10-2006, 02:06 AM
Hi there

I have uploaded making sure it is in acsi

and i still just get an internal server error

and the same header message in my log

curious