Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
cgi script to send mail failing
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- cgi script to send mail failing
cgi script to send mail failing
02-05-2010 11:45 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi,
A simple cgi script that's been working fine now fails. The script takes the data from a form and uses sendmail to email the content back to me.
I've tried changing the sendmail location from /usr/sbin to /usr/lib which made no difference and I changed the email address to my plusnet address which also didn't change anything.
I suspect it may have stopped working when php was upgraded.
Has anybody come across this or can anybody see the problem with the attached script?
Thanks,
Mike
#!/usr/bin/perl -wT
#
# mail-form cgi
# Quick and dirty Web form processing script. Emails the data
# to the recipient.
#
# You should change any variable that has "CONFIGURE" in the
# comment.
#### modules (these don't need changing)
#
# be strict, define all variables
use strict;
# use CGI.pm for parsing form data and printing headers/footers
use CGI;
# redirect errors to the browser window
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
# create an instance of CGI.pm:
my($cgi) = CGI->new;
# CONFIGURE: change this to the proper location of sendmail on your system:
my($mailprog) = '/usr/sbin/sendmail';
# Set the path, so taint mode won't complain. This should be the path
# that sendmail lives in! (If you're using /usr/lib/sendmail, then
# the path had better be /usr/lib here.)
$ENV{PATH} = "/sbin/lib";
# CONFIGURE: change this to the e-mail address you want to receive the
# mailed form data
my($recipient) = 'info@millennium-internet.co.uk';
# CONFIGURE: change this to your URL:
my($homepage) = "http://www.millennium-internet.co.uk/";
# CONFIGURE: change this to the subject you want the e-mail to have
# WARNING: Do NOT Let the form specify the subject line, or your
# program can be hijacked by spammers!!!
my($subj) = "Question from Millennium Website";
# everything below this shouldn't need changing, except possibly the
# "thank you" page at the end.
# Print out a content-type header
print $cgi->header;
# CGI.pm automatically parses the data, and you can retrieve it using
# $cgi->param("fieldname")
# Now send mail to $recipient
open (MAIL, "|$mailprog -t") || &dienice("Can't open $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "From: $recipient\n";
print MAIL "Subject: $subj\n\n";
# print all of the form fields:
foreach my $i ($cgi->param()) {
print MAIL $i . ": " . $cgi->param($i) . "\n";
}
print MAIL "\n\n";
# print some extra info:
# print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
# print MAIL "HTTP From: $ENV{'HTTP_FROM'}\n";
# print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
# print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);
# CGI.pm prints the HTML header
print $cgi->start_html(-title=>"Thank You",
-bgcolor=>"#ffffff",
-text=>"#000000");
# CONFIGURE:
# Print a thank-you page - you can customize this however you wish.
# Be sure to use proper HTML, and escape any $-signs or @-signs with a
# backslash, e.g.: \$25.00, nullbox\@cgi101.com
print <<EndHTML;
<H2>Thank you for writing!</H2>
<p>
Thank you for your message. Return to the
<a href="$homepage">home page.</a>
</p>
EndHTML
# CGI.pm prints the HTML footer
print $cgi->end_html;
# error handler
sub dienice {
my($msg) = @_;
print $cgi->start_html(-title=>"Error");
print qq(<h2>Error</h2>\n);
print $msg;
print $cgi->end_html;
exit;
}
# the end.
A simple cgi script that's been working fine now fails. The script takes the data from a form and uses sendmail to email the content back to me.
I've tried changing the sendmail location from /usr/sbin to /usr/lib which made no difference and I changed the email address to my plusnet address which also didn't change anything.
I suspect it may have stopped working when php was upgraded.
Has anybody come across this or can anybody see the problem with the attached script?
Thanks,
Mike
#!/usr/bin/perl -wT
#
# mail-form cgi
# Quick and dirty Web form processing script. Emails the data
# to the recipient.
#
# You should change any variable that has "CONFIGURE" in the
# comment.
#### modules (these don't need changing)
#
# be strict, define all variables
use strict;
# use CGI.pm for parsing form data and printing headers/footers
use CGI;
# redirect errors to the browser window
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
# create an instance of CGI.pm:
my($cgi) = CGI->new;
# CONFIGURE: change this to the proper location of sendmail on your system:
my($mailprog) = '/usr/sbin/sendmail';
# Set the path, so taint mode won't complain. This should be the path
# that sendmail lives in! (If you're using /usr/lib/sendmail, then
# the path had better be /usr/lib here.)
$ENV{PATH} = "/sbin/lib";
# CONFIGURE: change this to the e-mail address you want to receive the
# mailed form data
my($recipient) = 'info@millennium-internet.co.uk';
# CONFIGURE: change this to your URL:
my($homepage) = "http://www.millennium-internet.co.uk/";
# CONFIGURE: change this to the subject you want the e-mail to have
# WARNING: Do NOT Let the form specify the subject line, or your
# program can be hijacked by spammers!!!
my($subj) = "Question from Millennium Website";
# everything below this shouldn't need changing, except possibly the
# "thank you" page at the end.
# Print out a content-type header
print $cgi->header;
# CGI.pm automatically parses the data, and you can retrieve it using
# $cgi->param("fieldname")
# Now send mail to $recipient
open (MAIL, "|$mailprog -t") || &dienice("Can't open $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "From: $recipient\n";
print MAIL "Subject: $subj\n\n";
# print all of the form fields:
foreach my $i ($cgi->param()) {
print MAIL $i . ": " . $cgi->param($i) . "\n";
}
print MAIL "\n\n";
# print some extra info:
# print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
# print MAIL "HTTP From: $ENV{'HTTP_FROM'}\n";
# print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
# print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);
# CGI.pm prints the HTML header
print $cgi->start_html(-title=>"Thank You",
-bgcolor=>"#ffffff",
-text=>"#000000");
# CONFIGURE:
# Print a thank-you page - you can customize this however you wish.
# Be sure to use proper HTML, and escape any $-signs or @-signs with a
# backslash, e.g.: \$25.00, nullbox\@cgi101.com
print <<EndHTML;
<H2>Thank you for writing!</H2>
<p>
Thank you for your message. Return to the
<a href="$homepage">home page.</a>
</p>
EndHTML
# CGI.pm prints the HTML footer
print $cgi->end_html;
# error handler
sub dienice {
my($msg) = @_;
print $cgi->start_html(-title=>"Error");
print qq(<h2>Error</h2>\n);
print $msg;
print $cgi->end_html;
exit;
}
# the end.
Message 1 of 7
(1,876 Views)
6 REPLIES 6
Re: cgi script to send mail failing
02-05-2010 12:24 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Make sure the perl script only has 700 permissions (rwx------). Any other permissions set for group or world/all will mean the script will not run.
http://community.plus.net/library/settings/cgi-platform-php-upgrade-faq/ item 6
http://community.plus.net/library/settings/cgi-platform-php-upgrade-faq/ item 6
Message 2 of 7
(678 Views)
Re: cgi script to send mail failing
02-05-2010 1:00 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Thanks Peter,
I have tried changing the permissions. It was set to 740. I've changed it to 700 but still get the same result.
Any other suggestions?
Thanks,
Mike
I have tried changing the permissions. It was set to 740. I've changed it to 700 but still get the same result.
Any other suggestions?
Thanks,
Mike
Message 3 of 7
(678 Views)
Re: cgi script to send mail failing
04-05-2010 10:15 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
The script seems to work. Do you get anything if you call it directly with ?foo=bar after the url?
Gabe
Gabe
Message 4 of 7
(679 Views)
Re: cgi script to send mail failing
04-05-2010 12:11 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi Gabe,
I get the same result as if I'd pressed submit on my form.
http://ccgi.mikefa.plus.com/cgi-bin/mill/millemail.php?foo=bar or form
# # mail-form cgi # Quick and dirty Web form processing script. Emails the data # to the recipient. # # You should change any variable that has "CONFIGURE" in the # comment. #### modules (these don't need changing) # # be strict, define all variables use strict; # use CGI.pm for parsing form data and printing headers/footers use CGI; # redirect errors to the browser window use CGI::Carp qw(warningsToBrowser fatalsToBrowser); # create an instance of CGI.pm: my($cgi) = CGI->new; # CONFIGURE: change this to the proper location of sendmail on your system: my($mailprog) = '/usr/sbin/sendmail'; # Set the path, so taint mode won't complain. This should be the path # that sendmail lives in! (If you're using /usr/lib/sendmail, then # the path had better be /usr/lib here.) $ENV{PATH} = "/sbin/lib"; # CONFIGURE: change this to the e-mail address you want to receive the # mailed form data my($recipient) = 'info@millennium-internet.co.uk'; # CONFIGURE: change this to your URL: my($homepage) = "http://www.millennium-internet.co.uk/"; # CONFIGURE: change this to the subject you want the e-mail to have # WARNING: Do NOT Let the form specify the subject line, or your # program can be hijacked by spammers!!! my($subj) = "Question from Millennium Website"; # everything below this shouldn't need changing, except possibly the # "thank you" page at the end. # Print out a content-type header print $cgi->header; # CGI.pm automatically parses the data, and you can retrieve it using # $cgi->param("fieldname") # Now send mail to $recipient open (MAIL, "|$mailprog -t") || &dienice("Can't open $mailprog!\n"); print MAIL "To: $recipient\n"; print MAIL "From: $recipient\n"; print MAIL "Subject: $subj\n\n"; # print all of the form fields: foreach my $i ($cgi->param()) { print MAIL $i . ": " . $cgi->param($i) . "\n"; } print MAIL "\n\n"; # print some extra info: # print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n"; # print MAIL "HTTP From: $ENV{'HTTP_FROM'}\n"; # print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n"; # print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n"; close (MAIL); # CGI.pm prints the HTML header print $cgi->start_html(-title=>"Thank You", -bgcolor=>"#ffffff", -text=>"#000000"); # CONFIGURE: # Print a thank-you page - you can customize this however you wish. # Be sure to use proper HTML, and escape any $-signs or @-signs with a # backslash, e.g.: \$25.00, nullbox\@cgi101.com print <
Thank you for writing!
Thank you for your message. Return to the home page.
EndHTML # CGI.pm prints the HTML footer print $cgi->end_html; # error handler sub dienice { my($msg) = @_; print $cgi->start_html(-title=>"Error"); print qq(
Error
\n); print $msg; print $cgi->end_html; exit; } # the end.
I've tried passing the variables that the form passes to the script and get the same result.
Which has got me wondering if they are not being passed correctly to the script by the form.
Any reason for anything to have changed in this area?
You can see the actual form at www.millennium-internet.co.uk if it helps.
Any suggestions gratefully received.
Thanks,
Mike
I get the same result as if I'd pressed submit on my form.
http://ccgi.mikefa.plus.com/cgi-bin/mill/millemail.php?foo=bar or form
# # mail-form cgi # Quick and dirty Web form processing script. Emails the data # to the recipient. # # You should change any variable that has "CONFIGURE" in the # comment. #### modules (these don't need changing) # # be strict, define all variables use strict; # use CGI.pm for parsing form data and printing headers/footers use CGI; # redirect errors to the browser window use CGI::Carp qw(warningsToBrowser fatalsToBrowser); # create an instance of CGI.pm: my($cgi) = CGI->new; # CONFIGURE: change this to the proper location of sendmail on your system: my($mailprog) = '/usr/sbin/sendmail'; # Set the path, so taint mode won't complain. This should be the path # that sendmail lives in! (If you're using /usr/lib/sendmail, then # the path had better be /usr/lib here.) $ENV{PATH} = "/sbin/lib"; # CONFIGURE: change this to the e-mail address you want to receive the # mailed form data my($recipient) = 'info@millennium-internet.co.uk'; # CONFIGURE: change this to your URL: my($homepage) = "http://www.millennium-internet.co.uk/"; # CONFIGURE: change this to the subject you want the e-mail to have # WARNING: Do NOT Let the form specify the subject line, or your # program can be hijacked by spammers!!! my($subj) = "Question from Millennium Website"; # everything below this shouldn't need changing, except possibly the # "thank you" page at the end. # Print out a content-type header print $cgi->header; # CGI.pm automatically parses the data, and you can retrieve it using # $cgi->param("fieldname") # Now send mail to $recipient open (MAIL, "|$mailprog -t") || &dienice("Can't open $mailprog!\n"); print MAIL "To: $recipient\n"; print MAIL "From: $recipient\n"; print MAIL "Subject: $subj\n\n"; # print all of the form fields: foreach my $i ($cgi->param()) { print MAIL $i . ": " . $cgi->param($i) . "\n"; } print MAIL "\n\n"; # print some extra info: # print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n"; # print MAIL "HTTP From: $ENV{'HTTP_FROM'}\n"; # print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n"; # print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n"; close (MAIL); # CGI.pm prints the HTML header print $cgi->start_html(-title=>"Thank You", -bgcolor=>"#ffffff", -text=>"#000000"); # CONFIGURE: # Print a thank-you page - you can customize this however you wish. # Be sure to use proper HTML, and escape any $-signs or @-signs with a # backslash, e.g.: \$25.00, nullbox\@cgi101.com print <
Thank you for writing!
Thank you for your message. Return to the home page.
EndHTML # CGI.pm prints the HTML footer print $cgi->end_html; # error handler sub dienice { my($msg) = @_; print $cgi->start_html(-title=>"Error"); print qq(
Error
\n); print $msg; print $cgi->end_html; exit; } # the end.
I've tried passing the variables that the form passes to the script and get the same result.
Which has got me wondering if they are not being passed correctly to the script by the form.
Any reason for anything to have changed in this area?
You can see the actual form at www.millennium-internet.co.uk if it helps.
Any suggestions gratefully received.
Thanks,
Mike
Message 5 of 7
(679 Views)
Re: cgi script to send mail failing
04-05-2010 12:35 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Try changing the extension to .pl
Gabe
Gabe
Message 6 of 7
(679 Views)
Re: cgi script to send mail failing
04-05-2010 1:06 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi Gabe,
That's it! It now works as before.
Thanks a million.
Cheers,
Mike
That's it! It now works as before.
Thanks a million.
Cheers,
Mike
Message 7 of 7
(679 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- cgi script to send mail failing