问题
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');
回答1:
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'
)
));
回答2:
As described in the documentation the attachments
method takes an array as the first parameter so your code should look like:-
$Email->attachments(array(
'path/to/example.txt',
'path/to/example1.txt',
'path/to/example3.txt',
'abs/path/to/example4.txt',
'path/to/example5.txt'
));
This is also clearly stated in the API documentation (always worth checking).
If you look at the actual code for attachments()
you'll see that if you pass just a string for the first parameter it gets cast as an array
. Your code isn't working as the method doesn't take multiple parameters.
回答3:
Try
$Email->attachments(
array(
'path/to/example.txt',
'path/to/example1.txt',
'path/to/example3.txt',
'abs/path/to/example4.txt',
'path/to/example5.txt'
)
);
来源:https://stackoverflow.com/questions/34760777/attach-multiple-files-to-email-in-cakephp