/**
  * @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());
     }
 }
Exemple #2
0
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    $data = curl_exec($curl);
    curl_close($curl);
    $data = preg_replace("/.*?<body.*?>/is", "", $data);
    $data = preg_replace("/<\\/body>.*?/is", "", $data);
    return true;
}
function get_string_between($string, $start, $end)
{
    $string = " " . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) {
        return "";
    }
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
}
$data = $_POST['res'];
$link = get_string_between($data, "id]", "[");
$link = substr($link, 4, strlen($link));
$link = trim($link);
require 'Mailinator.php';
$mailinator = new Mailinator("380dd5efc8a94b50821226fa62b91067");
try {
    print_r($mailinator->fetchMail($link));
} catch (Exception $e) {
    // Process the error
    echo "Inca nu a venit mesaj";
}
<?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";
}