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

Using Perl to invoke sendmail

Using Perl to invoke sendmail

Using Perl to invoke sendmail

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

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: Using Perl to invoke sendmail

syntax looks ok to me - what happens when you try it?

RE: Using Perl to invoke sendmail

something I forgot to ask - have you thought of having a look at exactly what is passed to the MAIL pipe?

RE: Using Perl to invoke sendmail

I use Mail::Sendmail and pass variables to a function like this...
When you get the module Mail::Sendmail and build it, it finds Sendmail for you and makes is easy to send a message.
No need to pipe, pipes can get yucky! :-)

Setup your perl prog to get the addresses from your page and assign a value to $M for the message and you can also
assign a value to To, Cc, subject, etc.. just change
my ( $M ) = $_; to....
my ( $to, $cc, $subject, $M ) = $_;

That's how you pass variables to your function, make it's very dynamic if needed.

Then change the %mail hash to accept your variables like...
To => $to,
Cc => $cc,
etc... etc...

use Mail::Sendmail; # This goes at the top obviously :)

sub handle_email {
my ( $M ) = $_; # get this variable $M from your web page
my %mail = ( To => 'name1@this.host.com',
Cc => 'name2@this.host.com',
From => 'name3@this.host.com',
Subject => 'whatever subject it is',
Message => $M

$mail{Smtp} = 'localhost';
sendmail(%mail) or die $Mail::Sendmail::error;
print "OK. Log says:\n", $Mail::Sendmail::log;

And there ya have it. Whenever you need to send email, call the function when you users have input data for the $to, $cc,etc.. variables and it'll email it..


James Robertson

RE: Using Perl to invoke sendmail

Don't forget to add a newline to each print to the process filehandle.


open (MAIL, "¦/usr/lib/sendmail -t");
print MAIL "To: user\@domain.com\n";
print MAIL "From: another.user\@domain.com\n";
print MAIL "Subject: Test Message\n";
print MAIL "This is the message\nPlease reply\n";
close (MAIL);

Closing the filehandle, forces the process closed.

I'm sure this is one of the perl FAQs.

RE: Using Perl to invoke sendmail

Just something obvious are you sure sendmail is in /usr/lib different sys programmer put it in different places.


RE: Using Perl to invoke sendmail

i have an autoresponder running on my server and rather than pointing to /usr/lib .. it points to /usr/sbin/sendmail
maybe you should check for the location of sendmail with which ?

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