2017 © Pedro Peláez
 

library php-mailhog-client

image

mohrekopp/php-mailhog-client

  • Wednesday, October 4, 2017
  • by mohrekopp
  • Repository
  • 1 Watchers
  • 1 Stars
  • 905 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 53 % Grown

The README.md

php-mailhog-client

PHP-Client for the Mailhog-API (v2) based on HTTPlug, (*1)

Build Status, (*2)

Installation

composer require mohrekopp/php-mailhog-client

Since HTTPlug is just an abstraction, you have to install a client or an adapter, e.g. CURL-client:, (*3)

composer require php-http/curl-client

Or Guzzle6-adapter:, (*4)

composer require php-http/guzzle6-adapter

Usage

<?php 
require_once 'vendor/autoload.php';

use Mohrekopp\MailHogClient\MailHogClient;
use Mohrekopp\MailHogClient\SearchCriteria;

# Instantiate client
$client = new MailHogClient('http://localhost:8025');

# Retrieve all messages
$messages = $client->getMessages();

# Iterate over messages
foreach ($messages as $message) {
    $message->getBody();
    $message->getSubject();
}   

# Search for messages based on subject or body content
$criteria = SearchCriteria::createContainingCriteria('Content for searching');

$messages = $client->searchMessages($criteria);

# Search for messages sent *from* bob@example.com
$criteria = SearchCriteria::createSentByCriteria('bob@example.com');
$client->searchMessages($criteria);

# Search for messages sent *to* alice@example.com
$criteria = SearchCriteria::createSentToCriteria('alice@example.com');
$client->searchMessages($criteria);

Tests

Run Unit-Tests

composer run test-unit

Run Functional-Tests

  1. You have to install a HTTPlug-Client:
composer require php-http/curl-client
  1. Copy the .env.dist file and start a docker-container for Mailhog:
cp .env.dist .env
docker-compose up -d
  1. Seed Mailhog with testdata and run tests
composer run test-seed-mailhog
composer run test-functional

License

The MIT License (MIT). Please see License File for more information., (*5)

The Versions