q-alliance/qsendgrid

此包最新版本(1.0.4)没有可用的许可证信息。

简单易用的邮件发送工具,后台使用Sendgrid

1.0.4 2020-07-25 09:50 UTC

This package is not auto-updated.

Last update: 2021-10-02 17:09:37 UTC


README

简单易用的邮件发送工具,后台使用Sendgrid构建。发送基本的HTML邮件,可带或不带附件。

先决条件

您需要提供

键示例:SG.QDzWlz_gShWMVi8svP...

安装

使用composer安装QSendgrid

composer require q-alliance/qsendgrid

基本用法

发送基本的HTML电子邮件

<?php

use QAlliance\QSendgrid;

// Create new QSendgrid object
$qs = new QSendgrid('NO_REPLY_EMAIL', 'SENDGRID_API_KEY');

// Send email to given address with given subject and content, returns bool
$result = $qs->send('to@example.com', 'My Subject', '<h1>This is a QSendgrid test email.</h1>');

使用fromName参数发送HTML电子邮件

// Send email to given address with given subject, content and fromName, returns bool
$result = $qs->send('to@example.com', 'My Subject', '<h1>This is a QSendgrid test email.</h1>', null, 'From Name');

带附件发送HTML电子邮件

<?php

use QAlliance\QSendgrid;

$attachmentUrls = [
	'./src/attachments/sample1.jpg',
	'./src/attachments/sample2.jpg'
];

// Create new QSendgrid object
$qs = new QSendgrid('NO_REPLY_EMAIL', 'SENDGRID_API_KEY');

// Send email to given address with given subject and content, returns bool
$result = $qs->send('to@example.com', 'My Subject', '<h1>This is a QSendgrid test email with attachments.</h1>', $attachmentUrls);

发送同时包含html和text/plain内容的电子邮件

// Send email with both html and text/plain content, returns bool
$result = $qSendgrid->sendWithTextPlain('to@example.com', 'My Subject', '<h1>This is a QSendgrid test email with plain text.</h1>', 'This is a QSendgrid test email with plain text', null, 'From Name');

运行测试

编辑PHPUnit引导文件(phpunit.bootstrap.php)并添加所需值。使用以下命令运行测试

vendor/bin/phpunit --bootstrap phpunit.bootstrap.php

作者