0

我正在使用 CakePHP,我需要发送带有附件的电子邮件,这是我的代码

function sendAsEmail($data) {
    App::import('Component', 'Email');
    $user = $this->Sender->find('first', array(
        'conditions' => array('Sender.id' => $data['Message']['sender_id']),
    ));
    $Email = new EmailComponent();
    if ($this->useDbConfig == 'test') {
        $Email->delivery = 'debug';
    }

    $Email->sendAs = 'html';
    $Email->from = 'info@admin.ca';
    $Email->return = Configure::read('App.systemAdminEmail');
    $Email->bcc = array($data['Message']['recipient_text']);
    $Email->attachments = $data['Message']['attachments'];
    $Email->subject = $data['Message']['subject'];
    $content = $data['Message']['message'];
    $replyToAddress = isset($data['Message']['reply_to_address']) ? 
        (bool)$data['Message']['reply_to_address'] : false;
    if (!$replyToAddress) {
        $content .= "\n\n".__("Please do not reply to this email", true);
    } elseif (!empty($data['Message']['reply_to'])) {
        $Email->replyTo = $data['Message']['reply_to'];
    }
    if (Configure::read('App.systemAdminEmail')) {
        $Email->additionalParams = '-f'.Configure::read('App.systemAdminEmail');
    }

    $Email->send($content);
    return true;
}

我在 $data['Message']['attachments'] 上有我的附件,但我仍然无法在电子邮件中看到附件

有什么帮助吗?

4

1 回答 1

0

$Email->attachments期望包含要附加的文件的路径的数组。让你拥有$data['Message']['attachments']一系列路径,而不仅仅是文件名......

于 2012-10-11T07:27:36.290 回答