本文整理汇总了PHP中Cake\Network\Email\Email::attachments方法的典型用法代码示例。如果您正苦于以下问题:PHP Email::attachments方法的具体用法?PHP Email::attachments怎么用?PHP Email::attachments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Network\Email\Email
的用法示例。
在下文中一共展示了Email::attachments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendNotification
/**
* Abstract sender method
*
* @param User $user The recipient user
* @param Notification $notification the notification to be sent
* @param NotificationContent $content the content
* @return mixed
*/
public function sendNotification(User $user, Notification $notification, NotificationContent $content)
{
$subject = $content->render('email_subject', $notification);
$htmlBody = $content->render('email_html', $notification);
$textBody = $content->render('email_text', $notification);
$email = new Email($this->_config['profile']);
$email->transport($this->_config['emailTransport']);
$email->emailFormat('html');
if (!empty($notification->config['attachments'])) {
$email->attachments($notification->config['attachments']);
}
$email->to([$user->email => $user->firstname . ' ' . $user->lastname]);
$email->subject($subject);
if (!empty($this->_config['templated']) && !empty($this->_config['template']) && !empty($this->_config['layout'])) {
$email->template($this->_config['template'], $this->_config['layout']);
$email->viewVars(['content' => $htmlBody]);
return $email->send();
}
return $email->send($htmlBody);
}
示例2: _attachments
/**
* Format the attachments
*
* @param Email $email
* @param type $message
* @return array Message
*/
protected function _attachments(Email $email, $message = [])
{
foreach ($email->attachments() as $filename => $attach) {
$content = base64_encode(file_get_contents($attach['file']));
if (isset($attach['contentId'])) {
$message['images'][] = ['type' => $attach['mimetype'], 'name' => $attach['contentId'], 'content' => $content];
} else {
$message['attachments'][] = ['type' => $attach['mimetype'], 'name' => $filename, 'content' => $content];
}
}
return $message;
}