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!
  • Students Click Here

*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

How to invoke sendmail with perl

How to invoke sendmail with perl

How to invoke sendmail with perl

I'm having one heck of a time getting sendmail to respond appropriately to my cgi script.

There are lines in my script designating:

$mailprog = '/usr/lib/sendmail';
open (MAIL, "¦$mailprog -t ");

The recipient is a hidden field in the html form.

2 questions: Does recipient have to be designated elsewhere for it to work?
Is there something missing from these lines that should be there?


RE: How to invoke sendmail with perl

Where's the rest of the script?

There must be some kind of web page for the browser and hence the script to work. A simple header would do (print "Content-type: text/html\n\n";).
When piping to sendmail, there must be a newline after each header field to tell sendmail it's time to move on to the next line. Closing the sendmail filehandle has the effect of telling the instance of sendmail that you've finished.

Try something like...


use CGI qw(:standard);

print header, start_html();
print h1('Mailing message from web form');

# These are name/value pairs comming from the web form

$recipient = param('recipent');
$message = param('message');

open (SENDMAIL, "¦/usr/lib/sendmail -t") die "Can't open sendmail filehandle: $!\n";

print SENDMAIL "To: $recipient\n";
print SENDMAIL "From: admin\@localhost.localdomain\n";
print SENDMAIL "Subject: Test message\n";
Print SENDMAIL "$message\n";

close (SENDMAIL);

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