Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 20th, 2005, 10:17 AM   #1
glevine
Newbie
 
Join Date: Jun 2005
Posts: 22
Rep Power: 0 glevine is on a distinguished road
2 problems with a script

I set up an email list for a project I am working on. I used perl to write a script which reads a subject and content (content is written in html) from a webpage and sends them to the email list.

Problem #1: I tried to test it out by sending an email to myself, as opposed to the list. So I commented out the line which specifies the list as the recipient and added $recipient='myemailaddress';. I uploaded it to the server, wrote a simple html page to use as content and fired off an email. When I received the email in my inbox I also received 3 blank emails from the same source. Has anyone ever seen an error like this?

Problem #2: I tried to test it out by sending an email to the list, as opposed to myself. I removed all email addresses in the list and added 4 email addresses which all go to me. I fired off another email. This time I received 4 replies from the program to my email address which is the list manager address (or sender). All four said the same thing.

From MAILER-DAEMON@mail.___.com (I took my domain name in all cases):
"Hi. This is the qmail-send program at mail.___.net.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<email@address_of_list>:
ezmlm-reject: fatal: Sorry, I don't accept message with empty Subject (#5.7.0)"

Hopefully someone knows what this is saying. And for all I know, it could be something that has nothing to do with perl. I really don't know and Googling the error didn't help, so that's why I came here. Thanks.

**I used the perl code from another email list done the same way and that other email list works perfectly. My code is below:

#!/usr/local/bin/perl

$mailprog = '/usr/lib/sendmail';
$sender = 'my email address';
$recipient = 'list email address';
#$recipient = 'my email address';
$century = '19';
$title = 'title';
$return_html_main_heading ='Thank You For Submitting Your Request';
$return_link = 'my homepage';
$return_link_title = 'title of link to my homepage';

@required = ("address");

# Done
#############################################################################

# Retrieve Date
&get_date;

# Parse Form Contents
&parse_form;

# Check Required Fields
#&check_required;

# Send E-Mail
&send_mail;

# Return HTML Page
&return_html;

sub get_date {

   $refdate  = localtime
}

sub parse_form {

   if ($ENV{'REQUEST_METHOD'} eq 'GET') {
      # Split the name-value pairs
      @pairs = split(/&/, $ENV{'QUERY_STRING'});
   }
   elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
      # Get the input
      read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 
      # Split the name-value pairs
      @pairs = split(/&/, $buffer);
   }
   else {
      &error('request_method');
   }

   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);
 
      $name =~ tr/+/ /;
      $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      $value =~ s/<!--(.|\n)*-->//g;


      if ($name eq 'email') {
       $CONFIG{$name} = $value;
      }

      elsif ($name eq 'env_report') {
         @env_report = split(/,/,$value);
      }
      else {
         if ($FORM{$name} && ($value)) {
	    $FORM{$name} = "$FORM{$name}, $value";
	 }
         elsif ($value) {
            $FORM{$name} = $value;
         }
      }
   }
}

sub check_required {

   foreach $require (@required) {
 if ($require eq 'email')  {

         if (!($CONFIG{$require}) || $CONFIG{$require} eq ' ') {
            push(@ERROR,$require);
         }
    }
      elsif (!($FORM{$require}) || $FORM{$require} eq ' ') {
         push(@ERROR,$require);
      }
   }

   if (@ERROR) {
      &error('missing_fields', @ERROR);
   }

}

sub return_html {
 
print "Location: url of the page where the program goes after successfully sending an email\n\n";
}

sub send_mail {
   # Open The Mail Program

   open(MAIL,"|$mailprog -f $sender -t");
   print MAIL "Content-Type:  text/html; charset=ISO-8859-1\n";
   print MAIL "To: $recipient\n";
   print MAIL "From: my email address\n";
   print MAIL "Subject: $FORM{'headline'}\n\n"; 
   
print MAIL qq~$FORM{'comments'}\n~;


# Send Any Environment Variables To Recipient.
   foreach $env_report (@env_report) {
      print MAIL "$env_report: $ENV{$env_report}\n";
   }

   close (MAIL);

 }

