Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Web broadcast e-mail perl script

by wfsp (Abbot)
on Aug 21, 2010 at 16:14 UTC ( [id://856477]=note: print w/replies, xml ) Need Help??


in reply to Web broadcast e-mail perl script

I think dasgar has identified the reason you are getting that output from your script.

Not what you want perhaps but it does reveal that

  • the web server can find the script
  • it is executable (has the right permissions)
  • the shebang line (the first one) is correct
  • the line endings are correct
  • the code compiles
  • the appropriate modules are available
  • the code runs
  • you get understandable, if unwanted, output
When you are debugging cgi scripts that is a result. You're halfway there. :-)

The script has warnings enabled (the -w on the shebang line) and uses CGI.pm. Also a good thing.

If you're starting out on working with cgi scripts I would suggest putting your script to one side and writing a cut down version and get that working. For instance, if you are able to create a dir under cgi-bin you could create a /cgi-bin/test/test.cgi like the following (i.e. leaving out the email side of things).

test.cgi

#!/usr/bin/perl -w use CGI; $query = new CGI; # let CGI.pm print the content header print $query->header; $cc = $query->param("Ccemail"); $from = $query->param("From"); $subject = $query->param("Subject"); $comment = $query->param("Comment"); $file = $query->param("Attach"); @name = split(/\\/, $file); $name = $name[$#name]; @list = $query->param("list"); $list = join(",", @list); # change the file name to include a path that # the web server can write to # e.g. the path you have in your script open(UPLOAD, ">uploaded_file.txt") or die "Sorry, cannot open $FILE: $!"; my ($data, $chunk); while ($chunk = read($file, $data, 1024)){ print UPLOAD $data; } close(UPLOAD) or die "Cannot close $FILE: $!"; # let CGI.pm help output well formed HTML print $query->start_html; print "subject: $subject<br>"; print "from: $from<br>"; print "cc: $cc<br>"; print "comment: $comment<br>"; print "Attachment: $name<br>"; print $query->end_html;
I've tried to keep the script as close to yours as possible (differences have comments) so that it will be familiar but have taken out the email stuff. Get this bit working first. Set the permissions to executable (0755 ought to do it). A test.txt somewhere you can find it e.g.
one two three
And a test.html in, say, the document root
<html> <head> <title>form test</title> </head> <body> <p>upload file</p> <form name = "test_form" action = "/cgi-bin/test/test.cgi" method = "post" enctype = "multipart/form-data" > from:<br> <input type="text" name="From" ><br> subject:<br><input type="text" name="Subject" ><br> comment:<br><input type="text" name="Comment" ><br> cc:<br> <input type="text" name="Ccemail" ><br> list:<br> <input type="checkbox" name="list" value="Car" > car + <input type="checkbox" name="list" value="Bike"> bik +e<br> attach:<br> <input type="file" name="Attach"><br> <input type="submit" name="Submit" value="Submit"> </form> </body> </html>
The html has a lot of whitespace blown into it which I find useful while developing.

Typing http://your_domain/test.html into your browser should bring up the form. Fill in some dummy data and, if the wind is in the right direction, you will see something like

subject: web broadcast from: a@b.com cc: b@b.com comment: hello Attachment: test.txt
and there should be a file upload_file.txt in cgi-bin/test or wherever you set the path to in the script.

There are a number of good tutorials that will help and it is worth have a look at the docs for CGI.pm (at least, the methods that you are using - there is rather a lot of it).

There are a number of improvements that could be made (secutity, error checking etc) and many other approaches to developing cgi scripts (e.g. setting up your own local web server rather that 'playing' on a production server) but I reckon it's best to build up gradually .

Hope this helps, let us know how you get on and get back to us if you need any more help.

By the way, your introduction to perl was identical to my own. :-)

Good luck!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://856477]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (None)
    As of 2024-04-25 04:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found