View Full Version : Any CGI programmers around here ?
cmM
12th of November 2004 (Fri), 08:01
I'm really new at it and I have this script to forward the contents of a form to my e-mail address (my guestbook on cmuntean.net), but it does everything but forwarding the damned thing. I really think that there's something wrong with the server, and not my script.
here's the HTML part:
<form name="ask" action="guestbook.cgi" method="post" enctype="text/plain">
Name:<br><input type="text" name="name" .....
and here's my CGI script:
#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
print header;
print start_html("Results");
$ENV{PATH} = "/usr/sbin/sendmail";
open (MAIL, "|/usr/sbin/sendmail -oi -t ") or &dienice("Can't fork for sendmail: $!\n");
my $recipient = 'cmuntean@sbcglobal.net';
print MAIL "To: $recipient\n";
print MAIL "From: emails\@cmuntean.net \n";
print MAIL "Subject: cmuntean.net guestbook\n\n";
foreach my $p (param()) {
print MAIL "$p = ", param($p), "\n";
}
close(MAIL);
print <<EndHTML;
<body bgcolor="#7A6D6D" text="#660000" link="#660000" vlink="#660000">
<font face="Tahoma" size ="1">
<br><br><br><br>
<h2 align="center">Thank You</h2>
<hr width="250" size="2">
<p align="center"><a href="javascript:window.close();">close window</a></p>
</font>
EndHTML
print end_html;
sub dienice {
my ($errmsg) = @_;
print "<h2>Error</h2>\n";
print "<p>$errmsg</p>\n";
print end_html;
exit;
}
My hosting provider does allow CGI scripts, the paths to sendmail are right, there are sufficient file permissions, and the script is run and the "thank you" page displays, it just doesn't e-mail me the contents.
Do I have some syntax errors or what is going on? It looks ok to me, but then again, I haven't been around it so much.
Any help would be appreciated.
Scottes
12th of November 2004 (Fri), 08:12
How's DNS on the machine? Can you log into the machine and try:
dig mx sbcglobal.net
or
nslookup
> set type=mx
> sbcglobal.net
And make sure that you get something valid?
Can you "mail -v cmuntean@sbcglobal.net" and send a sinple mail and look at the output to see if it's OK?
Is this a smple script you borrowed? I'm used to building $message and then:
open(MAIL... ;
print MAIL $message;
close MAIL;
Just habit though. Your way *should* be OK.
Can you install a module and try Net::SMTP or MIME::Lite?
Scottes
12th of November 2004 (Fri), 08:19
----- The following addresses had permanent fatal errors -----
cmuntean@sbcglobal.net
(reason: 550 Invalid recipient/sender mailing address)
----- Transcript of session follows -----
... while talking to sbcmx3.prodigy.net.:
>>> RCPT To:<cmuntean@sbcglobal.net>
<<< 550 Invalid recipient/sender mailing address
550 5.1.1 cmuntean@sbcglobal.net... User unknown
--iACFPp613486.1100273151/xena.sqa21.com
Content-Type: message/delivery-status
But when I switched to a real email address, mine at work, it ran just fine.
So the email address is suspect, but when it comes to mail DNS is *always* suspect.
cmM
12th of November 2004 (Fri), 08:30
hmmm.....
that is weird. I knew it!
What's even more weird, is that a had a CGI script for a different form e-mail me to the same address and it worked just fine.
let's see here
PacAce
12th of November 2004 (Fri), 08:36
Have you tried hardcoding the recipient email address instead of using a variable? If not, you might want to try that first to make sure you're not getting screwed up by a misvalued variable.
The only line I find questionable is
my $recipient = 'cmuntean@sbcglobal.net';
I'm not sure what the 'my' is being used for. It may be legit but I'm not familar with it's use if it is.
[edit]Oops, looks like Scott may have it figured out. Should have read all the way down before responding. :oops:
cmM
12th of November 2004 (Fri), 08:43
yea, it is the e-mail address.... dammit
well that sucks.... because that's probably my most "legitimate" e-mail address.
Thanks Scott
Scottes
12th of November 2004 (Fri), 09:16
because that's probably my most "legitimate" e-mail address.
Not any more - it doesn't exist. :?
cmM
12th of November 2004 (Fri), 09:49
because that's probably my most "legitimate" e-mail address.
Not any more - it doesn't exist. :?
yes it does. cmuntean@sbcglobal.net is the address I use most actually.
Scottes
12th of November 2004 (Fri), 10:12
Actually, it might not be the email address at all. My outbound firewall is redirecting my SMTP packets to an internal mail server here at work. So of course the address fails.
I can't test this from my home system because I'm on ComCast and Prodigy is blocking inbound mail from ComCast home systems. (Which is expected nowadays.)
So go back to my first message, log into the host and see what happens with those commands I gave you. The script works fine, so we're back to DNS on that system. Or possibly a firewall blocking outbound SMTP but I wouldn't expect that,
tommykjensen
12th of November 2004 (Fri), 10:25
You probably have checked this already but make sure that the sending email address is valid too.
print MAIL "From: emails\@cmuntean.net \n";
I have no knowledge about CGI script but if I interpret that correctly You are setting the sending email address to emails@cmuntean.net . Does this email address exist? Most email servers are setup to only allow sending from valid email addresses to prevent spamming/relaying.
PacAce
12th of November 2004 (Fri), 10:36
You probably have checked this already but make sure that the sending email address is valid too.
print MAIL "From: emails\@cmuntean.net \n";
I have no knowledge about CGI script but if I interpret that correctly You are setting the sending email address to emails@cmuntean.net . Does this email address exist? Most email servers are setup to only allow sending from valid email addresses to prevent spamming/relaying.
You don't need a valid email address for the sender. I've used fake email addresses in my mail scripts without a problem....unless, of course, it varies from server to server.
tommykjensen
12th of November 2004 (Fri), 10:44
You don't need a valid email address for the sender. I've used fake email addresses in my mail scripts without a problem....unless, of course, it varies from server to server.
It does depend on emailserver settings. Some allow it some don't. Mine for example don't allow fake addresses. At work our email server is also configured not to allow fake email adresses.
cmM
12th of November 2004 (Fri), 11:05
the sender e-mail address does not exist.
However, the script works just fine with a different e-mail address
cmM
12th of November 2004 (Fri), 11:08
okay.... my hosting provider has a "CGI output monitor"
After testing my script it seems to be just fine:
+ CGI Check succeeded
Content-Type: text/html; charset=ISO-8859-1
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>Results</title>
</head><body><body bgcolor="#7A6D6D" text="#660000" link="#660000" vlink="#660000">
<font face="Tahoma" size ="1">
<br><br><br><br><h2 align="center">Thank You</h2>
<hr width="250" size="2">
<p align="center"><a href="javascript:window.close();">close window</a></p></font>
</body></html>
STDOUT OK STDERR OK
Scottes, I don't know if I have the privileges to log into the server and test out those commands. How do you do that ?
cmM
12th of November 2004 (Fri), 11:39
ok.... I'm thinkin here.
Instead of that e-mail address I used cmm@cmuntean.net
Using that address with nothing else changed works perfect and I get the e-mail almost instantly. Would it make any difference if the e-mail address is hosted by them and the mail does not have to go outside?
I think the server takes a long time to send mail outside. (I tried sending me an e-mail from cmm@cmuntean.net to my initial e-mail cmuntean@sbcglobal.net and I have not received anything yet..... probably a real long queue).
I e-mail tech support to check into it but no response yet.
**Edit: e-mailing worked from the server to an outside address (got the e-mail). I still think they have some "sendmail" issues, because it still does not work through the script.
Scottes
12th of November 2004 (Fri), 12:06
The Prodigy mail server blocked my attempt from my home system. This is fairly common since a home cable user shouldn't be running a mail server, but worm-infected cable systems often do.
Perhaps Prodigy's mail server thinks that your server's IP is in a bad block of IPs? You may be screwed if this is the case.
Which would explain why it works with @cmuntean.net since the provider wouldn't block it's own IPs.
I wouldn't be surprised if you're not allowed to run those commands on your server - it's probably a virtual host anyway. Which may also explain why it might be on Prodigy's block list - if one of the other virtual hosts did a bad thing....
cmM
12th of November 2004 (Fri), 12:25
well....
the IP address is not blacklisted, firewalls are not blocking the mail...
I just received an e-mail from the script....... from 3 days ago, the first one I sent to test it out.
Turns out it's just a slow POS server and it takes a humongous amount of time to send the mail or there's a very long queue. (worked much faster with cmm@cmuntean.net however).
So much for the great 1and1.com web hosting provider. I need to talk to someone there.
Thanks for taking the time and investigating into this.... my script is ok, and I think I'll just use the @cmuntean.net e-mail for that.
Scottes
12th of November 2004 (Fri), 12:32
Turns out it's just a slow POS server and it takes a humongous amount of time to send the mail or there's a very long queue.
That's not the way sendmail works - at least not how you're calling it. By calling sendmail directly you are telling it to immediately connect to the mail server and deliver the message.
So it must be the Prodigy mail server.
Try changing the sendmail line to "| /usr/sbin/sendmail -oi -t -v" for verbose and do whatever you need to do to trap STDOUT so you can read the output of the -v.
However, this is getting kinda moot. You aren't going to fix this problem. And you're probably not going to get someone else to fix it either. So the real answer lies in using a different email address - just like you are doing.
:)
vBulletin® v3.6.12, Copyright ©2000-2012, Jelsoft Enterprises Ltd.