我正在使用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 ['消息'] ['附件']上有我的附件,但仍然无法看到电子邮件中的附件
任何帮助?
答案 0 :(得分:0)
$Email->attachments
期望包含要附加的文件路径的数组。在$data['Message']['attachments']
路径数组中设置shure,而不仅仅是文件名...