PHP code example of blackfinwebware / laravel-mail-merge

1. Go to this page and download the library: Download blackfinwebware/laravel-mail-merge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blackfinwebware / laravel-mail-merge example snippets


return [
    /*
    |--------------------------------------------------------------------------
    | Namespace
    |--------------------------------------------------------------------------
    | To integrate the mailmerge package, there will be some classes you'll need to create in your app to identify
    | Groups and Macro Sets(see below). This parameter provides you with the ability to customize your root namespace
    | for these classes. Note that if you change it here, you'll need to change it wherever it appears in this file, 
    | and remember to clear your config cache after making changes in this file.
    */

    'namespace' => 'App\\Mail\\Merge',

    /*
    |--------------------------------------------------------------------------
    | Tables
    |--------------------------------------------------------------------------
    | Tables needed to support the package. At the least we need the EmailTemplates table
    | which corresponds with our EmailTemplate model.
    */

    'tables' => ['email_templates' => 'mailmerge_email_templates'],

    /*
    |--------------------------------------------------------------------------
    | Groups
    |--------------------------------------------------------------------------
    | Groups here are those that can be identified as intended targets of an email merge. Each group
    | must be identified with a Merge Distribution class. This serves two functions: 1) it provides a way to get a
    | recipient list and 2) a way to reverse that and find the instance of our nexus object related to each
    | recipient. This nexus object is what will provide the values for the macro expansions - typically this is
    | a specific model in your app that is related directly or indirectly to a user, but is traversable from the
    | user so that macro values can be discovered and expanded quickly for each user.
    */

    'groups' => ['GroupName' => App\Mail\Merge\Distribution\GroupNameMergeDistribution::class],

    /*
    |--------------------------------------------------------------------------
    | Macro Sets
    |--------------------------------------------------------------------------
    | Macros are grouped in sets by like function. They may be related to a specific model or process which we refer to
    | as a nexus here. The General macros are applied to all outbound emails. Those defined within a Macro Expansion
    | Guide are application specific where the Guide provides a map to expand each macro appropriately for the
    | recipient.
    */

    'macro_sets' => ['general' => ['app_name' => env('APP_NAME', 'MyApp'),
                                   'primary_contact_email' => '[email protected]'],
                     'macro_set_name' => App\Mail\Merge\Macro\ModelNameMacroExpansionGuide::class],

    /*
    |--------------------------------------------------------------------------
    | Queue outbound email
    |--------------------------------------------------------------------------
    | Queue mail when sending -- this allows the actual send to be handled asynchronously and is much preferred.
    | You must have queueing configured in your system.
    */

    'use_queues' => true,

    /*
    |--------------------------------------------------------------------------
    | Debug
    |--------------------------------------------------------------------------
    | Used within the package to provide more debugging info to the log, and other items. If true, the primary
    | admin email will get bcc'd on outbound emails when in production and sandbox is false.
    */

    'debug' => true,

    /*
    |--------------------------------------------------------------------------
    | Sandbox Email
    |--------------------------------------------------------------------------
    | If true, when your app is not in production OR you have debug set to true, it will send all the generated
    | messages to the primary_admin_email, and NOT to the intended recipient(s).
    */

    'sandbox_email' => true,
    'primary_admin_email' => env('MAIL_FROM_ADDRESS', '[email protected]'),

    /*
    |--------------------------------------------------------------------------
    | UI App Layout
    |--------------------------------------------------------------------------
    | App layout template. This is initially populated with a minimalist package layout for demo / test of the
    | provided package UI, using Bootstrap 4.6. Hint: to use your own layout, you may just need to remove the
    | 'mailmerge::'.
    */

    'blade_layout' => 'mailmerge::layouts.app',

    /*
    |--------------------------------------------------------------------------
    | Route prefix
    |--------------------------------------------------------------------------
    | If you want package provided routes to have a prefix so they are set apart from you main application, you
    | can leave this at the default or modify as appropriate.
    */

    'route_prefix' => 'mailmerge',

    /*
    |--------------------------------------------------------------------------
    | Route middleware groups
    |--------------------------------------------------------------------------
    | Wrap the routes in the web middleware so that they run through the normal Laravel processes. You may want to use
    | the 'auth' middleware group as well if you are protecting your routes with a login layer.
    */

    'middleware' => ['web'],

    /*
    |--------------------------------------------------------------------------
    | Advanced
    |--------------------------------------------------------------------------
    | If you have enough differentiation between your notification and broadcast emails,
    | and/or have different user roles that are maintaining these, you can specify their
    | classnames here. Note that they must extend BlackfinWebware\LaravelMailMerge\Models\EmailTemplate
    |
    | 'notification_email_class' => App\Models\NotificationEmailTemplate::class,
    | 'broadcast_email_class' => App\Models\BroadcastEmailTemplate::class,
    */
];

'macro_sets' = ['general' => ['app_name' => env('APP_NAME', 'MyApp'),
                         'primary_contact_email' => '[email protected]'],
                         'password_reset_request' => App\Mail\Merge\Macro\PasswordResetRequestMacroExpansionGuide::class];

public function expansions(){
        $password_reset_link = url("/password_reset_request/reset/" . $this->objects['password_reset_request']->reset_access_token);

        return ['password_reset_request_email' => $this->objects['password_reset_request']->email,
                'member_username' => $this->objects['password_reset_request']->user->username,
                'password_reset_link' => $password_reset_link];
    }

Mailmerge::composeAndSend('password_reset_request', $password_reset_request);
bash
php artisan vendor:publish --tag="laravel-mail-merge-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="laravel-mail-merge-views"
bash
php artisan make:mergeDistribution MyGroupName
bash
php artisan make:macroExpansion MyClassName