定制 cyberwizard/sendgrid-mailer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cyberwizard/sendgrid-mailer

Composer 安装命令:

composer require cyberwizard/sendgrid-mailer

包简介

A Laravel package for sending 'templated based' emails using SendGrid API KEY

README 文档

README

Cyberwizard SendGrid Mailer is a Laravel package designed to simplify the process of sending emails using SendGrid API KEY and Laravel Blade templates. This package is useful when you need to send emails with dynamic content generated from Blade templates while leveraging the power of SendGrid for email delivery.

Why Cyberwizard SendGrid Mailer?

When integrating SendGrid with Laravel applications, you might want to utilize Blade templates for email content generation. However, using Blade templates directly with SendGrid API can be challenging due to compatibility issues. Cyberwizard SendGrid Mailer solves this problem by providing a seamless integration between Laravel Blade templates and SendGrid API.

Installation

You can install the package via Composer:

composer require cyberwizard/sendgrid-mailer:dev-main

Usage

Once installed, you can use the sendEmail method provided by the Cyberwizard\SendGridMailer\CyberSendGridMailer class to send emails. Here's how you can use it:

use Cyberwizard\SendGridMailer\CyberSendGridMailer;

$subject = 'Your email subject';
$to = 'recipient@example.com';
$fromEmail = 'sender@example.com';
$fromName = 'Sender Name';
$templatePath = 'emails.template'; // Path to your Blade template
$data = [
    'name' => 'John Doe',
    'order_id' => '123456',
    // Add more key-value pairs as needed
];

try {
    $success = CyberSendGridMailer::sendEmail($subject, $to, $fromEmail, $fromName, $templatePath, $data);
    if ($success) {
        // Email sent successfully
    } else {
        // Email sending failed
    }
} catch (\Exception $e) {
    // Handle exception
}

Environment Configuration

Before using the package, make sure to set your SendGrid API key in your .env file:

SENDGRID_API_KEY=your-sendgrid-api-key

Parameters

  • $subject (string): The subject of the email.
  • $to (string): The recipient email address.
  • $fromEmail (string): The sender's email address.
  • $fromName (string, optional): The sender's name.
  • $templatePath (string): The path to the email template in your views directory. For example: 'emails.template'.
  • $data (array, optional): The data to pass to the email template. For example:
    [
        'name' => 'John Doe',
        'order_id' => '123456',
        // Add more key-value pairs as needed
    ]

License

This package is open-source software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-02-07