public function sendEmail($template, $data = [], $to, $toName, $subject, $cc = null, $bcc = null, $replyTo = null) { $result = false; try { $config = new Config(); $messageHeader = ['from' => $config->getValueByKey('address_sender_mail'), 'fromName' => $config->getValueByKey('display_name_send_mail'), 'to' => $to, 'toName' => $toName, 'cc' => $cc, 'bcc' => $bcc, 'replyTo' => $replyTo, 'subject' => $subject]; \Mail::send($template, $data, function ($message) use($messageHeader) { $message->from($messageHeader['from'], $messageHeader['fromName']); $message->to($messageHeader['to'], $messageHeader['toName']); if (!is_null($messageHeader['cc'])) { $message->cc($messageHeader['cc']); } if (!is_null($messageHeader['bcc'])) { $message->bcc($messageHeader['bcc']); } if (!is_null($messageHeader['replyTo'])) { $message->replyTo($messageHeader['replyTo']); } $message->subject($messageHeader['subject']); }); $result = true; } catch (Exception $e) { $result = ['success' => false, 'message' => $e->getMessage()]; } return \Response::json($result); }
public function createContact(Request $request) { $validator = Validator::make($request->get('Contact'), Contact::$rules); if ($validator->fails()) { return redirect()->back()->withErrors($validator->errors()); } else { $contact = new Contact(); $contact->full_name = $request->input('Contact.full_name'); $contact->email = $request->input('Contact.email'); $contact->phone = $request->input('Contact.phone'); $contact->subject = $request->input('Contact.subject'); $contact->content = $request->input('Contact.content'); //save data contact $contact->save(); // send email $common = new Common(); $config = new Config(); $common->sendEmail('frontend.emails.contact', $data = ['contact' => $contact], $to = $config->getValueByKey('address_received_mail'), $toName = $contact->full_name, $subject = $contact->subject, $cc = $contact->email, $replyTo = $contact->email); //return redirect(route('contact'))->with('contact-status', 'Nội dung liên hệ của quý khách đã được gửi đến ban quản trị. Chúng tôi sẽ phản hồi quý khách trong thời gian sớm nhất. Xin cảm ơn!'); return 1; } }
public function createContact(Request $request) { $json = json_decode('{"success":false, "message": "Đăng ký không thành công"}'); //$arrayName = array('success' => false, 'message' => 'Đăng ký không thành công' ); $validator = Validator::make($request->get('Contact'), Contact::$rules); if ($validator->fails()) { if ($request->ajax()) { return response()->json($json); } else { return redirect()->back()->withErrors($validator->errors()); } } else { $contact = new Contact(); $contact->full_name = $request->input('Contact.full_name'); $contact->email = $request->input('Contact.email'); $contact->phone = $request->input('Contact.phone'); $contact->subject = $request->input('Contact.subject'); $contact->content = $request->input('Contact.content'); //Tiến hành lưu dữ liệu vào database $contact->save(); // send email $common = new Common(); $config = new Config(); try { $common->sendEmail('frontend.emails.contact', $data = ['contact' => $contact], $to = $config->getValueByKey('address_received_mail'), $toName = $contact->full_name, $subject = $contact->subject, $cc = $contact->email, $replyTo = $contact->email); } catch (Exception $e) { } if ($request->ajax()) { $json->success = true; $json->message = 'Chúng tôi sẽ chủ động cập nhật thông tin mới nhất đến bạn.'; return response()->json($json); } else { return redirect(route('contact'))->with('contact-status', 'Nội dung liên hệ của quý khách đã được gửi đến ban quản trị. Chúng tôi sẽ phản hồi quý khách trong thời gian sớm nhất. Xin cảm ơn!'); } } }