使用perl和sendmail发送电子邮件 [英] Sending email using perl with sendmail
问题描述
我正在尝试在perl中使用sendmail发送电子邮件。电子邮件已发送,但我作为主题发送的内容已添加到电子邮件的收件人:中。例如,如果发件人地址为 from@gmail.com
,则收件人地址为 to@gmail.com
,主题为测试对象
。我收到 Reply-to:
字段为 from@gmail.com, Subject:test.email, To:to @的电子邮件gmail.com,内容类型:文本/纯文本
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 from@gmail.com
, To address is to@gmail.com
and subject is "test subject"
. I get the email with Reply-to:
field as from@gmail.com,"Subject:test.email","To:to"@gmail.com,"Content-type:text/plain"
这是我的代码:
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);
如果我删除$ reply_to和$ send_to行,则电子邮件附带来自:
字段
作为Apache服务器。
And if I remove $reply_to and $send_to lines, the email comes with from:
field
as Apache server.
任何帮助将不胜感激。我不想使用任何其他库,例如 Email :: MIME
,因为它在我的系统上不存在。
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.
推荐答案
我不确定您显示的内容有什么问题,但这是一些有效的代码
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);
注意。以前有 my $ cc_addresses =’;
,然后(有可能)建立了它。
Note. There is my $cc_addresses = '';
earlier, which then (possibly) gets built up.
这篇关于使用perl和sendmail发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!