/** * @Then /^I should receive a confirmation email$/ */ public function iShouldReceiveAConfirmationEmail() { $mailinator = new Mailinator(self::MAILINATOR_TOKEN); //we can wait or not for the email to arrive in the inbox sleep(5); //let's wait 5sec try { $data = $mailinator->fetchInbox(self::$email); if (count($data) > 0) { /** * Note that the $data array returned by the mailinator API will have keys in the array starting with 0 * for ex. if we have 2 emails in the inbox then: * $data[0]['id'] - is the id of the oldest email * and $data[1]['id'] - is the id of the latest email * * the structure of the $data array returned: *array(9) { 'seconds_ago' 'id' 'to' 'time' 'subject' 'fromfull' 'been_read' 'from' 'ip' } */ //var_dump($data); sleep(2); //note that if we make to many requests we will get api error 429 'Too Many Requests'. This is a limitation of the free mailinator account //let's check if the latest email is from 'Madison Island' with the subject 'Welcome, FIRST_NAME LAST_NAME!' if ($data[count($data) - 1]['from'] == 'Madison Island' && $data[count($data) - 1]['subject'] == 'Welcome, ' . self::FIRST_NAME . ' ' . self::LAST_NAME . '!') { echo "'We have received the registration email!\n"; echo "We have an email from : " . $data[count($data) - 1]['from'] . "\n"; echo "With the subject : " . $data[count($data) - 1]['subject'] . "\n"; } else { throw new Exception("The registration email was not found!\n"); } //we can also get the content of the email if we want $email_id = $data[count($data) - 1]['id']; //let's get the id of the latest email $email_content = $mailinator->fetchMail($email_id); //then we can get an array with the content of the email echo "Email content:\n"; print_r($email_content); } else { throw new Exception("No emails found in the inbox.\n"); } } catch (Exception $e) { //we will fail this step if we have any exceptions throw new Exception("Something went wrong: " . $e->getMessage()); } }
<?php require 'Mailinator.php'; $em = '*****@*****.**'; $mailinator = new Mailinator("380dd5efc8a94b50821226fa62b91067"); //Get messages in inbox// try { print_r($mailinator->fetchInbox($em)); } catch (Exception $e) { // Process the error echo "Inca nu a venit mesaj"; }