silverslice / mail-reader
Test emails easily
v1.0
2022-02-11 06:49 UTC
Requires
- php: >=7.2
- zbateson/mail-mime-parser: ^2.2
Requires (Dev)
- phpunit/phpunit: ^9.5
- satooshi/php-coveralls: ^1.0
- squizlabs/php_codesniffer: ^3.6
- symfony/filesystem: ^6.0
This package is auto-updated.
Last update: 2024-12-11 13:21:27 UTC
README
Without mailcatcher headache:)
MailReader stores your emails in local directory and provides convenient way to test them.
Install
composer require silverslice/mail-reader
Usage
- Copy
bin/smtp_catcher.php
to convenient folder. - Specify folder for e-mails in
bin/smtp_catcher.php
(optional). - Set in php.ini:
sendmail_path = /path/to/smtp_catcher.php
- Write test:
use Silverslice\MailReader\MailReader; ... public function testGetLastMessage() { $reader = new MailReader('/path/to/mails/'); // get last sent message $message = $reader->getLastMessage(); $this->assertEquals('fromemail@mail.dev', $message->getFrom()); $this->assertEquals('toemail@mail.dev', $message->getTo()); $this->assertEquals('Third email', $message->getSubject()); $this->assertContains('This is the last email', $message->getBody()); $this->assertTrue($message->hasAttachment()); $this->assertTrue($message->hasAttachmentWithName('file1.txt')); // get total count of messages $count = $reader->getCountOfMessages(); // get next to the last message $prevMessage = $reader->getLastMessageByIndex(1); // clear all messages $reader->clearMessages(); }