示例#1
0
 public function mailto(Request $request)
 {
     $messages = ['email.required' => 'El correo debe ser válido', 'email.email' => 'El correo debe ser válido'];
     // validate the title
     $this->validate($request, ['email' => 'required|email'], $messages);
     $user = Auth::user();
     $creator = $user->id;
     $blueprint = Blueprint::find($request->input('id'));
     $email = $request->input("email");
     $form_key = str_replace("/", "", Hash::make('blueprint' . $blueprint->id . $email));
     $_header = $request->input('header', null);
     $header = $_header ? $_header : self::HEADER;
     // escapeshellarg($_header)
     if (!$blueprint->is_visible) {
         $request->session()->flash('status', ['type' => 'create-fail send-fail alert', 'name' => "la encuesta no es pública, y no se pueden enviar correos!"]);
         return redirect('dashboard/encuestados');
     }
     $applicant = Applicant::firstOrCreate(["blueprint_id" => $blueprint->id, "form_key" => $form_key, "user_email" => $email]);
     $this->sendForm($applicant, $header);
     $update = $blueprint->emails + 1;
     $blueprint->emails = $update;
     $blueprint->update();
     $mailgun = new MailgunEmail(["blueprint" => $blueprint->id, "emails" => 1]);
     $mailgun->save();
     $request->session()->flash('status', ['type' => 'create', 'name' => "el correo se ha enviado!"]);
     return redirect('dashboard/encuestados');
 }
示例#2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $_key = $this->argument('key');
     $_blueprint = $this->argument('blueprint');
     $_file = $this->argument('file');
     $_creator = $this->argument('creator');
     $_header = escapeshellarg($this->argument('header'));
     $blueprint = Blueprint::find($_blueprint);
     if (!$blueprint) {
         Log::error("la encuesta con id: {$_blueprint} no se encontró");
         return;
     }
     $blueprint->sending_emails = 1;
     $blueprint->update();
     $counter = 0;
     Excel::load("storage/app/" . $_key . ".xlsx", function ($reader) use($blueprint, $counter, $_key, $_header) {
         $reader->each(function ($row) use($blueprint, $counter, $_key, $_header) {
             if (trim($row->correo) != "" && filter_var($row->correo, FILTER_VALIDATE_EMAIL)) {
                 $form_key = str_replace("/", "", Hash::make('blueprint' . $blueprint->id . $row->correo));
                 $applicant = Applicant::firstOrCreate(["blueprint_id" => $blueprint->id, "form_key" => $form_key, "user_email" => $row->correo, "temporal_key" => $_key]);
                 $path = base_path();
                 exec("php {$path}/artisan email:send {$applicant->id} {$_header} > /dev/null &");
                 $update = $blueprint->emails + 1;
                 $blueprint->emails = $update;
                 $blueprint->update();
             }
         });
     })->first();
     $total = Applicant::where("temporal_key", $_key)->count();
     $mailgun = new MailgunEmail(["blueprint" => $blueprint->id, "emails" => $total]);
     $mailgun->save();
     $blueprint->sending_emails = 0;
     $blueprint->update();
 }