PHP code example of redberry / mailbox-for-laravel
1. Go to this page and download the library: Download redberry/mailbox-for-laravel 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/ */
redberry / mailbox-for-laravel example snippets
use Redberry\MailboxForLaravel\Testing\InteractsWithMailbox;
uses(InteractsWithMailbox::class);
class OrderEmailTest extends TestCase
{
use InteractsWithMailbox;
}
use Redberry\MailboxForLaravel\Facades\Mailbox;
use Redberry\MailboxForLaravel\DTO\MailboxMessageData;
Mailbox::assertSentCount(2);
Mailbox::assertNothingSent();
Mailbox::assertSentTo('[email protected] ');
Mailbox::assertNotSentTo('[email protected] ');
Mailbox::assertSent(fn (MailboxMessageData $m) => $m->subject === 'Welcome');
Mailbox::assertSent(
fn (MailboxMessageData $m) => str_contains($m->subject, 'Newsletter'),
expectedCount: 3,
);
Mailbox::firstSent()
->assertHasSubject('Order Confirmation')
->assertFrom('[email protected] ')
->assertHasTo('[email protected] ')
->assertSeeInHtml('Order #12345')
->assertDontSeeInHtml('error')
->assertHasAttachment('invoice.pdf', 'application/pdf')
->assertAttachmentCount(1);
Mailbox::firstSent(fn (MailboxMessageData $m) => $m->subject === 'Password Reset')
->assertHasTo('[email protected] ')
->assertSeeInHtml('Reset your password');
it('sends welcome email with getting started guide', function () {
$this->post('/register', [
'name' => 'John Doe',
'email' => '[email protected] ',
'password' => 'secret123',
]);
Mailbox::assertSentCount(1);
Mailbox::assertSentTo('[email protected] ');
Mailbox::firstSent()
->assertHasSubject('Welcome, John!')
->assertFrom('[email protected] ')
->assertSeeInOrderInHtml(['Welcome', 'Getting Started', 'Support'])
->assertHasAttachment('getting-started.pdf');
});
'connections' => [
'mailbox' => [
'driver' => 'mysql',
'host' => env('MAILBOX_DB_HOST', '127.0.0.1'),
'database' => env('MAILBOX_DB_DATABASE', 'mailbox'),
'username' => env('MAILBOX_DB_USERNAME', 'root'),
'password' => env('MAILBOX_DB_PASSWORD', ''),
],
],
// config/filesystems.php
'disks' => [
'mailbox' => [
'driver' => 's3',
'bucket' => env('MAILBOX_S3_BUCKET'),
'region' => env('MAILBOX_S3_REGION', 'us-east-1'),
],
],
'store' => [
'driver' => 'redis',
'resolvers' => [
'redis' => fn () => new \App\Storage\RedisMessageStore,
],
],
use Illuminate\Support\Facades\Gate;
public function boot(): void
{
Gate::define('viewMailbox', fn ($user) => $user?->isAdmin());
}
bash
php artisan mailbox:install
xml
<env name="MAIL_MAILER" value="mailbox"/>
<env name="MAILBOX_STORE_DRIVER" value="file"/>
<env name="MAILBOX_STORE_FILE_PATH" value="storage/framework/testing/mailbox"/>
<env name="MAILBOX_ATTACHMENTS_PATH" value="testing/attachments"/>
bash
MAILBOX_STORE_DATABASE_CONNECTION=mailbox_testing php artisan mailbox:install
vendor/bin/pest
bash
php artisan vendor:publish --tag=mailbox-config
bash
composer update redberry/mailbox-for-laravel
php artisan mailbox:upgrade
bash
php artisan vendor:publish --tag=mailbox-config --force