areeb-malik/email-boiler-plate

电子邮件的基本模板。

安装: 0

依赖项: 0

建议者: 0

安全性: 0

星级: 0

关注者: 1

分支: 0

开放问题: 0

类型:package

dev-main 2023-01-24 05:51 UTC

This package is not auto-updated.

Last update: 2024-10-01 13:52:32 UTC


README

Composer命令

composer require areeb-malik/email-boiler-plate

发布配置

php artisan vendor:publish --tag=CC-Emails

安装命令

php artisan install:email

环境变量

要运行此项目,您需要在.env文件中添加以下环境变量:

MAIL_MAILER

MAIL_HOST

MAIL_PORT

MAIL_USERNAME

MAIL_PASSWORD

MAIL_ENCRYPTION

设置环境变量后,您可以通过点击发送按钮来启动本地开发服务器并发送邮件。

代码片段

发送附件

public function build()
{
    $this->from($this->validator['sender'])
        ->subject($this->validator['subject'])
        ->to($this->validator['to'])
        ->attach(base_path('README.md'))
        ->markdown('emails.welcome');
    return $this;
}

发送多个附件

public function sendEmail()
{
    $attachments = [
        <attachment_1>,
        <attachment_2>,
        <attachment_3>,
    ];

    $validator = [
        'sender' => '<sender>',
        'to' => '<receiver>',
        'subject' => '<subject>',
        'message' => '<message>',
        'attachments' => $attachments
    ];
    Mail::queue((new Emails($validator))->onQueue('emails'));
    return "mail has been sent";
}

在电子邮件文件中

class Emails extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public $validator;

    /**
     * Create a new message instance.
     *
     * @return void
     */

    public function __construct($validator)
    {
        $this->validator = $validator;
    }

    /**
     * Build the message.
     *
     * @return $this
     */

    public function build()
    {
        $this->from($this->validator['sender'])
            ->subject($this->validator['subject'])
            ->to($this->validator['to'])
            ->markdown('emails.welcome');
            foreach ($this->validator['attachments'] as $attachment) {
                $this->attach($attachment);
            }
        return $this;
    }