×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Send Mail script doesn't work. Need help!

Send Mail script doesn't work. Need help!

Send Mail script doesn't work. Need help!

(OP)
Script doesn't work or give an error. see below.

Thanks for your comments!

                           #!/usr/bin/perl
                           # This script should send an e-mail


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

                           read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
                           @pairs = split(/&/, $buffer);

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

                           $mailprog = '/var/qmail/bin/qmail-inject';
                           $recipient = 'pecan204@netscape.com';
                           open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");
                           print MAIL "To: $recipient\n";
                           print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
                           print MAIL "Subject: Form Data\n\n";

                           # krb print info from form to mail message.
                           foreach $key (keys(%FORM))
                           {
                           print MAIL "$key = $FORM{$key}\n";
                           }

                           close(MAIL);

                           #added to assess problems- krb!!!!!
                           print "<html><head><title>Form Diagnostics</title></head><body
                           bgcolor="#ffffff" text="#000000" id=all>";
                           print "<h2>Diagnostics for send mail form</h2>\n";
                           print "Referer = $ENV{'HTTP_REFERER'}\n";
                           print "Caller = $ENV{'CONTENT_LENGTH'}\n";
                           print "</body></html>";

                           # Notify mail has been delivered - krb
                           print "</body></html>";
                           print <<EndHTML;
                           <h2>Thank You</h2>
                           Thank you for writing. Your mail has been delivered.<p>
                           Return to our <a href="http://users.vr9.com/pecan204/send_mail.html";>home
                           page</a>.
                           </body></html>
                           EndHTML


                           sub dienice
                           {
                           ($errmsg) = @_;
                           print "<h2>Error</h2>\n";
                           print "$errmsg<p>\n";
                           print "</body></html>\n";
                           exit;
                           }

RE: Send Mail script doesn't work. Need help!

there are a couple of points where your script might be messing up, but what errors are you receiving?


"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."

RE: Send Mail script doesn't work. Need help!

(OP)
I'm not getting errors but I am also not getting the mail sent as a test.

What areas do you  think are questionable?

RE: Send Mail script doesn't work. Need help!

(OP)
Just got these error. Any suggestions on what to do?

syntax error at /data/pecan204/cgi-bin/send_mail.cgi line 27, near "$key ("
Execution of /data/pecan204/cgi-bin/send_mail.cgi aborted due to compilation errors.
[Fri Jan 26 18:31:38 2001] [error] [client 24.25.151.112] Premature end of script headers: /data/pecan204/cgi-bin/send_mail.cgi
[Fri Jan 26 18:31:38 2001] [error] [client 24.25.151.112] MOD_VR9: Error 500 occured while processing : /data/pecan204/cgi-bin/send_mail.cgi





RE: Send Mail script doesn't work. Need help!

Well, baring the syntax error for now, i'm not sure you're using your mail program correctly.  I don't know the specifics of your program, but does it require a "From:" field in order to send?  Does it require a "." on a line by itself at the end of an email to correctly send a file?  The problem doesn't seem to be in the script.  i can compile it fine with the -c option, syntax is fine if i leave out all the html stuff (you have a (print "</body></html>";) where i don't think you want it, around line 40 under the (#notify mail has been sent).  it should probly be starting the html and body, because you end it again 6 lines later.)  Also, i don't get the syntax error you reported having to do with the "$key (", and i don't see anything wrong with it.
 so, my best suggestion for now is to make sure you're using your mailing program to the letter.  maybe when you open it, it needs some options thrown in to get it to read your output properly.  try small scripts with small sample emailings to get it to work.
(Also, you could use CGI::Lite to parse all the data automatically instead of by hand, which would clean up your code a bit, but isn't necessary.)


"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."

RE: Send Mail script doesn't work. Need help!

I am a beginner myself, however, I have wrote a couple of email scripts for different servers and different platforms and one thing I found that was odd on a server in which I wrote such a script was I had to rearrange the header information to get the email to send. In my case I had to address the the header in the following manner: The subject then the from line then the to line in order for my email to send. Sometimes, we have to go about problems in different ways.

Also I would try this method for opening the mail:
open (MAIL, "|$mailprog -t -f \"$recipient\" ") || &dienice;

RE: Send Mail script doesn't work. Need help!

I copied/pasted your code onto my box and found several simple syntax errors.

The following chunk needs to be in single quotes... The double quotes cause the interpreter to try to evaluate the string and it finds other quotes and # signs in the middle causing compile errors.

#added to assess problems- krb!!!!!
print '<html><head><title>Form Diagnostics</title></head>
    <body bgcolor="#ffffff" text="#000000" id=all>';

#the closing 'EndHTML' has  a space on the end.  It needs to match the <<EndHTML exactly.

# the HTML you are trying to generate has two close </body></HTML> tags????

The general flow of the code looks reasonable.  I think it just needs a few wrinkles ironed out.

'hope this helps....


 
 
 keep the rudder amid ship and beware the odd typo

RE: Send Mail script doesn't work. Need help!

ALSO, there is a good FAQ on this subject. http://tek-tips.com/faqs.cfm?spid=219&;sfid=364&CFID=11644252&CFTOKEN=60543523


 
 
 keep the rudder amid ship and beware the odd typo

RE: Send Mail script doesn't work. Need help!

ALSO, there is a good FAQ on this subject.  See the tab at the top of the Perl Forum front page.


 
 
 keep the rudder amid ship and beware the odd typo

RE: Send Mail script doesn't work. Need help!

goBoating, you can link to a FAQ by copying the code number below its title, like this: FAQ219-364.  TGML automatically makes it a link.


Sincerely,
 
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Send Mail script doesn't work. Need help!

Tom,
I tried that in another thread and it produced a link that came back to the same thread.  I thought I was loosing it, but, your faq_link above returns to this thread.  Looks like a bug to me......  I'll let the admins know.


 
 
 keep the rudder amid ship and beware the odd typo

RE: Send Mail script doesn't work. Need help!

(OP)
Gents,

1.) Sent email to confirm mail prog/path to server staff- no answer yet.

2.) Tried "open (MAIL, "|$mailprog -t -f \"$recipient\" ") || &dienice;" - no clear effect

