0

我正在努力发送带有附件的电子邮件。我正在使用 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 中定义文件路径。

我哪里错了?

4

1 回答 1

2

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

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

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

于 2012-08-17T07:14:39.267 回答