Today, We want to share with you Laravel create Dynamic Email Templates from Database.In this post we will show you Laravel Email Templates from Database, hear for How to create a dynamic HTML Email Template we will give you demo and example for implement.In this post, we will learn about Email the contents of a dynamic webpage generated by php with an example.
Laravel create Dynamic Email Templates from Database
There are the Following The simple About Laravel create Dynamic Email Templates from Database Full Information With Example and source code.
As I will cover this Post with live Working example to develop Creating Dynamic Email Template in PHP, so the Laravel create the dynamic template for this example is following below.
function send_mail_template($to, $from, $subject, $message) { $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= "From: ContactNameGoesHere <" . $from . ">\r\n"; $response = mail($to, $subject, $message, $headers); }
function buildTemplate($email_subject_image, $message) { // Get Laravel email template as string $email_template_string = file_get_contents('template.html', true); // Fill Laravel email template with comments or message and relevant banner image $email_msg_dtls = sprintf($email_template_string,'BASE_URL/banner_' . $email_subject_image. '.png', $message, $mobile_plugin_string); return $email_msg_dtls; } $from = "[email protected]"; $to = "[email protected]"; $body_text = "Your email has been successfully verified...(Good Luck!)"; $banner_image_subject = "Your Email account_verified"; $email_msg_dtls = buildTemplate($banner_image_subject, $body_text); send_email($to, $from, "You email has been verified", $email_msg_dtls);
Creating Dynamic Email Template in Laravel
Helper.php
public static function parseTemplate($email_msg_dtls,$token_array) { $pattern = '[%s]'; foreach($token_array as $key=>$val){ $varMap[sprintf($pattern,$key)] = $val; } return strtr($email_msg_dtls,$varMap); } public static function buildTemplate($email_msg_dtls,$user_type) { $custom_email_msg = ""; if($user_type == 'admin') { //$custom_email_msg .="--------admin----------"; $custom_email_msg .=$email_msg_dtls; } else{ // $custom_email_msg .="--------user----------"; $custom_email_msg .=$email_msg_dtls; } $custom_email_msg .= ""; return $custom_email_msg; }
app/Http/Controllers/customchartController.php
public function store(Request $request) { if ($request->has('newvisitors')) { try { DB::table('visitors')->insert([ 'discussions_id' => $request['discussions_id'], 'message' => $request['formText'], 'visitor_name' => $request['xyzzy'], 'visitor_email' => $request['zyxxy'], 'visitors_ip' => $request->ip(), 'type' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ]); if(!is_null($request['formemailText'])) { $base_url = env('APP_URL'); $get_data = DB::table('discussions')->where('id', '=', $request->discussions_id)->get(); $from = 'Company Name'; $cc = 'Company Name '; $bcc = 'Company Name '; $to = 'Company Name'.trim($request['active_adveiser']); $email_data_templates = DB::table('emailtemplates')->where("id", "=", 1)->get(); $message_subject = trim($email_data_templates[0]->title); $email_msg_dtls = trim($email_data_templates[0]->content); $data_array_parse = array( 'adveiser_NAME' => $get_data[0]->adveiser_name, 'adveiser_TITLE' => $get_data[0]->discussion_title, 'discussions_ID' => $request->discussions_id, 'COMMENT_DESCRIPTION' => $request['formemailText'], 'VIEW_LINK'=> 'View Ticket' ); $subject = Helpers::parseTemplate($message_subject,$data_array_parse); $email_msg_dtls = Helpers::buildTemplate($email_msg_dtls,'user'); $emailContent_admin = Helpers::parseTemplate($email_msg_dtls,$data_array_parse); $data = array('from' => $from, 'to' => $to, 'cc' => $cc, 'cc' => $cc, 'bcc' => $bcc, 'subject' => $subject, 'message' => $emailContent_admin); Helpers::mail($data); } $discussions_id = DB::getPdo()->lastInsertId(); return redirect('admin-discussions/'.$request['discussions_id'].'/#comment'.$discussions_id); } catch(\Illuminate\Database\QueryException $e) { //return View::make('edit.create')->with('status',''.$siteName.' Site already exist!'); } } }
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Laravel create Dynamic Email Templates from Database.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.