[英]Sending email using perl with sendmail
I am trying to send email using sendmail in perl. 我试图在Perl中使用sendmail发送电子邮件。 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"
. 例如,如果
from@gmail.com
地址为from@gmail.com
,则收件人地址为to@gmail.com
,主题为"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"
我收到的电子邮件带有
Reply-to:
字段,例如from@gmail.com,"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. 而且,如果我删除$ reply_to和$ send_to行,则电子邮件将来自Apache服务器的
from:
字段。
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. 我不想使用任何其他库,例如
Email::MIME
因为它在我的系统上不存在。
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 = '';
这是
my $cc_addresses = '';
earlier, which then (possibly) gets built up. 之前,然后(可能)建立起来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.