sub error {

   ($error,@error_fields) = @_;

   print "Content-type: text/html\n\n";

   if ($error eq 'bad_referer') {
      print "<html>\n <head>\n  <title>Bad Referrer - Access Denied</title>\n </head>\n";
      print " <body>\n  <center>\n   <h1>Bad Referrer - Access Denied</h1>\n  </center>\n";
      print "The form that is trying to use this Program</a>\n";
      print "resides at: $ENV{'HTTP_REFERER'}, which is not allowed to access this cgi script.<p>\n";
      print "Sorry!\n";
      print "</body></html>\n";
   }

   elsif ($error eq 'request_method') {
      print "<html>\n <head>\n  <title>Error: Request Method</title>\n </head>\n";
      print "</head>\n <body>\n <center>\n\n";

      print "   <h1>Error: Request Method</h1>\n  </center>\n\n";
      print "The Request Method of the Form you submitted did not match\n";
      print "either GET or POST.  Please check the form, and make sure the\n";
      print "method= statement is in upper case and matches GET or POST.\n";
      print "<p><hr size=7 width=75%><p>\n";
      print "<ul>\n";
      print "<li><a href=\"$ENV{'HTTP_REFERER'}\">Back to the Submission Form</a>\n";
      print "</ul>\n";
      print "</body></html>\n";
   }

   elsif ($error eq 'missing_fields') {


      print "<html>\n <head>\n  <title>Error: Blank Fields</title>\n </head>\n";
      print " </head>\n <body BGCOLOR=\"White\">";
      print "<IMG SRC=\"/images/balogo.gif\" WIDTH=569 HEIGHT=63 BORDER=0><P>\n";
      
      
      print "<FONT FACE=\"Arial\">You must include at least your email address.<p>\n";

      # Provide Explanation for Error and Offer Link Back to Form.
      print "Please return to the <a href=\"$ENV{'HTTP_REFERER'}\">Fill Out Form</a> and try again.\n";
      print "</font></body></html>\n";
   }
   exit;
}

Last edited by glevine; Jul 20th, 2005 at 10:30 AM.
glevine is offline   Reply With Quote
Old Jul 20th, 2005, 10:25 AM   #2
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
Code. Tags.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jul 20th, 2005, 10:33 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I see that you ATTEMPTED to use code tags, but they require square brackets, not angle brackets. Your error says you had no subject line. Oddly enough, I believe I'd pursue that path. Most programs contain information (or a lack thereof) that indicates where the failure is. One just has to look at it rather than ignore it. Use some output statements sprinkled liberally around the likely places.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 20th, 2005, 10:43 AM   #4
glevine
Newbie
 
Join Date: Jun 2005
Posts: 22
Rep Power: 0 glevine is on a distinguished road
I did look into this, but I did include a subject in the subject form on my html page from which the email program is executed. I will try it another time be sure, with some output statemets, but I am fairly certain that while it may be related to the subject, it is not because of no subject line. Since the error messages may be very vague in Perl (I'm not sure since I don't much experience with it) this could be a situation where it throws out an error message that is somewhat related but not really the true case.
glevine is offline   Reply With Quote
Old Jul 20th, 2005, 10:55 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I'm not saying error messages can't be cryptic, but often they're right on the button. At any rate, I was speaking more of checking what's available to be checked. As an example, have you actually examined "$FORM{'headline'}" to see what's there by the time you get around to needing it?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 20th, 2005, 12:57 PM   #6
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
glevine, add -w to your "shebang" ( #!/opt/perl/bin/perl -w ) ... see if you get any interesting messages like "use of uninitialized value in print at line xxx"

it's a good idea to always use -w ... as well as "use strict;"


also ... I am experienced with the error messages Perl gives off ... go ahead and post any your receive ...
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC