PHP code example of pepipost / pepipost-laravel-driver

1. Go to this page and download the library: Download pepipost/pepipost-laravel-driver 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/ */

    

pepipost / pepipost-laravel-driver example snippets


    'pepipost' => [
        'api_key' => env('PEPIPOST_API_KEY'),
    ],
     

      'mailers' => [
        'pepipost' => [
            'transport' => 'pepipost',
        ],
    ],
      

      
        namespace App\Http\Controllers;
        use Illuminate\Support\Facades\Mail;
        use App\Mail\TestEmail;
        
        use Illuminate\Http\Request;
        
        class TestController extends Controller
        {
        	function sendMail(){
        		try {
        			Mail::to('[email protected]')
        			->send(new TestEmail(['message' => 'Just a test message']));
        			return 'Email sent successfully';
        		}
        		catch (Exception $e) {
        			echo $e->getResponse();
        		}
        	}
        }
      

      Route::get('/send/email', [TestController::class, 'sendMail'])->name('sendEmail');
      

    
        namespace App\Mail;
        
        use Illuminate\Bus\Queueable;
        use Illuminate\Contracts\Queue\ShouldQueue;
        use Illuminate\Mail\Mailable;
        use Illuminate\Queue\SerializesModels;
        use Pepipost\PepipostLaravelDriver\Pepipost;
        
        class TestEmail extends Mailable
        {
          /**
           * Create a new message instance.
           *
           * @return void
           */
        
          use Pepipost;
        
          public $data;
          public function __construct($data)
          {
            $this->data = $data;
          }
        
          /**
           * Build the message.
           *
           * @return $this
           */
          public function build()
          {
            return $this
              ->view('mailtemplate.test')
              ->from('[email protected]')
              ->subject("Demo email from laravel")
              ->with([ 'test_message' => $this->data['message'] ]);
          }
        }
    



namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Pepipost\PepipostLaravelDriver\Pepipost;

class TestEmail extends Mailable
{
    /**
     * Create a new message instance.
     *
     * @return void
     */

    use Pepipost;

    public $data;
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this
            # To provide template provide empty array.
            ->view('mailtemplate.test')
            ->from('[email protected]')
            # Not                     "email" => "[email protected]",
                                "name" => "Emma Watson"
                            ],
                        ],
                        // This will override the above cc_recipient specified in the mailer method, if provided.
                        "cc" => [
                            [
                                "email" => "[email protected]",
                                "email" => "[email protected]",
                            ]
                        ],
                        // This will override the above bcc_recipient specified in the mailer method, if provided.
                        "bcc" => [
                            [
                                "email" => "[email protected]",
                                "email" => "[email protected]",
                            ]
                        ],
                        # X-Api header for to mail
                        "token_to" => "tracker_phone",
                        # X-Api header for cc mail
                        "token_cc" => "tracker_cc",
                        # X-Api header for bcc mail
                        "token_bcc" => "tracker_bcc"
                    ],
                    [
                        # Different parameters for second recipient
                        "to" => [
                            [
                                "email" => "[email protected]",
                                "name" => "Jenna Bane"
                            ]
                        ],
                        # X-Api header for to mail
                        "token_to" => "jenna_emp"
                    ]
                ],
                "settings" => [
                    "open_track" => true,
                    "click_track" => true,
                    "unsubscribe_track" => true,
                    "hepf" => false
                ],
                # For using pepipost templates instead of view templates
                "template_id" => 1234
            ]
        );
    }
}
bash
    php artisan make:controller TestController
    
bash
      php artisan make:mail TestEmail