cakephpemail-attachmentscakephp-2.3

Attach multiple files to email in CakePHP


I want to attach 5 dynamic text file in mail but not working.

I send single attachment in email working perfect my code is :

  $Email->attachments('path/to/example.txt');

But i send multiple attachment in email not working.

My code is :

$Email->attachments('path/to/example.txt','path/to/example1.txt','path/to/example3.txt','abs/path/to/example4.txt','path/to/example5.txt');

Solution

  • Try this code for multiple attachment :

    $Email->attachments(array(
                'example.txt' => array(
                    'file' => 'path/to/example.txt',
                    'mimetype' => 'text/plain'
                ),
    example1.txt' => array(
                    'file' => 'path/to/example1.txt',
                    'mimetype' => 'text/plain'
                ),
    example3.txt' => array(
                    'file' => 'path/to/example3.txt',
                    'mimetype' => 'text/plain'
                ),
    example4.txt' => array(
                    'file' => 'path/to/example4.txt',
                    'mimetype' => 'text/plain'
                ),
    example5.txt' => array(
                    'file' => 'path/to/example5.txt',
                    'mimetype' => 'text/plain'
                )
    
            ));