Git Product home page Git Product logo

mailtrap's Introduction

PHP client for Mailtrap

Installation

First install this package using composer:

composer require stephanecoinon/mailtrap

Plain Vanilla 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

This package includes a Laravel service provider (tested for Laravel v5.4).

Add your Mailtrap API token to your .env file.

MAILTRAP_API_TOKEN=your_mailtrap_api_token_here

Then add mailtrap in your config/services.php configuration:

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

Finally, if your app runs on Laravel < 5.5, register the Mailtrap service provider in config/app.php:

'providers' => [
    // ...

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

    StephaneCoinon\Mailtrap\MailtrapServiceProvider::class,

    // ...
],

Otherwise it will be discovered automatically on Laravel >= 5.5.

Usage

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

mailtrap's People

Contributors

sco-tt avatar junker avatar

Stargazers

Simon Benjámin avatar Hexel Colorado avatar  avatar John McCann avatar  avatar Spacetum Co avatar Anis Marrouchi avatar Markel avatar

Watchers

James Cloos avatar Stéphane Coinon avatar

mailtrap's Issues

Laravel 5.2 Compatiblity

In order to make this compatible with Laravel 5.2, I had to add an empty register() method in MailTrapServiceProvider.php.

Are you open to a pull request?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.