PHP code example of stephanecoinon / mailtrap

1. Go to this page and download the library: Download stephanecoinon/mailtrap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stephanecoinon / mailtrap example snippets


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);

'mailtrap' => [
    'token' => env('MAILTRAP_API_TOKEN'),
],

'providers' => [
    // ...

    /*
     * Package Service Providers...
     */
    // ...

    StephaneCoinon\Mailtrap\MailtrapServiceProvider::class,

    // ...
],

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('[email protected]');

// Get message recipients as an array
$recipients = $message->recipientEmails();
ini
MAILTRAP_API_TOKEN=your_mailtrap_api_token_here
config/services.php
config/app.php