![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Jun 2005
Posts: 22
Rep Power: 0
![]() |
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. |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|