3.) Cleaned up double html close in script

I'll check the FAQ when it is working later.

This was the latest error log. One note though the $keys error was probably induced by commenting out the print statements and adding a "print     "  per suggestion to maybe locate an error. The error below is with no commented lines. Does this help?

[Tue Jan 30 19:29:00 2001] [error] [client 24.25.151.112] Premature end of script headers: /data/pecan204/cgi-bin/send_mail.cgi
[Tue Jan 30 19:29:00 2001] [error] [client 24.25.151.112] MOD_VR9: Error 500 occured while processing : /data/pecan204/cgi-bin/send_mail.cgi

Also thanks for looking at it.

RE: Send Mail script doesn't work. Need help!

(OP)
Just to reduce confusion, this is what it looks like now.

#!/usr/bin/perl
# This script should send an e-mail


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

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);

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

$mailprog = '/var/qmail/bin/qmail-inject';
$recipient = 'pecan204@netscape.com';
open (MAIL, "|$mailprog -t -f \"$recipient\" ") || &dienice;
#open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
print MAIL "Subject: Form Data\n\n";

foreach $key (keys(%FORM))
{
    print MAIL "$key = $FORM{$key}\n";
}

close(MAIL);

print <<EndHTML;
<h2>Thank You</h2>
Thank you for writing.  Your mail has been delivered.<p>
Return to our <a href="http://users.vr9.com/pecan204/send_mail.html";>home page</a>.
</body></html>
EndHTML


sub dienice
{
    ($errmsg) = @_;
    print "<h2>Error</h2>\n";
    print "$errmsg<p>\n";
    print "</body></html>\n";
    exit;
}

RE: Send Mail script doesn't work. Need help!

Good Morning Pecan,
I copied the most recent version of your code, changed $mail_prog to point at my sendmail and ran it from a command prompt.  It sent me an email.  The mail had no text( I had not run it as a CGI), but it sent the mail.  I then changed the recipient to pecan204@netscape.com and ran it again.  You should have an empty email with a subject of 'Form Data' waiting for you (unless you already got it).  

Conclusion: syntax works.

Some Possible reasons it won't work for you:
1 - you are uploading your script from a PC and forgetting to convert to UNIX line terminators.

2 - you are uploading, converting to UNIX, and forgetting to set the execute bits.

3 - Maybe that is not where you mail executable is??




 
 
 keep the rudder amid ship and beware the odd typo

RE: Send Mail script doesn't work. Need help!

(OP)
Hi goboating,

Did not recieve any e-mail with ..form.

Aren't Unix line terminators just a semi colan.

Protections are 755

RE: Send Mail script doesn't work. Need help!

(OP)
The latest error log.

[Wed Jan 31 19:26:13 2001] [error] [client 24.25.151.112] Premature end of script headers: /data/pecan204/cgi-bin/send_mail.cgi
[Wed Jan 31 19:26:13 2001] [error] [client 24.25.151.112] MOD_VR9: Error 500 occured while processing : /data/pecan204/cgi-bin/send_mail.cgi

I also noted a operation timed out. Maybe it cannot get to the mail program.

I think I ill try to setup on another server.

RE: Send Mail script doesn't work. Need help!

Hey pecan,
' just curious ..... is that pea'-can  or pec-kaun'?  

I don't know why you did not receive the email.  I may have typo'd your address in the script when I ran it.  

The 'Premature end of script headers: /data/pecan204/cgi-bin/send_mail.cgi' error usually means your code did not run at all.  It probably blew up and thus failed to create the appropriate HTML header stuff.  

About the UNIX line endings.  DOS files have both "\n" and "\r".  Unix files have only a "\n".  If you are writing your code on a PC (Windows) box and are then uploading (ftp) the code to a unix box, you need to convert the file to the unix format or it will not run.

If that is the case, that may be your first problem.  Your ftp software may allow you to do an on-the-fly conversion when you do the upload.  If not, get another ftp client, WSFTP is available on the net, ....it works well and has that option.

'hope this helps.


 
 
 keep the rudder amid ship and beware the odd typo

RE: Send Mail script doesn't work. Need help!

(OP)
Hi goBoating,

Well I started in pea'-can land then I moved to pec-kaun land then I moved back to  pea'-can land and now would like to move back to pec-kaun land, but I got this job with stk options that I don't know were it is going.

How about you? Is your anchor in warm waters or are you snowed over and in storage?

I edited everything for unix. I am setting up now at virtualave.net. Looks like a nice service.

Will check in when I give that a try.

Thanks for the help!

RE: Send Mail script doesn't work. Need help!

(OP)
Wanted to update all.

I setup this page on virtualave and they happen to have two different mail programs.
One qmail-inject also, and sendmail, is their newer program.

Script worked for both, so I would conclude that the vr9 program wasn't working correctly.

Thanks for all the good help!

RE: Send Mail script doesn't work. Need help!

warm water.... always warm waters.... South Carolina


 
 
 keep the rudder amid ship and beware the odd typo

RE: Send Mail script doesn't work. Need help!

(OP)
Interesting! Would that be piedmont or in the low country?

I lived in Simpsonville SC near Greenville.

RE: Send Mail script doesn't work. Need help!

Pecan,
I tried to email you at the address listed above to minimize socializing off topic, but it bounced back.  Charlestonian..... marsh mud and fiddler crabs....


 
 
 keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close