PHP code example of ingenerator / mailhook

1. Go to this page and download the library: Download ingenerator/mailhook 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/ */

    

ingenerator / mailhook example snippets


$mailhook = new \Ingenerator\Mailhook\Mailhook('/tmp/outgoing_mail.dump');
// You'll usually want to purge the file before your tests, to ensure you have a clean state
$mailhook->purge();

run_my_code_that_should_send_emails();

$mailhook->refresh();

$mails = $mailhook->getEmails();
assert(count($mails) === 1, 'An email was sent');

$mail   = $mailhook->assert()->firstEmailMatching(new EmailSentToMatcher('[email protected]'));
$emails = $mailhook->assert()->emailsMatching(new EmailSentToMatcher('[email protected]'));
$mailhook->assert()->noEmailMatching(new AnyEmailMatcher);

$mailhook = new \Ingenerator\Mailhook\Mailhook('/tmp/outgoing_mail.dump');
$mailhook->purge();

submit_my_password_reset_form();

$mail = $mailhook->assert()->firstEmailMatching(
    new EmailSentToMatcher('[email protected]'),
    new EmailWithLinkMatcher('/reset/')
);
$links  = $mail->getLinksMatching('/reset/');

visit_page_and_reset_password($links[0]->getUrl());