archey347/

uf_mailattachments

这个扩展为UF添加了对邮件附件的支持

安装: 44

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 0

开放问题: 0

类型:userfrosting-sprinkle

v2.0.0 2022-03-10 02:00 UTC

This package is auto-updated.

Last update: 2024-09-12 20:11:01 UTC


README

此扩展为UserFrosting添加了对邮件附件的支持

v2版本弃用通知

由于一些奇怪的PHP原因,它似乎无法接受父类方法定义中参数类型的孩子作为参数类型。我不确定这是从哪个PHP版本开始的这个问题。我不知道这是否是我做错了什么,但不知何故,zend编译器对此报错。作为一个便宜的解决方案,在这个扩展的v2版本中,你现在必须调用sendWithAttachmentssendDistinctWithAttachments而不是正常的函数。我可能会在UserFrosting的邮件发送器中直接实现它,而不是作为一个扩展。

使用方法

使用方法类似,你只需要使用不同的类和不同的服务。

首先,创建一个消息

// Add this to the top
use UserFrosting\Sprinkle\MailAttachments\Mail\ExtendedTwigMailMessage;

$message = new ExtendedTwigMailMessage($this->ci->view, "mail/booking-confirmation.html.twig");    

ExtendenTwigMailMessage 的使用与标准的 TwigMailMessage 相同

要添加附件,创建一个 MailAttachment 对象

// Add this to the top
use UserFrosting\Sprinkle\MailAttachments\Mail\MailAttachment;

$attachment = New MailAttachment("Hello World","hello.txt");
// OR using UF's disk storage
$fs = $this->ci->filesystem;
$disk = $fs->disk("diskName");
$file = new MailAttachment($disk->get('hello.txt'), 'hello.txt');

// Then add to the message
$message->addAttachment($attachment);

使用 extendedMailer 服务发送消息

$extendedMailer = $this->ci->extendedMailer;

$extendedMailer->sendDistinctWithAttachments($message);

选项

附件对象有四个选项,可以在构造函数中设置。

  • $file - 文件内容
  • $fileName - 文件名
  • $encoding - 文件编码方式(默认为 PHPMailer::ENCODING_BASE64
  • $mimeType - 文件的MIME类型(如果为空,PHPMailer将自动检测MIME类型)