简体   繁体   English

如何使用CakePHP 1.3发送带附件的电子邮件?

[英]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. 我使用php默认配置发送电子邮件但使用CakePHP框架。

$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. 我知道我们必须在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. 第一个文件att.doc将附加相同的文件名。 For the second file we specify an alias att2.doc will be be used for attaching instead of its actual filename some-name . 对于第二个文件,我们指定别名att2.doc将用于附加而不是其实际文件名some-name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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