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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sendmail not working with "To:" specified?

Status
Not open for further replies.

Supra

Programmer
Dec 6, 2000
422
US
This is weird - I am writing an incredibly simple Perl script (with absolutely NO taint checking) and it is not cooperating when I have "To: blah@blah.com" specified. Here's what I have:
Code:
    open(MAIL,"|/usr/sbin/sendmail");
    print MAIL "[b]To:[/b] blah@blah.com\n";
    print MAIL "From: anon\n";
    print MAIL "-" x 75 . "\n\n";
    print MAIL "Testing\n";
    print MAIL "-" x 75 . "\n\n";
    close(MAIL);
That will return a 500 error. If I Remove the "To:" from the first line, it works fine! Am I simply being denied access to sendmail or is there something else I am missing here? Any help is MUCH appreciated!!
 
escape the @ symbol like so:

print MAIL "To: blah\@blah.com\n";
 
Piping directly to sendmail is generally not a good idea, as it's easy to make your programs open to security breaches, resulting in them being used as relays for span. You should consider using a secure pre-made program such as NMS's formmail or one of the many mailing modules from CPAN, such as MIME::Lite.
 
Kevin, it works when I simply take "To:" out of it with the @ symbol as it is. I tried it anyway, and still no go. I'm really confused about that.

ishnid, I'm not going to keep it like this. I wanted to strip it down so that the problem could be found much easier. When I can find the issue preventing this simple code from working, I will then add taint checking and possibly image verification to even send the mail. However I do appreciate the suggestion.

Could it be that my host has it disabled in a very.. stupid way?
 
Yyou can't have the @ symbol in a double-quoted string, perl will try and expand it into a scalar since the @ symbol is used to indicate an array. So you have to escape it if you continue with that syntax. Are you sure the path to sendmail is correct? Try this:


open(MAIL,"|/usr/sbin/sendmail") or die "Can't open sendmail: $!";
 
Kevin, I didn't realize I put it in double quotes in the code above. I actually have it in single quotes in my code.

Fortunately, I have found the problem. I put the t switch after the path to sendmail and voila - everything works perfectly.

Thank you for all of your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top