/** * @testdox Requesting a password reminder adds an item to the Mail Queue. * @test */ public function emailReminder() { $user = new User(['username' => 'test']); $user->save(); $user->sendPasswordReminder(); $this->assertEquals(1, QueuedEmail::count()); }
public function sendPasswordReminder() { DB::beginTransaction(); // Save the reset token. $passwordReminder = str_random(40); $this->password_reminder = bcrypt($passwordReminder); $this->save(); // Queue. $queuedEmail = new QueuedEmail(); $queuedEmail->recipient_id = $this->id; $queuedEmail->subject = 'Password reminder for ' . config('app.site_name'); $queuedEmail->template = 'users/reminder_email'; $queuedEmail->data = ['password_reminder' => $passwordReminder]; $queuedEmail->save(); DB::commit(); }
public function handle() { $num = $this->argument('num'); $queuedEmails = QueuedEmail::query()->take($num)->get(); foreach ($queuedEmails as $email) { $standardData = ['site_name' => config('app.site_name'), 'user' => $email->recipient]; $data = array_merge($standardData, $email->data); \Mail::send($email->template, $data, function (\Illuminate\Mail\Message $msg) use($email) { $msg->from(config('app.site_email'), config('app.site_name')); if (!empty($email->recipient->email)) { $msg->to($email->recipient->email, $email->recipient->name); } else { // If the recipient doesn't have an email address recorded, // forward this to the site administrator to figure out. $msg->to(config('app.site_email')); $transParams = ['name' => $email->recipient->name, 'site_email' => config('app.site_email')]; $newBody = trans('mail.no-recipient-address', $transParams) . '<hr />' . $msg->getSwiftMessage()->getBody(); $msg->getSwiftMessage()->setBody($newBody); } $msg->subject($email->subject); }); $email->delete(); } }
public function index(Request $request) { if ($request->input('username')) { return redirect('users/' . $request->input('username')); } $this->view->title = 'Users'; $this->view->breadcrumbs = ['users' => 'Users']; $this->view->email_queue_count = \App\Model\QueuedEmail::count(); $this->view->roles = Role::orderBy('name', 'ASC')->get(); $this->view->users = User::orderBy('name', 'ASC')->paginate(20); $start = new \DateTime('today'); $end = new \DateTime('1 month'); $this->view->dates = new \DatePeriod($start, new \DateInterval('P1D'), $end); $this->view->day_count = iterator_count($this->view->dates); return $this->view; }