CakePHP电子邮件发送0字节文件附件

时间:2014-07-18 20:25:32

标签: cakephp cakephp-2.3

我需要将最近的文件附加到电子邮件中。附件在那里,但它是0字节。路径正确

我有以下代码,部分内容:

$file =  WWW_ROOT . $handle->file_dst_pathname; 
/* $file = /var/www/app/webroot/files/uploads/children/0000000220.pdf which is correct */

$attachment_name = 'Progress Note for ' . $parent['Child']['child_name'] . '-' . date('mdY') . '.' . $data['extension'];
$Email->attachments(array($attachment_name => $file));

我正在使用Cakephp 2.4.9

感谢任何帮助。

格雷格

2 个答案:

答案 0 :(得分:0)

根据文件 $Email->attachments(array( $attachment_name => array( 'file' => '$file' ) ));

答案 1 :(得分:0)

它可能取决于您使用的CakePHP版本(2.x)以及可能是PHP的版本。我也在努力处理0字节的附件。我不得不深入挖掘供应商的电子邮件文件。基本上事实证明,_readFile()fn正在搞乱CakePHP文件阅读器。

那么对我有用的是指定文件名,指定完整路径并在base64中附加文件的数据。一切顺利。文档中的所有其他选项都不起作用。我正在运行PHP 5.4.45(旧版)。

    'filename' = array(
        'file' => '/full/path/to/the/file/on/disc.pdf',
        'data' => chunk_split(base64_encode(file_get_contents('/full/path/to/the/file/on/disc.pdf')))
    );