divya2407sharma / pepipost
此库为Laravel添加了'pepipost'邮件驱动。此库是 https://github.com/pepipost/pepipost-laravel-driver 的副本。
Requires
- php: >=5.5.9
- guzzlehttp/guzzle: ~5.3|~6.0
- illuminate/mail: ~5.2
Requires (Dev)
- illuminate/container: ~5.2
- illuminate/filesystem: ~5.2
README
此项目是 pepipost/pepipost-laravel-driver 的副本,针对Laravel 5.2进行了一些定制。
Laravel用于Pepipost的驱动程序
支持Pepipost Send Email Web API的邮件驱动程序,使用原始Laravel API。此库扩展了原始Laravel类,因此使用完全相同的方法。
要使用此包,需要您的 Pepipost Api Key。请将其添加到 此处。
我们正在努力使我们的库社区驱动 - 这意味着我们需要您的帮助来正确、有序地构建正确的东西。我们请求您通过分享评论、创建新的 问题 或 拉取请求 来帮助我们。
我们欢迎对这个库的任何形式的贡献。
此库的最新1.0.0版本完全兼容最新的Pepipost v2.0 API。
有关此库的任何更新,请查看 发布。
目录
安装
先决条件
在Pepipost上拥有一个免费账户。如果您还没有,请点击此处注册。
用法
配置laravel项目
步骤 1 - 创建新的Laravel项目
laravel new testproject
步骤 2 - 在composer.json中添加包并运行composer update。
"require": { "divya2407sharma/pepipost": "~1.0" },
或使用composer安装
$ composer require divya2407sharma/pepipost
步骤 3 - 配置
-
在config/app.php中添加pepipost服务提供者:(Laravel 5.5+使用包自动发现,因此不需要手动添加ServiceProvider。)
'providers' => [ DS\PepiPost\PepipostTransportServiceProvider::class ];
-
在config/services.php中添加pepipost api密钥、端点
'pepipost' => [ 'api_key' => env('PEPIPOST_API_KEY'), ],
endpoint config If you need to set custom endpoint, you can set any endpoint by using endpoint key. For example,calls to Pepipost Web API through a proxy,configure endpoint in config/services.php. 'pepipost' => [ 'api_key' => env('PEPIPOST_API_KEY'), 'endpoint' => 'https://api.pepipost.com/v2/sendEmail', ], -
在.env文件中添加以下内容
MAIL_DRIVER=pepipost PEPIPOST_API_KEY='YOUR_PEPIPOST_API_KEY'
步骤 4 - Laravel步骤创建控制器和视图
-
定义控制器
php artisan make:controller TestController
-
在resources/views/viewname/name.blade.php中创建文件并包含您的邮件内容
在TestController中包含以下函数sendMail以发送viewname.name作为邮件内容,并将$data初始化以在视图页面上使用
function sendMail(){ Mail::send('viewname.name',$data, function ($message) { $message ->to('foo@example.com', 'foo_name') ->from('sender@example.com', 'sender_name') ->subject('subject') ->cc('cc@example.com','recipient_cc_name') ->bcc('recipient_bcc@example.com','recipient_bcc_name') ->replyTo('reply_to@example.com','recipient_bcc') ->attach('/myfilename.pdf'); }); return 'Email sent successfully'; }
-
在routes/web.php中创建路由
Route::get('/send/email', 'TestController@sendMail')->name('sendEmail');
步骤 5 - 测试
托管您的laravel项目,然后在浏览器中输入url- http://your_url.com/send/email
这将发送邮件并在浏览器上显示“邮件发送成功”。
其他用法
如果您想传递PepiPost SendEmail API的其他参数,请使用embedData函数,并包含以下代码。根据您的需求添加参数。不要使用此方法多次使用to、cc、bcc。
function sendMail(){ Mail::send('viewname.name',$data, function ($message) { $message ->to('foo@example.com', 'foo_name') ->from('sender@example.com', 'sender_name') ->subject('subject') ->cc('cc@example.com','recipient_cc_name') ->bcc('recipient_bcc@example.com','recipient_bcc_name') ->replyTo('reply_to@example.com','recipient_bcc') ->attach('/myfilename.pdf') ->embedData([ 'personalizations' => ['attributes'=>['ACCOUNT_BAL'=>'String','NAME'=>'NAME'],'x-apiheader'=>'x-apiheader_value','x-apiheader_cc'=>'x-apiheader_cc_value'],'settings' => ['bcc'=>'bccemail@gmail.com','clicktrack'=>1,'footer'=>1,'opentrack'=>1,'unsubscribe'=>1 ],'tags'=>'tags_value','templateId'=>'' ],'pepipostapi'); return 'Email sent successfully'; }
对于多个to、cc、bcc,传递recipient、recipient_cc、recipient_bcc如下,创建所需的自定义
function sendMail(){ Mail::send('viewname.name',$data, function ($message) { $message ->from('sender@example.com', 'sender_name') ->subject('subject') ->replyTo('reply_to'@example.com,'recipient_bcc') ->attach('/myfilename.pdf') ->embedData([ 'personalizations' => [['recipient'=>'foo@example.com','attributes'=>['ACCOUNT_BAL'=>'String','NAME'=>'name'],'recipient_cc'=>['cc@example.com','cc2@example.com'],'recipient_bcc'=>['bcc@example.com','bcc2@example.com'],'x-apiheader'=>'x-apiheader_value','x-apiheader_cc'=>'x-apiheader_cc_value'],['recipient'=>'foo@example.com','attributes'=>['ACCOUNT_BAL'=>'String','NAME'=>'name'],'x-apiheader'=>'x-apiheader_value','x-apiheader_cc'=>'x-apiheader_cc_value']],'settings' => ['bcc'=>'bccemail@gmail.com','clicktrack'=>1,'footer'=>1,'opentrack'=>1,'unsubscribe'=>1 ],'tags'=>'tags_value','templateId'=>'' ],'pepipostapi'); }); return 'Email sent successfully'; }