Ejemplo n.º 1
0
 public function mailStore(Request $request)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $validation = Validator::make($request->all(), ['from_address' => 'required|email', 'from_name' => 'required']);
     if ($validation->fails()) {
         return redirect()->back()->withInput()->withErrors($validation->messages());
     }
     $mail_config = Helper::getMail();
     $services = Helper::getServices();
     $config_type = $request->input('config_type');
     $mail_config['driver'] = $request->input('driver');
     $mail_config['from']['address'] = $request->input('from_address');
     $mail_config['from']['name'] = $request->input('from_name');
     if ($request->input('driver') == 'smtp') {
         $mail_config['host'] = $request->input('host');
         $mail_config['port'] = $request->input('port');
         $mail_config['username'] = $request->input('username');
         $mail_config['password'] = $request->input('password');
     } elseif ($request->input('driver') == 'mandrill') {
         $services['mandrill']['secret'] = $request->input('mandrill_secret');
         $filename = base_path() . config('paths.SERVICE_PATH');
         File::put($filename, var_export($services, true));
         File::prepend($filename, '<?php return ');
         File::append($filename, ';');
     } elseif ($request->input('driver') == 'mailgun') {
         $services['mailgun']['secret'] = $request->input('mailgun_secret');
         $services['mailgun']['domain'] = $request->input('mailgun_domain');
         $filename = base_path() . config('paths.SERVICE_PATH');
         File::put($filename, var_export($services, true));
         File::prepend($filename, '<?php return ');
         File::append($filename, ';');
     }
     $mail_config['encryption'] = 'tls';
     $mail_config['sendmail'] = '/usr/sbin/sendmail -bs';
     $mail_config['pretend'] = false;
     $filename = base_path() . config('paths.MAIL_PATH');
     File::put($filename, var_export($mail_config, true));
     File::prepend($filename, '<?php return ');
     File::append($filename, ';');
     return redirect('/configuration#' . $config_type)->withSuccess(config('constants.SAVED'));
 }