简体   繁体   中英

How to send emails with attachments using CakePHP 1.3?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM