Reputation: 4763
I am working over to send email with attachments. I am using php default configurations to send email but using CakePHP framework.
$fromEmail = $from_name." <".$from_email.">";
$this->Email->from = $fromEmail;
$this->Email->to = trim($email);
$this->Email->subject = $subjects[$this->params['action']];
$this->Email->sendAs = 'text';
$this->Email->template = $this->params['action'];
print_r($attachments); exit; // Gave me an empty Array ( )
$this->Email->attachments = $attachments;
$attachments = array( );
if ( ! empty($this->data['Submit']['files'])) {
$attach_files = $this->Document->DocumentDocument->find('all', array(
'conditions' => array(
'MailDocument.Mail_id' => $this->data['Submit']['prop_id'],
'MailDocument.id' => $this->data['Submit']['files'],
),
));
$attachments = Set::combine($attach_files, '/PropertyDocument/file', '/PropertyDocument/file_path');
}
I understand we have to define file path in cakePHP.
Where am I going wrong?
Upvotes: 0
Views: 1539
Reputation: 2886
You set an array containing the paths to the files to attach to the attachments property of the component.
$this->Email->attachments = array(
TMP . 'att.doc',
'att2.doc' => TMP . 'some-name'
);
The first file att.doc
will be attached with the same filename. For the second file we specify an alias att2.doc
will be be used for attaching instead of its actual filename some-name
.
Upvotes: 2