Reputation: 1932
I am trying to send email using sendmail in perl. Email is sent but the content which I send as Subject gets added to 'To:' in the email. For example, if from address is [email protected]
, To address is [email protected]
and subject is "test subject"
. I get the email with Reply-to:
field as [email protected],"Subject:test.email","To:to"@gmail.com,"Content-type:text/plain"
Here is my code:
open(SENDMAIL, "|/usr/lib/sendmail -oi -t '$to_email' -f '$from_email'") || ($error_message .= "<P>Unable to open email process.</P>");
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $send_to;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
And if I remove $reply_to and $send_to lines, the email comes with from:
field
as Apache server.
Any help would be appreciated. I do not want to use any other library like Email::MIME
since it doesn't exist on my system.
Upvotes: 0
Views: 985
Reputation: 66873
I am not sure what is wrong with what you show, but here is some working code
my ($header, $From, $To, $Cc, $ReplyTo, $Subject);
$From = "From: $from";
$To = "To: $to";
$Cc = "Cc: $cc_addresses";
$ReplyTo = "Reply-To: $replyto";
$Subject = "Subject: $subj";
# Form the header. The fields always submitted:
$header = join("\n", $From, $To, $ReplyTo, $Subject, '');
# Optional fields
$header .= "$Cc\n" if $cc_addresses;
open(SENDMAIL, "|/usr/sbin/sendmail -oi -t")
or carp "Can't fork for sendmail: $!\n";
say SENDMAIL "$header\n$msg_cont";
close(SENDMAIL);
Note. There is my $cc_addresses = '';
earlier, which then (possibly) gets built up.
Upvotes: 2