PHPackages                             mailosaur/mailosaur - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. mailosaur/mailosaur

ActiveLibrary[Testing &amp; Quality](/categories/testing)

mailosaur/mailosaur
===================

The Mailosaur PHP library lets you integrate email and SMS testing into your continuous integration process.

8.1.1(1mo ago)2338.0k↓14.4%31MITPHPPHP &gt;=7.2CI passing

Since Sep 24Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/mailosaur/mailosaur-php)[ Packagist](https://packagist.org/packages/mailosaur/mailosaur)[ RSS](/packages/mailosaur-mailosaur/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (9)Versions (32)Used By (1)

[Mailosaur - PHP library](https://mailosaur.com/) · [![](https://github.com/mailosaur/mailosaur-php/workflows/CI/badge.svg)](https://github.com/mailosaur/mailosaur-php/actions)
================================================================================================================================================================================

[](#mailosaur---php-library--)

Mailosaur lets you automate email and SMS tests as part of software development and QA.

- **Unlimited test email addresses for all** - every account gives users an unlimited number of test email addresses to test with.
- **End-to-end (e2e) email and SMS testing** Allowing you to set up end-to-end tests for password reset emails, account verification processes and MFA/one-time passcodes sent via text message.
- **Fake SMTP servers** Mailosaur also provides dummy SMTP servers to test with; allowing you to catch email in staging environments - preventing email being sent to customers by mistake.

Get Started
-----------

[](#get-started)

This guide provides several key sections:

- [Mailosaur - PHP library · ](#mailosaur---php-library--)
    - [Get Started](#get-started)
        - [Installation](#installation)
        - [Set your API key](#set-your-api-key)
        - [Create your code](#create-your-code)
        - [API Reference](#api-reference)
    - [Creating an account](#creating-an-account)
    - [Test email addresses with Mailosaur](#test-email-addresses-with-mailosaur)
    - [Find an email](#find-an-email)
        - [What is this code doing?](#what-is-this-code-doing)
        - [My email wasn't found](#my-email-wasnt-found)
    - [Find an SMS message](#find-an-sms-message)
    - [Testing plain text content](#testing-plain-text-content)
        - [Extracting verification codes from plain text](#extracting-verification-codes-from-plain-text)
    - [Testing HTML content](#testing-html-content)
        - [Working with HTML using DOMDocument](#working-with-html-using-domdocument)
    - [Working with hyperlinks](#working-with-hyperlinks)
        - [Links in plain text (including SMS messages)](#links-in-plain-text-including-sms-messages)
    - [Working with attachments](#working-with-attachments)
        - [Writing an attachment to disk](#writing-an-attachment-to-disk)
    - [Working with images and web beacons](#working-with-images-and-web-beacons)
        - [Remotely-hosted images](#remotely-hosted-images)
        - [Triggering web beacons](#triggering-web-beacons)
    - [Spam checking](#spam-checking)
    - [Development](#development)
    - [Contacting us](#contacting-us)

You can find the full [Mailosaur documentation](https://mailosaur.com/docs/) on the website.

If you get stuck, just contact us at .

### Installation

[](#installation)

You can install the bindings via Composer. Run the following command:

```
composer require mailosaur/mailosaur
```

To use the client library, use Composer's autoload:

```
require_once('vendor/autoload.php');
```

### Set your API key

[](#set-your-api-key)

Get your API key from the [Mailosaur Dashboard](https://mailosaur.com/app/keys) and set it as an environment variable:

```
export MAILOSAUR_API_KEY='your-api-key-here'
```

### Create your code

[](#create-your-code)

Now import the library and create a client:

```
use Mailosaur\MailosaurClient;

$mailosaur = new MailosaurClient();
```

### API Reference

[](#api-reference)

This library is powered by the Mailosaur [email &amp; SMS testing API](https://mailosaur.com/docs/api/). You can easily check out the API itself by looking at our [API reference documentation](https://mailosaur.com/docs/api/) or via our Postman or Insomnia collections:

[![Run in Postman](https://camo.githubusercontent.com/82ccefddb001e2caf9d399f1153fdda561cf3da341bb270e18644d516906bc64/68747470733a2f2f72756e2e7073746d6e2e696f2f627574746f6e2e737667)](https://app.getpostman.com/run-collection/6961255-6cc72dff-f576-451a-9023-b82dec84f95d?action=collection%2Ffork&collection-url=entityId%3D6961255-6cc72dff-f576-451a-9023-b82dec84f95d%26entityType%3Dcollection%26workspaceId%3D386a4af1-4293-4197-8f40-0eb49f831325)[![Run in Insomnia](https://camo.githubusercontent.com/c20c32d5d0fda0969d1050c77a4007e5815c0aaca26d0b623246c02ac3674455/68747470733a2f2f696e736f6d6e69612e726573742f696d616765732f72756e2e737667)](https://insomnia.rest/run/?label=Mailosaur&uri=https%3A%2F%2Fmailosaur.com%2Finsomnia.json)

Creating an account
-------------------

[](#creating-an-account)

Create a [free trial account](https://mailosaur.com/app/signup) for Mailosaur via the website.

To start testing you'll need three things:

- **API key** - [manage API keys within the Mailosaur Dashboard](https://mailosaur.com/app/keys). You can scope a key to a single inbox (server) — recommended — or create an account-level key. [Learn more about API keys](https://mailosaur.com/docs/managing-your-account/api-keys/).
- **Inbox (server) domain** - open [your inbox](https://mailosaur.com/app/servers/default) (server) within the Mailosaur Dashboard to see its domain name (e.g. `abc123.mailosaur.net`). You'll need this to send email to the inbox (server).
- **Inbox (server) ID** - the first part of the inbox (server) domain. For `abc123.mailosaur.net` the ID is `abc123`. You need this whenever you interact with the inbox (server) via the API.

Test email addresses with Mailosaur
-----------------------------------

[](#test-email-addresses-with-mailosaur)

Mailosaur gives you an **unlimited number of test email addresses** - with no setup or coding required!

Here's how it works:

- When you create an account, you are given an inbox (server).
- Every inbox (server) has its own domain name (e.g. `abc123.mailosaur.net`)
- Any email address that ends with `@{YOUR_SERVER_DOMAIN}` will work with Mailosaur without any special setup. For example:
    - `build-423@abc123.mailosaur.net`
    - `john.smith@abc123.mailosaur.net`
    - `rAnDoM63423@abc123.mailosaur.net`
- You can create more inboxes (servers) when you need them. Each one will have its own domain name.

***Can't use test email addresses?** You can also [use SMTP to test email](https://mailosaur.com/docs/email-testing/sending-to-mailosaur/#sending-via-smtp). By connecting your product or website to Mailosaur via SMTP, Mailosaur will catch all email your application sends, regardless of the email address.*

Find an email
-------------

[](#find-an-email)

In automated tests you will want to wait for a new email to arrive. This library makes that easy with the `messages->get` method. Here's how you use it:

```
