承接 mega-tj/mailer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mega-tj/mailer

Composer 安装命令:

composer require mega-tj/mailer

包简介

A Laravel 11 package for sending emails with flexible email templates (Blade & Markdown) using PHPMailer.

README 文档

README

Mega Mailer Version: 1.1.2 License: MIT

Mega Mailer is a simple and elegant mailer package for PHP, built on PHPMailer, and designed to integrate seamlessly with the Laravel Mailable pattern. It facilitates sending emails through SMTP with ease, offering robust support for recipients, attachments, and Blade views.

Features SMTP Support: Easily send emails using SMTP configured via Laravel's config/mailer.php.

Full Recipient Control: Dedicated methods for TO, CC, and BCC.

Attachment Support: Attach files directly via the fluent interface or through Mailable objects.

Mailable Integration: Full compatibility with Laravel's standard Mailable, Envelope, and Attachment classes.

Blade View Rendering: Send HTML emails using Laravel Blade views.

Simple API: Set recipients, subjects, and email bodies with a straightforward, fluent interface.

Installation You can install Mega Mailer via Composer. Run the following command in your project directory:

Bash

composer require mega-tj/mailer:dev-main --dev Laravel Integration

  1. Register the Service Provider Ensure your package is installed via Composer. If you are using Laravel 5.5+ and have configured your composer.json for auto-discovery (as shown below), this step is automatic.

JSON

// composer.json "extra": { "laravel": { "providers": [ "Mega\App\Providers\MailerServiceProvider" ] # Mega Mailer

Version: 1.0.0
License: MIT

Mega Mailer is a lightweight PHP mailer package that uses PHPMailer and integrates with Laravel's Mailable pattern. It provides a small, opinionated API for sending SMTP emails, with support for recipients (TO/CC/BCC), attachments, and rendering Blade views.

## Features

- SMTP support via PHPMailer and settings from `config/mailer.php`.
- Fluent API for quick messages and first-class support for Laravel `Mailable` objects.
- TO, CC, and BCC helpers.
- Attach local files or include attachments from a `Mailable`.
- Render Blade views for HTML emails.

## Installation

Require the package with Composer (stable or dev branch):

```bash
composer require mega-tj/mailer
# or for the current development branch
composer require mega-tj/mailer:dev-main --dev
```

## Laravel integration

The package registers the service provider automatically if you rely on Composer auto-discovery. The provider class is:

```
Mega\App\Providers\MailerServiceProvider
```

### Publish configuration

To publish the package configuration to your Laravel app (creates `config/mailer.php`):

```bash
php artisan vendor:publish --provider="Mega\App\Providers\MailerServiceProvider" --tag=config
```

The package reads SMTP settings using `config('mailer.*')`.

## Configuration

The shipped configuration (`src/config/mailer.php`) exposes these keys (and defaults):

- `host` (env: MAIL_HOST) — default: `localhost`
- `port` (env: MAIL_PORT) — default: `25`
- `username` (env: MAIL_USERNAME)
- `password` (env: MAIL_PASSWORD)
- `from_address` (env: MAIL_FROM_ADDRESS) — default: `no-reply@example.com`
- `from_name` (env: MAIL_FROM_NAME) — default: `Mega Mailer`
- `smtp_auth` (env: MAIL_SMTP_AUTH) — default: `false`
- `encryption` (env: MAIL_ENCRYPTION) — `tls`, `ssl`, or `false`
- `auto_tls` (env: MAIL_AUTO_TLS) — default: `false`
- `charset` (env: MAIL_CHARSET) — default: `UTF-8`
- `smtp_options` — array of `smtp_options` passed to PHPMailer (defaults allow self-signed certs)

Set the corresponding environment variables in your `.env` file for production.

## Usage

The primary API surface is the `Mega\App\Mailer` class (PSR-4 autoloaded from `src/`). The class supports a fluent API and can also accept a Laravel `Mailable` in `send()`.

### Option 1 — Send a Laravel Mailable (recommended)

When you pass a `Mailable` instance to `send()`, the Mailer pulls subject, from, recipients, and attachments from the `Mailable`'s `envelope()` and `attachments()` methods.

```php
use Mega\App\Mailer;
use App\Mail\TestMailable;

$mailer = new Mailer();
$response = $mailer->to('recipient@example.com')
                 ->send(new TestMailable());

// $response is a string message or an error message
```

Example `Mailable` (Laravel 10+ style using `Envelope`/`Content`/`Attachment` classes):

```php
namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Attachment;

class TestMailable extends Mailable
{
    use Queueable, SerializesModels;

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Report',
            from: new Address('support@example.com', 'Support Team'),
            cc: [new Address('manager@example.com')],
            bcc: [new Address('archive@example.com')]
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.send_report',
            with: ['user' => 'John Doe']
        );
    }

    public function attachments(): array
    {
        return [
            Attachment::fromPath(storage_path('app/report.pdf'))->as('Report.pdf')
        ];
    }
}
```

### Option 2 — Fluent API (simple emails)

For quick one-off messages you can use the fluent methods. You must set the `from()` address (or configure `from_address` in `config/mailer.php`).

```php
use Mega\App\Mailer;

$mailer = new Mailer();
$mailer->from('noreply@mycompany.com', 'System')
       ->to('primary.user@example.com', 'Primary User')
       ->cc('team.lead@example.com')
       ->bcc(['logs@example.com', 'security@example.com'])
       ->subject('Deployment Complete')
       ->message('The deployment finished successfully at '.now())
       ->attach(storage_path('app/logs.zip'))
       ->send();
```

## Behaviour and notes

- The Mailer uses PHPMailer under the hood and configures it from `config('mailer.*')`.
- When rendering a Blade view the Mailer sets the message as HTML. If the view is missing it falls back to a plaintext message.
- Attachments added through a `Mailable` must be instances of `Illuminate\Mail\Mailables\Attachment` (the Mailer checks for this type).

## Contributing

Contributions are welcome. Please open issues or PRs against the upstream repository: https://github.com/wisedev99/mega-mailer

## License

This project is licensed under the MIT License.

mega-tj/mailer 适用场景与选型建议

mega-tj/mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 107 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mega-tj/mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mega-tj/mailer 我们能提供哪些服务?
定制开发 / 二次开发

基于 mega-tj/mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 107
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-15