Пример #1
0
 public function testSendMessage()
 {
     // Create an old email to purge
     Config::set('mail-tracker.expire-days', 1);
     $old_email = \jdavidbakr\MailTracker\Model\SentEmail::create(['hash' => str_random(32)]);
     $old_url = \jdavidbakr\MailTracker\Model\SentEmailUrlClicked::create(['sent_email_id' => $old_email->id, 'hash' => str_random(32)]);
     // Go into the future to make sure that the old email gets removed
     \Carbon\Carbon::setTestNow(\Carbon\Carbon::now()->addWeek());
     $faker = Faker\Factory::create();
     $email = $faker->email;
     $subject = $faker->sentence;
     $name = $faker->firstName . ' ' . $faker->lastName;
     \View::addLocation(__DIR__);
     \Mail::send('email.test', [], function ($message) use($email, $subject, $name) {
         $message->from('*****@*****.**', 'From Name');
         $message->sender('*****@*****.**', 'Sender Name');
         $message->to($email, $name);
         $message->cc('*****@*****.**', 'CC Name');
         $message->bcc('*****@*****.**', 'BCC Name');
         $message->replyTo('*****@*****.**', 'Reply-To Name');
         $message->subject($subject);
         $message->priority(3);
     });
     $this->seeInDatabase('sent_emails', ['recipient' => $name . ' <' . $email . '>', 'subject' => $subject, 'sender' => 'From Name <*****@*****.**>', 'recipient' => "{$name} <{$email}>"]);
     $this->assertNull($old_email->fresh());
     $this->assertNull($old_url->fresh());
 }
 public function getL($url, $hash)
 {
     $url = base64_decode(str_replace("\$", "/", $url));
     $tracker = Model\SentEmail::where('hash', $hash)->first();
     if ($tracker) {
         $tracker->clicks++;
         $tracker->save();
         $url_clicked = Model\SentEmailUrlClicked::where('url', $url)->where('hash', $hash)->first();
         if ($url_clicked) {
             $url_clicked->clicks++;
             $url_clicked->save();
         } else {
             $url_clicked = Model\SentEmailUrlClicked::create(['sent_email_id' => $tracker->id, 'url' => $url, 'hash' => $tracker->hash]);
         }
         Event::fire(new LinkClickedEvent($tracker));
     }
     return redirect($url);
 }