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!

How to invoke sendmail with perl

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 to my cgi script.<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
 
Where's the rest of the script?<br>
<br>
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";).<br>
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.<br>
<br>
Try something like...<br>
<br>
#!/usr/bin/perl<br>
<br>
use CGI qw:)standard);<br>
<br>
print header, start_html();<br>
print h1('Mailing message from web form');<br>
<br>
# These are name/value pairs comming from the web form<br>
<br>
$recipient = param('recipent');<br>
$message = param('message');<br>
<br>
open (SENDMAIL, "¦/usr/lib/sendmail -t") die "Can't open sendmail filehandle: $!\n";<br>
<br>
print SENDMAIL "To: $recipient\n";<br>
print SENDMAIL "From: admin\@localhost.localdomain\n";<br>
print SENDMAIL "Subject: Test message\n";<br>
Print SENDMAIL "$message\n";<br>
<br>
close (SENDMAIL);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top