0

500 附加文件时出现内部服务器错误,但在不带附件的情况下发送。

    use MIME::Lite; 


$msg = MIME::Lite->new(
    From    =>'email@domain.com',
    To      =>'email@domain2.com',
    Subject =>'A message with 2 parts...',
    CC      => '',
    Type    =>'TEXT',
    Data    =>'Thank you for your interest in'
);

    ### If I comment out the following attachment code the email sends OK, otherwise i get 500 internal server error

$msg->attach(
    Type     =>'image/gif',
    Path     =>'/images/tree.gif',
    Filename =>'tree.gif',
    Disposition => 'attachment'
)or die "error attaching file\n"; 



$msg->send;
4

2 回答 2

1

只是一个建议和一些我也可以为此推荐的东西。应用此方法将允许您split包含要包含的文本/html 部分和附件,因此您可以根据需要发送具有多属性的消息。

use strict;
use warnings;

use MIME::Lite; 

my $msg = MIME::Lite->new(
        To      => 'email@domain2.com',
        From    => 'email@domain.com',
        Subject => 'A message with 2 parts...',
        Type    => 'multipart/alternative',
);

# Make my text part
my $txt = MIME::Lite->new(
        Type => "text/plain",
        Data => 'Thank you for your interest in',
);

# Make my html part
my $html = MIME::Lite->new(
         Type => 'multipart/related',
);

# Here you can attach what html tags you would like to include.
$html->attach(
     Type => 'text/html',
     Data => "<b>my html is here</b>",
);

$html->attach(
     Type => 'image/gif',
     Id   => 'tree.gif',
     Path => "../images/tree.gif",
); 

$msg->attach($txt);
$msg->attach($html);

my $data = $msg->as_string;

我还看到你在哪里使用die错误处理,这里不需要这样做。

于 2013-05-04T02:58:41.257 回答
0

错误最终在于必须相对于脚本编写 URI。

所以我不得不改变/images/tree.gif

../images/tree.gif

于 2013-05-04T02:10:50.377 回答