Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

Laravel create Dynamic Email Templates from Database

December 27, 2018 Pakainfo Technology, Laravel, Programming Leave a comment

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

Contents

  • Laravel create Dynamic Email Templates from Database
    • Creating Dynamic Email Template in Laravel
    • Read
    • Summary
    • Related posts

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 = "<div>";
    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 .= "</div>";

    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 <[email protected]>';
                        $cc = 'Company Name <[email protected]>';
                        $bcc = 'Company Name <[email protected]>';
                        $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'=> '<a href="' .$base_url.'discussions/'.$request->discussions_id .'/'.$get_data[0]->discussion_slug.'">View Ticket</a>'
                        );
                        $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','<strong>'.$siteName.' Site already exist!</strong>'); 
                }
        }
}   

Angular 6 CRUD Operations Application Tutorials

Read :

  • Technology
  • Google Adsense
  • Programming
Also Read This ๐Ÿ‘‰   PHP Send Beautiful HTML Email Templates

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.

Related posts:

  1. PHP Send Beautiful HTML Email Templates
  2. Laravel 5.7 Bootstrap Admin Panel Templates Integrate
  3. PHP Laravel 7 Send Email Example Tutorial
  4. Laravel dynamic breadcrumbs with links
Creating Dynamic Email Template in PHPdynamic email template in laraveldynamic email template in phpEmail the contents of a dynamic webpage generated by phpHow to create a dynamic HTML Email Templatehow to send dynamic emails in phphow to store email template in databasejdtsoftware laravel email templateslaravel 5 send email templatelaravel email template from databaseLaravel Email Templates from Databasephp html email template

Post navigation

Previous Post:Laravel JOIN Multiple Tables Eloquent Relationships
Next Post:Laravel User Role based Access control Authentication

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

Weโ€™re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (92) Education (61) Entertainment (130) fullform (86) Google Adsense (63) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1032) Mysqli (891) php (2127) Programming (2338) Python (98) Software (169) Software (88) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (145) Technology (2395) Tips and Tricks (121) Tools (210) Top10 (490) Trading (92) Trending (72) VueJs (250) Web Technology (106) webtools (192) wordpress (166) World (333)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

ยฉ 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites