1. Go to this page and download the library: Download mailcapture/mailcapture-php 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/ */
mailcapture / mailcapture-php example snippets
use MailCapture\MailCapture;
$mc = new MailCapture($_ENV['MAILCAPTURE_API_KEY']);
$mc->ping(); // validates key, caches username
// In your test:
$mc->delete('signup');
$yourApp->register($mc->address('signup')); // e.g. "[email protected]"
$email = $mc->waitFor('signup', timeout: 15.0);
echo $email->subject; // "Verify your account"
echo $email->otp; // "123456" — extracted automatically
use MailCapture\MailCapture;
use MailCapture\Model\Capture;
use PHPUnit\Framework\TestCase;
class UserRegistrationTest extends TestCase
{
private static MailCapture $mc;
public static function setUpBeforeClass(): void
{
self::$mc = new MailCapture($_ENV['MAILCAPTURE_API_KEY']);
self::$mc->ping();
}
protected function setUp(): void
{
self::$mc->delete('signup'); // clean inbox before every test
}
public function testUserReceivesVerificationEmail(): void
{
$inbox = self::$mc->inbox('signup');
$this->app->register($inbox->getAddress()); // "[email protected]"
$email = $inbox->waitFor(timeout: 10.0);
$this->assertSame('Verify your account', $email->subject);
$this->assertMatchesRegularExpression('/^\d{6}$/', $email->otp);
$this->assertLessThan(5000, $email->latencyMs);
}
}
$mc = new MailCapture(
apiKey: $_ENV['MAILCAPTURE_API_KEY'],
baseUrl: 'http://localhost:3002', // override for local dev (default: https://mailcapture.app)
requestTimeout: 15.0, // seconds, default 10.0
username: 'alice', // pre-set to skip ping() (optional)
);
// Named arguments (recommended)
$email = $mc->waitFor('signup', timeout: 15.0);
// Full options
$email = $mc->waitFor(
tag: 'signup',
timeout: 15.0, // total seconds to wait (default 30)
pollTimeout: 5, // per-poll server timeout in seconds, max 30 (default 10)
after: new DateTime('-30 seconds'), // only captures after this time
);
$inbox = $mc->inbox('password-reset');
$inbox->getAddress() // "[email protected]"
$inbox->waitFor(timeout: 10.0) // Capture
$inbox->list(limit: 5) // CaptureList
$inbox->clear() // deletes all captures for this tag