public function pdf($id)
 {
     $hashId = \Jamesy\Miscellaneous::encryptId($id);
     $pdf = new SimpleHTMLToPDF();
     $link = URL::to('email/show/' . $hashId);
     $pdf->display($link);
 }
예제 #2
0
         Route::get('dashboard/users/{id}/ban', 'UserController@ban');
         Route::get('dashboard/users/{id}/unban', 'UserController@un_ban');
         Route::get('dashboard/users/{id}/destroy', 'UserController@destroy');
         Route::group(['before' => 'csrf'], function () {
             Route::post('dashboard/users/store', 'UserController@store');
             Route::post('dashboard/users/update', 'UserController@update');
             Route::post('dashboard/users/bulk-destroy', 'UserController@bulk_destroy');
         });
     });
     Route::get('dashboard/logout', 'AuthenticationController@logout');
 });
 //Email Pages Frontend Stuff
 Route::get('email/{slug}/preview', 'FrontendController@preview');
 Route::get('email/{slug}', 'FrontendController@show');
 Route::get('email/show/{hashId}', function ($hashId) {
     $id = \Jamesy\Miscellaneous::decryptId($hashId);
     if ($email = Email::find($id)) {
     }
     return View::make('backend.emails.send_templates.view-in-browser', ['email_body' => $email->email_body]);
 });
 //Mailgun API Endpoint
 Route::post('VjwombzKYGxeAKLB', 'AnalyticController@delivered');
 Route::post('YlpnbJyeXGPORABk', 'AnalyticController@failed');
 Route::post('bQKgqoyPXyORMZeN', 'AnalyticController@opened');
 Route::post('EWOvPbGNPznDdJek', 'AnalyticController@clicked');
 Route::post('BLNlanrLvyAXgVkp', 'AnalyticController@bounced');
 Route::post('XxLMnpzjmyJDNPmZ', 'AnalyticController@complained');
 //Unsubscribe
 Route::get('unsubscribe/{id}', 'FrontendController@unsubscribe');
 //Etc
 Route::get('dashboard/pdf/test', 'SentEmailCustomController@test');
 public function send()
 {
     $inputs = [];
     foreach (Input::all() as $key => $input) {
         $inputs[$key] = Jamesy\Sanitiser::trimInput($input);
     }
     $rules = Input::has('save_draft') ? $this->draftRules : $this->rules;
     $validation = Jamesy\MyValidations::validate($inputs, $rules);
     if ($validation != NULL) {
         return Redirect::back()->withErrors($validation)->withInput();
     } else {
         if (Input::has('save_draft')) {
             $draft = Input::has('was_draft') ? Draft::find(Input::get('was_draft')) : new Draft();
             $draft->user_id = $this->user->id;
             $draft->tag_id = $inputs['tag_id'];
             $draft->subject = $inputs['subject'];
             $draft->email_body = $inputs['email_body'];
             $draft->save();
             return Redirect::to('dashboard/emails/drafts');
         } else {
             $maxSendNum = 999;
             $email = new Email();
             $email->user_id = $this->user->id;
             $email->tag_id = $inputs['tag_id'];
             $email->from = Setting::getFromName($this->user) . " (" . Setting::getFromEmail($this->user) . ")";
             $email->reply_to = Setting::getFromName($this->user) . " (" . Setting::getReplyToEmail($this->user) . ")";
             $email->subject = $inputs['subject'];
             $email->email_body = $inputs['email_body'];
             $email->save();
             $maillists = Input::has('mail_lists') ? $inputs['mail_lists'] : [];
             $emails = Input::has('subscribers') ? $inputs['subscribers'] : [];
             $selectedSubs = Subscriber::getSelectedSubscribersForEmail($maillists, $emails);
             while (count($selectedSubs)) {
                 $data = ['email_body' => $inputs['email_body'], 'email_id' => \Jamesy\Miscellaneous::encryptId($email->id)];
                 $variables = [];
                 $tag = Tag::find($inputs['tag_id']);
                 $emailId = $email->id;
                 $numToSlice = count($selectedSubs) > $maxSendNum ? $maxSendNum : count($selectedSubs);
                 $subscribers = $numToSlice < count($selectedSubs) ? array_slice($selectedSubs, 0, $numToSlice) : $selectedSubs;
                 foreach ($subscribers as $subscriber) {
                     $variables[$subscriber['email']] = ['id' => $subscriber['id'], 'first_name' => $subscriber['first_name'], 'last_name' => $subscriber['last_name']];
                 }
                 $result = Mailgun::send('backend.emails.send_templates.main', $data, function ($message) use($subscribers, $inputs, $variables, $emailId, $tag) {
                     $message->from(Setting::getFromEmail($this->user), Setting::getFromName($this->user))->replyTo(Setting::getReplyToEmail($this->user), Setting::getFromName($this->user))->subject($inputs['subject']);
                     foreach ($subscribers as $subscriber) {
                         $message->to($subscriber['email'], $subscriber['first_name'] . ' ' . $subscriber['last_name']);
                     }
                     $message->recipientVariables($variables);
                     $message->tag($tag->name);
                 });
                 if (is_object($result)) {
                     if ($result->http_response_code == 200) {
                         foreach ($subscribers as $subscriber) {
                             $apicall_id = explode('<', explode('@', $result->http_response_body->id)[0])[1];
                             $analytic = new Analytic();
                             $analytic->subscriber_id = $subscriber['id'];
                             $analytic->email_id = $email->id;
                             $analytic->recipient = $subscriber['email'];
                             $analytic->apicall_id = $apicall_id;
                             $analytic->status = 'queued';
                             $analytic->save();
                         }
                     }
                 }
                 $selectedSubs = array_slice((array) $selectedSubs, $numToSlice);
             }
             if (Input::has('was_draft')) {
                 Draft::find(Input::get('was_draft'))->delete();
             }
             return Redirect::to('dashboard/emails/sent');
         }
     }
 }