/** * Store a newly created resource in storage. * * @return Response */ public function update(SettingRequest $request) { foreach ($request->all() as $name => $value) { if ($name != '_method' && $name != '_token') { $setting = Setting::whereName($name)->first(); $setting->update(['value' => $value]); } } //更新设置缓存 \Cache::forget('settings_array'); return redirect('admin/settings/index'); }
public function postSettings(Request $request) { $user_id = Auth::user()->id; $input = $request->all(); $validator = Validator::make($input, ['custom_domain' => 'required']); if ($validator->passes()) { $data['customer_id'] = $user_id; $data['name'] = 'custom_domain'; $data['value'] = removeSchemaUrl($input['custom_domain']); $setting = Setting::whereName('custom_domain')->where('customer_id', '=', $user_id)->first(); if (!$setting) { Setting::create($data); } else { $setting->value = $data['value']; $setting->save(); } return redirect()->back()->with("status", "Settings updated successfully"); } else { return redirect()->back()->withErrors($validator)->withInput(); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, $webinarId) { ini_set("max_execution_time", 0); try { $webinar = Webinar::find($webinarId); $webinar_uuid = hashWebinar($webinarId); $user_id = Auth::user()->id; $subscribers_lists = $webinar->subscribers_lists()->get(); $webinar_signup_subscribers_lists = $webinar->signup_subscribers_lists()->get(); $input = $request->all(); if (count($subscribers_lists) > 0) { $subject = $input['subject']; $body = $input['content']; $smtp_method = $input['smtp_method'][0]; $setting = Setting::whereName('custom_domain')->where('customer_id', '=', $user_id)->first(); if (!$setting) { return redirect()->back()->with("error", "Custom Domain is not Set."); } $smtp = Smtp::find($smtp_method); if (!$smtp) { return redirect()->back()->with("error", "No SMTP Method Found"); } $custom_domain = $setting->value; config(["mail.driver" => "smtp", "mail.host" => $smtp->host, "mail.port" => $smtp->port, "mail.from.address" => $smtp->from_email, "mail.from.name" => $smtp->from_name, "mail.encryption" => $smtp->protocol, "mail.username" => $smtp->username, "mail.password" => $smtp->password]); // General Subscribers List if ($subscribers_lists) { foreach ($subscribers_lists as $subscriber_list) { $subscribers = $subscriber_list->activeSubscribers()->get(); if (count($subscribers) > 0) { foreach ($subscribers as $subscriber) { $subscriber_hash = $subscriber->uuid; $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name; $to_email = $subscriber->email; $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash; $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url]; Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) { $message->subject($subject); $message->from('*****@*****.**', 'Webinar Admin'); $message->to($to_email, $subscriber_name); }); } } } } // Send Email to Webinar Specific Subscribers if ($webinar_signup_subscribers_lists) { foreach ($webinar_signup_subscribers_lists as $subscriber_list) { $subscribers = $subscriber_list->activeSubscribers()->get(); if (count($subscribers) > 0) { foreach ($subscribers as $subscriber) { echo $subscriber->id . "<br/>"; $subscriber_hash = $subscriber->uuid; $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name; $to_email = $subscriber->email; $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash; $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url]; Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) { $message->subject($subject); $message->to($to_email, $subscriber_name); }); } } } } } return redirect()->back()->with("status", "Mail Sent Succesfully"); } catch (\Exception $e) { } return redirect()->back(); }
public function postEmailNotification(Request $request, $userId, $webinarUUId) { ini_set("max_execution_time", 0); $input = $request->all(); $webinar = Webinar::whereId($webinarUUId)->first(); $webinar_uuid = $webinar->uuid; $subscribers_lists = $webinar->subscribers_lists()->get(); $webinar_signup_subscribers_lists = $webinar->signup_subscribers_lists()->get(); $setting = Setting::whereName('custom_domain')->where('customer_id', '=', $userId)->first(); if (!$setting) { return redirect()->back()->with("error", "Custom Domain is not Set."); } $custom_domain = $setting->value; $rules = ["subject" => "required", "content" => "required", "smtp_method" => "required", "send_type" => "required"]; $validator = Validator::make($input, $rules); if ($validator->passes()) { $send_type = $input["send_type"]; $input['customer_id'] = $userId; $input['smtp_setting_id'] = $input['smtp_method']; $smtp = Smtp::find($input['smtp_method']); if (!$smtp) { return redirect()->back()->with("error", "No SMTP Method Found"); } unset($input['smtp_method']); if ($send_type == "now") { $input['send_date'] = Carbon::now(); $input['minutes_before_webinar'] = NULL; } else { if ($send_type == "minutes_before") { $minutes_before_webinar = $input['minutes_before_webinar']; $input['send_date'] = Carbon::parse($webinar->starts_on)->subMinutes($minutes_before_webinar); $input['minutes_before_webinar'] = $minutes_before_webinar; } } $count_subscribers = 0; $input['webinar_id'] = $webinar->id; $email_notification = EmailNotification::create($input); $email_notification->uuid = hashCampaignEmail($email_notification->id); $email_notification->save(); $subject = $input['subject']; $body = $input['content']; if ($send_type == "now") { // Send Instant Email config(["mail.driver" => "smtp", "mail.host" => $smtp->host, "mail.port" => $smtp->port, "mail.from.address" => $smtp->from_email, "mail.from.name" => $smtp->from_name, "mail.encryption" => $smtp->protocol, "mail.username" => $smtp->username, "mail.password" => $smtp->password]); try { // General Subscribers List if ($subscribers_lists) { foreach ($subscribers_lists as $subscriber_list) { $subscribers = $subscriber_list->activeSubscribers()->get(); if (count($subscribers) > 0) { $count_subscribers += count($subscribers); foreach ($subscribers as $subscriber) { $subscriber_hash = $subscriber->uuid; $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name; $to_email = $subscriber->email; $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash; $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url]; //pr($emailData); die; Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) { $message->subject($subject); $message->from('*****@*****.**', 'Webinar Admin'); $message->to($to_email, $subscriber_name); }); } } } } // Send Email to Webinar Specific Subscribers if ($webinar_signup_subscribers_lists) { foreach ($webinar_signup_subscribers_lists as $subscriber_list) { $subscribers = $subscriber_list->activeSubscribers()->get(); if (count($subscribers) > 0) { $count_subscribers += count($subscribers); foreach ($subscribers as $subscriber) { $subscriber_hash = $subscriber->uuid; $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name; $to_email = $subscriber->email; $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash; $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url]; Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) { $message->subject($subject); $message->to($to_email, $subscriber_name); }); } } } } // Mail Sent Successfully $email_notification->count_subscribers = $count_subscribers; $email_notification->status = 1; $email_notification->save(); } catch (\Exception $e) { // Error in Sending Mail $email_notification->status = -1; $email_notification->save(); } } return redirect()->back()->with('status', "Email Notification updated successfully"); } else { return redirect()->back()->withErrors($validator)->withInput(); } }