cakephp在电子邮件上附加word文档

时间:2012-10-11 03:29:46

标签: cakephp

我正在使用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 ['消息'] ['附件']上有我的附件,但仍然无法看到电子邮件中的附件

任何帮助?

1 个答案:

答案 0 :(得分:0)

$Email->attachments期望包含要附加的文件路径的数组。在$data['Message']['attachments']路径数组中设置shure,而不仅仅是文件名...