in reply to Web broadcast e-mail perl script
Not what you want perhaps but it does reveal that
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
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.#!/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;
And a test.html in, say, the document rootone two three
The html has a lot of whitespace blown into it which I find useful while developing.<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>
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
and there should be a file upload_file.txt in cgi-bin/test or wherever you set the path to in the script.subject: web broadcast from: a@b.com cc: b@b.com comment: hello Attachment: test.txt
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!
|
|---|