项目作者: archey347

项目描述 :
This sprinkle adds support for email attachments in UF
高级语言: PHP
项目地址: git://github.com/archey347/UF_MailAttachments.git
创建时间: 2020-03-30T12:46:28Z
项目社区:https://github.com/archey347/UF_MailAttachments

开源协议:MIT License

下载


UF_MailAttachments

This sprinkle adds support for mail attachments to UserFrosting

Deprecation Notice for v2

Due to some weird PHP reasons, it can’t seem to accept paremter types that are children of paremeter types of the parent class’ method definition. I’m not sure what PHP version this became a problem in. I don’t know if it’s just something that I’ve done wrong, but for some reason the zend compiler barfs at it. As a cheap fix, for v2 of this sprinkle, you now have to call the sendWithAttachments or sendDistinctWithAttachments instead rather than the normal functions. I’ll probably try and get it implemented in UF’s mailer directly rather than having an extension.

Usage

Usage is similar, you just need to use differenct classes and a different service.

First, create a message

  1. // Add this to the top
  2. use UserFrosting\Sprinkle\MailAttachments\Mail\ExtendedTwigMailMessage;
  3. $message = new ExtendedTwigMailMessage($this->ci->view, "mail/booking-confirmation.html.twig");

Usage of the ExtendenTwigMailMessage is the same as the standard TwigMailMessage

To add an atachment, create a MailAttachment Object

  1. // Add this to the top
  2. use UserFrosting\Sprinkle\MailAttachments\Mail\MailAttachment;
  3. $attachment = New MailAttachment("Hello World","hello.txt");
  4. // OR using UF's disk storage
  5. $fs = $this->ci->filesystem;
  6. $disk = $fs->disk("diskName");
  7. $file = new MailAttachment($disk->get('hello.txt'), 'hello.txt');
  8. // Then add to the message
  9. $message->addAttachment($attachment);

To send the message use the extendedMailer service

  1. $extendedMailer = $this->ci->extendedMailer;
  2. $extendedMailer->sendDistinctWithAttachments($message);

Options

The attachment object has four options which can be set in the constructor.

  • $file - The contents of the file
  • $fileName - The name of the file
  • $encoding - How the file should be encoded (defaults to PHPMailer::ENCODING_BASE64)
  • $mimeType - The mime type of the file (if left blank, PHPMailer will automatically detect the mime type)