2013-05-04 75 views
0

500附加文件时发生内部服务器错误,但发送时没有附件时发生。MIME :: Lite错误附加文件perl

use MIME::Lite; 


$msg = MIME::Lite->new(
    From =>'[email protected]', 
    To  =>'[email protected]', 
    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; 
+1

您必须检查您的Web服务器日志以查看实际错误。 – Schwern 2013-05-04 01:53:08

回答

0

错误最终导致URI必须相对于脚本写入。

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

../images/tree.gif

+0

URI?这是一条路。当然,你可以在这里使用绝对路径,但它必须是有效的。 – innaM 2013-05-04 08:34:44

1

只是一个建议和几件事情,我可以推荐这个也。应用此方法将允许您将文本/ html部分和附件split包括在内,以便您可以根据需要发送具有多个属性的消息。

use strict; 
use warnings; 

use MIME::Lite; 

my $msg = MIME::Lite->new(
     To  => '[email protected]', 
     From => '[email protected]', 
     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的错误处理,没有必要在这里这样做。