homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

keep encountering Perl error

 3:32 am on Mar 15, 2011 (gmt 0)

I am a bit of a novice with CGI scripting, and you seem like a helpful bunch...hopefully you can help me with this issue I am having with an upload form.

I wanted to add a form to a website so visitors can upload audio files; I'm pretty certain the HTML is good, and the server settings appear to be fine as well (as do the paths for the .cgi file, and the upload folder), but I keep getting various errors whenever I try to test the form. The last error I got was:

Global symbol "$email" requires explicit package name at upload.cgi line 45.

I don't see "$email" anywhere in the vicinity of line 45, which is where the "thank you" message HTML starts. Further down, "$email" is in the HTML (where it references the visitor's email for the "thank you" message), but even if I add "my" in front of it, I still get the same error. What might I be doing wrong to cause this error?

Many thanks in advance...



 5:35 am on Mar 15, 2011 (gmt 0)

welcome to WebmasterWorld, drgonzo!

you must declare your variables within the same scope in which they are referred.

for example if you did this:

my $variable;
$variable = 1;

then "$variable" would be declared within the scope of the "if" and the "$variable" in the assignment statement would be an undeclared variable.


 2:38 am on Mar 16, 2011 (gmt 0)

Aha! I had $email, when I needed $email_address. All I needed was another look...thanks, Phranque.

Now I just need to be able to receive an email letting me know that form data has been submitted...I don't need to have the file that was uploaded actually emailed to me (most files uploaded via this particular form will probably be too large for email anyway), but I do need to receive an email notification that a file has been uploaded. I found info about Formmail.pl, but that seems to be pretty involved...is there a simpler way to get an email sent to me that just tells me someone has uploaded something via my CGI script?

Also, I see the file I uploaded as a test in my "upload" folder on the server, but where is the rest of the form data (name, email address, etc)? I don't see that in the upload folder at all...

Thanks again for the help!


 8:49 am on Mar 16, 2011 (gmt 0)

you can use sendmail to send a simple email - something like:

open(SENDMAIL, "|/usr/sbin/sendmail -t"or die "Cannot open sendmail: $!";
print SENDMAIL "Reply-to: me\@my.com\n";
print SENDMAIL "Send-to: you\@your.com\n";
print SENDMAIL "Subject: file uploaded\n";
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "form data has been submitted";

and you can use CGI [perldoc.perl.org] to access the form parameters values and save them in a file or db according to your requirements.


 3:24 am on Mar 17, 2011 (gmt 0)
Thanks again, phranque...that looks a lot more manageable than Formmail. I am guessing I will insert the sendmail commands into my upload.cgi script file; does it matter where I put that, or does it need to be in a specific place in the script? And I know I will obviously need to change the "me\@my.com" and "you\@your.com" addresses...will I also need to change "|/usr/sbin/sendmail" as well?

Sorry if that is a stupid question, I am pretty unfamiliar with all of this...it seems like I would need to change that to refer to my mail program on my server, but I am not quite sure exactly how to do that. The mail folder on my server is "/home/suppress/mail", but when I insert that in place of "/usr/sib" (so that the first line reads:

open(SENDMAIL, "|/home/suppress/mail/sendmail -t") or die "Cannot open sendmail: $!";)

...I get an error message at that line (Insecure $ENV{PATH} while running with -T switch at upload.cgi line 45) when I try to run the script. Do I need to reference something different there?

Sorry again if these are simple/elementary questions...please forgive my "newb-ness"!

Many thanks again...

 10:36 am on Mar 17, 2011 (gmt 0)

you have to find out where sendmail is installed on your server.
/usr/sbin/ is a common directory for sendmail installation.

then you need to read the perldoc on perlsec:
http://perldoc.perl.org/perlsec.html [perldoc.perl.org]
note especially the sections on "Taint mode" and "Cleaning Up Your Path".
then set $ENV{PATH} to an appropriate value.

and i would send out the email after successfully processing the request.


 8:56 pm on Mar 24, 2011 (gmt 0)
Hello phranque--
My provider confirmed that the sendmail location is good, once I took out the vertical line (|) before /usr...then I was getting an error message saying "Cannot open sendmail: No such file or directory at upload.cgi line 64." So, they had me remove the -t key from the "/usr/sbin/sendmail" instruction, and then I stopped getting an error...but I still haven't gotten any email notification as a result of the test.

I know the email address I am using is good, and I have it listed as per your example above (print SENDMAIL "Send-to: you\@your.com\n";), with my good address instead of the generic addy, or course.

I Googled it and found a slightly different version of the script, that basically used just MAIL instead of SENDMAIL, but it also included a final line of:
print MAIL "\n.\n";

...before the "close( MAIL );" line, which the tutorial I found online said would tell sendmail to actually send the message, but I still received no email when I used those modifications. I've checked my junk mail folder online for the email account in the "send to" field, but still nothing.

Any suggestions?

Thanks again,

 9:45 pm on Mar 24, 2011 (gmt 0)
I don't believe your problem is actually with sendmail, it's rather that you're running perl in Taint-Mode. Look at the shebang (that's usually the first line of your script), it probably says something like
#!/usr/bin/perl -T
There might be -wT or something else. The T advises perl to setup a very secure environment that'll complain when you try to use something it doesn't consider secure.
In your case, it seems to dislike the Path in %ENV. Easy solution: delete the -T from the shebang (or, if there are multiple arguments, delete the T).
The "-t" and the Pipe-Char (|) in calling sendmail are not related to the error message. The pipe char actually tells perl not to open the path as a file but rather as a program to be executed.

Just try to reset the Sendmail-calls to the original and remove the -T from the shebang. Report back if that doesn't help.

 10:14 pm on Mar 24, 2011 (gmt 0)

Hello janharders--
I reset the Sendmail-calls to the original state and then deleted -t in the shebang (actually just "t"), and I again get no error message, and a successful upload...but still no email confirmation message. I reconfirmed that the email address is good, and before I tested the adjusted script I sent a test email to the recipient address via my email client, and it came through fine.

Thanks for the quick response...but it still doesn't seem to want to send me a confirmation email...

Any other possible solutions?


 10:57 pm on Mar 24, 2011 (gmt 0)

I suppose you don't have access to the mail-log to see what happened to the email? Can you access the mail-logs of the receiving mail-server to see wether it was contacted about the email and maybe rejected it?

Uhm. Shame on me, I haven't really been paying attention. I think the problem lies in your email that you submit to sendmail.

print SENDMAIL "Reply-to: me\@my.com\n";
print SENDMAIL "Send-to: you\@your.com\n";

Should, imho rather be
print SENDMAIL "From: me\@my.com\n";
print SENDMAIL "To: you\@your.com\n";

give that a try. If that does not work and you cannot access the logs, send me a private message and I'll give you an email address that you can test where I can check the log to see wether the sending server actually tried to contact the receiving server.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved