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.0(2mo ago)2318.8k↑27.9%31MITPHPPHP &gt;=7.2CI passing

Since Sep 24Pushed 2mo ago2 watchersCompare

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

READMEChangelog (10)Dependencies (6)Versions (31)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:

- [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)
- [Find an SMS message](#find-an-sms-message)
- [Testing plain text content](#testing-plain-text-content)
- [Testing HTML content](#testing-html-content)
- [Working with hyperlinks](#working-with-hyperlinks)
- [Working with attachments](#working-with-attachments)
- [Working with images and web beacons](#working-with-images-and-web-beacons)
- [Spam checking](#spam-checking)

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/project/api) and set it as an environment variable:

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

### Create your code

[](#create-your-code)

Then import the library into your code:

```
$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.

Once you have this, navigate to the [API tab](https://mailosaur.com/app/project/api) to find the following values:

- **Server ID** - Servers act like projects, which group your tests together. You need this ID whenever you interact with a server via the API.
- **Server Domain** - Every server has its own domain name. You'll need this to send email to your server.
- **API Key** - You can create an API key per server (recommended), or an account-level API key to use across your whole account. [Learn more about API keys](https://mailosaur.com/docs/managing-your-account/api-keys/).

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 a server.
- Every server has its own **Server 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 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:

```
