stephanecoinon / mailtrap
Mailtrap的PHP客户端。
v0.2.0
2020-05-13 21:26 UTC
Requires
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- mockery/mockery: ^0.9.9
- orchestra/testbench: ^3.4
- phpunit/phpunit: ^6.0
- vlucas/phpdotenv: ^2.4
This package is auto-updated.
Last update: 2024-09-14 07:16:11 UTC
README
安装
首先使用composer安装此包
composer require stephanecoinon/mailtrap
纯PHP
use StephaneCoinon\Mailtrap\Client; use StephaneCoinon\Mailtrap\Model; // Instantiate Mailtrap API client $client = new Client('your_mailtrap_api_token_here'); // Boot API models Model::boot($client);
Laravel
此包包含一个Laravel服务提供者(已针对Laravel v5.4进行测试)。
将您的Mailtrap API令牌添加到您的.env
文件中。
MAILTRAP_API_TOKEN=your_mailtrap_api_token_here
然后,在config/services.php
配置文件中添加mailtrap
'mailtrap' => [ 'token' => env('MAILTRAP_API_TOKEN'), ],
最后,如果您的应用程序在Laravel < 5.5上运行,请在config/app.php
中注册Mailtrap服务提供者
'providers' => [ // ... /* * Package Service Providers... */ // ... StephaneCoinon\Mailtrap\MailtrapServiceProvider::class, // ... ],
否则,在Laravel >= 5.5的情况下,它将自动被发现。
用法
use StephaneCoinon\Mailtrap\Inbox; // Fetch all inboxes $inboxes = Inbox::all(); // Fetch an inbox by its id $inbox = Inbox::find(1234); // Get all messages in an inbox $messages = $inbox->messages(); // Get a message by its id $message = $inbox->message(123456789); $message->htmlBody(); // Get the HTML body (also sets html_body attribute on the message) $message->textBody(); // Get the plain text body (also sets txt_body attribute on the message) $message->rawBody(); // Get the raw body (also sets raw_body attribute on the message) $message->headers(); // Get the headers as an array (also sets headers attribute on the message) // Get the last (newest) message in an inbox $newestMessage = $inbox->lastMessage(); // Delete all messages from an inbox $inbox = $inbox->empty(); $inbox = (new Inbox)->empty(1234); // alternative syntax using the inbox id // Determine whether the inbox contains a message for a given recipient e-mail $recipientReceivedMessage = $inbox->hasMessageFor('john@example.com'); // Get message recipients as an array $recipients = $message->recipientEmails();