For those of you trying to get your CGI's to send mail AND use -T, here's the solution 
I found, and for those of you who know what they're doing, please let me know if I 
have any gaping security holes here.  

First, create a small shell script that looks like this:

#!/usr/bin/sh
/usr/bin/mail [EMAIL PROTECTED] < email.txt

CHMOD is to 700.  This will only be called by your CGI, which runs as you.  In my 
case, I wanted to email myself every time someone completed my form, so I hard-coded 
the recipient.   

In the CGI, write the contents of your email to "email.txt" or whatever file you want. 
 With mail, you can set the email attributes by having lines in the txt file like this:

Subject: put it here
Reply-to: whoever

I think you can put "To: whoever" to email it to other people, but I'm not sure.  
Check man mail.

So, you write your email file in the CGI, then close it and do a 

system("/home/user/public_html/cgi-bin/mymailer");

to call your shell script.  This was the only way I could get it to work.  I used the 
open( "|$sendmail") trick, and it didn't send mail, even after I deleted ENV 
variables.  

One thing to watch out for is when you write the email with user data, put something 
at the beginning of each line, so if the user puts in "Subject:This CGI sucks" the 
mailer doesn't interpret that as the subject.  In my CGI, it's sending me the 
information from a form, so mine looks like:

name= fn ln
email= email@whatever
etc...

Also, use flock(FILEHANDLE, LOCK_EX) or flock(FILEHANDLE, 2) to lock the email.txt 
when you open it, to preserve your data.

Hope it helps,
Ryan

Reply via email to