Sendmail via Perl?

software development


I’ve always sent out emails from a cgi script like this:

my $email = shift;
my $subject = shift;
my $msg = shift;

my $mailprog = “/usr/sbin/sendmail”;

open (MAIL, “|$mailprog $email”) || die “Unable to send request\n”;
print MAIL “From:\n”;
print MAIL “Subject: $subject\n”;
print MAIL “Content-type: text/html\n\n”;
print MAIL “\n\n”;
print MAIL “$msg\n\n\n”;
close (MAIL);

But this doesn’t work on Dreamhost. Anyone else have this problem?



You could try it “by hand” (i.e., replicating what you’re calling from the script on the command line). I’m not sure that will work with the Postfix “sendmail”, because you’re specifying the recipient in the call to Sendmail, but then putting other stuff in the message and expecting sendmail to pull it from that.

I’d do something like:
open(MAIL, “|/usr/sbin/sendmail -oi -t -f”)
print MAIL <<“EOF”;
To: $email
Subject: $subject
Content-type: text/html


Since you’re apparently sending HTML mail, I’d suggest using MIME-Tools instead, and also generating a plain text version.


I have that same problem! I simply used a trial code to send an email to myself to make sure the code worked. The code WORKS as far as creating the email and formatting to my specifications, but for some reason, I can’t get the addresses read by the sendmail program. = / I used a one question survey to test my code.

open (MAIL, “|/usr/sbin/sendmail -oi -t”);

select (MAIL);


Subject: Survey Input
Content-type: text/html

Blah blah, message.


I receive the “failed delivery status” report at my site’s address, but that’s independent of my “FROM” address. The email is properly written, as I said, but just never sent to the addresses. If you figure anything out or if anyone else knows of anything, please bounce me a message!

By the way, I’m stubborn and want to use SENDMAIL properly before trying the MIME-tools. d= P Thanks!



I’ve run into the same thing.

I can’t send messages using the mail command in PHP scripts. I also can’t send messages using mail or sendmail from the command line.

I’ve submitted a support ticket with the details, so hopefully I’ll hear back from DH peops soon.



Mine works when I include the address in my SENDMAIL call, but I don’t see WHY that would work and doesn’t make the program very flexible. = / I used the command to read the headers of the email for the addresses and subject, but it wouldn’t work. I have no idea what’s going on and am busy working on a game program for my site. Therefore, anyone who knows the answer off hand, HOLLA AT ME! = P

Thanks and have a great day!