繁体   English   中英

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

[英]How to send emails with attachments using CakePHP 1.3?

我正在努力发送带附件的电子邮件。 我使用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');
            }

我知道我们必须在cakePHP中定义文件路径。

我哪里错了?

您设置一个数组,其中包含要附加到组件的附件属性的文件的路径。

$this->Email->attachments = array(
    TMP . 'att.doc',
    'att2.doc' => TMP . 'some-name'
);

第一个文件att.doc将附加相同的文件名。 对于第二个文件,我们指定别名att2.doc将用于附加而不是其实际文件名some-name

暂无
暂无

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

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