PHP code example of twindots / email-service

1. Go to this page and download the library: Download twindots/email-service 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/ */

    

twindots / email-service example snippets


   use EmailShortCodes; 

   public function compileCodes( EmailShortCodes $shortcodes )
   { 
      // Or create a new instance
      // $shortcodes = new EmailShortCodes();

      $compiled = $shortcodes->objects([
                  'user' => $user,
               ])
               ->withUser()
               ->body( request('body') )
               ->compile(); 
   }

   use EmailService; 

   public function sendEmail( EmailService $emailService )
   { 
      // Or create a new instance
      // $emailService = new EmailService();

      $result = $emailService->email(['[email protected]', '[email protected]'])
                  ->subject( $subject )
                  ->body( $compiled ) // Send the compiled body or any html
                  ->attach([
                     'file-1.png' => 'path/to/file-1.png',
                     'file-2.pdf' => 'path/to/file-2.png'
                  ])
                  ->send();
   }

    'group_name' => [
      'short_code_1' => [...],
      'short_code_2' => [...],
    ]   
 

   'user_first_name' => [        // shortcode unique name
      'title' => 'First name',   // shortcode friendly name
      'type' => 'variable',      // type is variable 
      'object' => 'user',        // object can be any class, ex: $user
      'param' => 'first_name'    // parameter, ex first_name: $user->first_name
   ], 
 

   'user_full_name' => [        // shortcode unique name
      'title' => 'Full name',   // shortcode friendly name
      'type' => 'function',     // type is function 
      'object' => 'user',       // object can be any class, ex: $user
      'param' => 'getFullName'  // parameter, ex: getFullName: $user->getFullName()
   ], 
 

   'user_image' => [                      // shortcode unique name
      'title' => 'User image',            // shortcode friendly name
      'type' => 'view',                   // type is view 
      'object' => 'users.profile-image',  // object is the view path
   ], 
 
bash
$ php artisan vendor:publish --provider="TwinDots\EmailService\EmailServiceProvider"