Cakephp 不发送附件,只发送纯文本 html

Cakephp not sending attachment, only send plain html

我正在尝试使用 cakephp 电子邮件发送附件,但只发送了 html 而不是附件。

我正在使用以下代码。

$nmessage ="Hello Test\r\n\r\n";
$email = new CakeEmail();
$email->from(array('abc@example.com' => 'Test'));       
$email->filePaths  = array('/screenshots/');
$email->attachments =array('Google-Maps-9.22.2.jpg');
$email->to('user4@gmail.com');
$email->subject('Register a visit ');
$email->emailFormat('html');
$email->send($nmessage); // or use a template etc   

要发送附件,您可以通过以下方式进行,首先是带有完整路径的字符串(注意没有等号,这是 CakeEmail class 的一个功能)。

$email->attachments('/full/file/path/file.jpg');

其次是相同的但包裹在一个数组中

$email->attachments(array('/full/file/path/file.png'));

第三个是一个数组,其中包含用于重命名文件的键

$Email->attachments(array('photo.png' => '/full/some_hash.png'))

终于可以使用嵌套数组了

$email->attachments(array(
    'photo.png' => array(
        'file' => '/full/some_hash.png',
        'mimetype' => 'image/png',
        'contentId' => 'my-unique-id'
    )
));

所以总而言之,不要使用 $email->attachments = 并确保提供完整路径。

http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#sending-attachments