Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Perl to invoke sendmail

Status
Not open for further replies.

Blisswhips

Programmer
May 19, 1999
2
US
I'm having one heck of a time getting sendmail to respond appropriately.<br>
<br>
There are lines in my script designating:<br>
<br>
$mailprog = '/usr/lib/sendmail';<br>
(and)<br>
open (MAIL, "¦$mailprog -t ");<br>
<br>
The recipient is a hidden field in the html form.<br>
<br>
2 questions: Does recipient have to be designated elsewhere for it to work?<br>
Is there something missing from these lines that should be there?<br>
<br>
BW
 
something I forgot to ask - have you thought of having a look at exactly what is passed to the MAIL pipe?<br>
-ml
 
I use Mail::Sendmail and pass variables to a function like this... <br>
When you get the module Mail::Sendmail and build it, it finds Sendmail for you and makes is easy to send a message.<br>
No need to pipe, pipes can get yucky! :)<br>
<br>
Setup your perl prog to get the addresses from your page and assign a value to $M for the message and you can also<br>
assign a value to To, Cc, subject, etc.. just change<br>
my ( $M ) = $_; to....<br>
my ( $to, $cc, $subject, $M ) = $_; <br>
<br>
That's how you pass variables to your function, make it's very dynamic if needed.<br>
<br>
Then change the %mail hash to accept your variables like...<br>
To =&gt; $to,<br>
Cc =&gt; $cc,<br>
etc... etc...<br>
<br>
use Mail::Sendmail; # This goes at the top obviously :)<br>
<br>
sub handle_email {<br>
my ( $M ) = $_; # get this variable $M from your web page<br>
my %mail = ( To =&gt; 'name1@this.host.com',<br>
Cc =&gt; 'name2@this.host.com',<br>
From =&gt; 'name3@this.host.com',<br>
Subject =&gt; 'whatever subject it is',<br>
Message =&gt; $M<br>
);<br>
<br>
$mail{Smtp} = 'localhost';<br>
sendmail(%mail) or die $Mail::Sendmail::error;<br>
print "OK. Log says:\n", $Mail::Sendmail::log;<br>
}<br>
<br>
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..<br>
<br>
:)<br>
<br>
lanlord<br>
James Robertson
 
Don't forget to add a newline to each print to the process filehandle.<br>
<br>
So...<br>
<br>
open (MAIL, "¦/usr/lib/sendmail -t");<br>
print MAIL "To: user\@domain.com\n";<br>
print MAIL "From: another.user\@domain.com\n";<br>
print MAIL "Subject: Test Message\n";<br>
print MAIL "This is the message\nPlease reply\n";<br>
close (MAIL);<br>
<br>
Closing the filehandle, forces the process closed.<br>
<br>
I'm sure this is one of the perl FAQs.
 
Just something obvious are you sure sendmail is in /usr/lib different sys programmer put it in different places.<br>
<br>
Bob
 
i have an autoresponder running on my server and rather than pointing to /usr/lib .. it points to /usr/sbin/sendmail<br>
maybe you should check for the location of sendmail with which ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top