Skip to content

pepipost/pepipost-laravel-driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pepipostlogo

Packagist Packagist Packagist Open Source Helpers Twitter Follow

Laravel Driver for Pepipost

A Mail Driver with support for Pepipost Send Email Web API, using the original Laravel API. This library extends the original Laravel classes, so it uses exactly the same methods.

To use this package required your Pepipost Api Key. Please make it Here.

We are trying to make our libraries Community Driven- which means we need your help in building the right things in proper order we would request you to help us by sharing comments, creating new issues or pull requests.

We welcome any sort of contribution to this library.

The latest 1.0.0 version of this library provides is fully compatible with the latest Pepipost v2.0 API.

For any update of this library check Releases.

Table of Content

Installation

Prerequisites

PHP >= 7.2.5

Composer v1.8

Laravel 7

Guzzle 6.3

A free account on Pepipost. If you don't have a one, click here to signup.

Usage

Configuring laravel project

Step 1 - Create New Laravel project

laravel new testproject

Step 2 - Add the package to your composer.json and run composer update.

"require": {
    "pepipost/pepipost-laravel-driver": "~1.0"
},

or install with composer

$ composer require pepipost/pepipost-laravel-driver

Step 3 - Configurations

  1. Add the pepipost service provider in config/app.php: (Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.)

    'providers' => [
        Pepipost\PepipostLaravelDriver\PepipostTransportServiceProvider::class
    ];
  2. Add pepipost api key, endpoint in config/services.php

        'pepipost' => [
            'api_key' => env('PEPIPOST_API_KEY'),
        ],
     endpoint config
    
     If you need to set custom endpoint, you can set any endpoint by using endpoint key.
     For example,calls to Pepipost Web API through a proxy,configure endpoint in config/services.php.
    
           
       'pepipost' => [
               'api_key' => env('PEPIPOST_API_KEY'),
               'endpoint' => 'https://api.pepipost.com/v5/mail/send',
           ],
    
  3. Add following in .env file

    MAIL_DRIVER=pepipost
    
    PEPIPOST_API_KEY='YOUR_PEPIPOST_API_KEY'

Step 4- Laravel Steps to create controller and view

  1. Define Controller

    php artisan make:controller TestController
    
  2. create file in resources/views/viewname/name.blade.php and include your email content

    include following function sendMail in TestController to send viewname.name as content of email and initialize $data to use it on view page

    function sendMail(){
    
    Mail::send('viewname.name',$data, function ($message) {
        $message
            ->to('[email protected]', 'foo_name')
            ->from('[email protected]', 'sender_name')
            ->subject('subject')
            ->cc('[email protected]','recipient_cc_name')
            ->bcc('[email protected]','recipient_bcc_name')
            ->replyTo('[email protected]','recipient_bcc')
            ->attach('/myfilename.pdf');
    });
    
    return 'Email sent successfully';
    }
  3. Create Route in routes/web.php

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

Step 5 - Testing

Host your laravel project and enter url- http://your_url.com/send/email in browser

This will send email and display Email sent successfully on browser.

Additional Usage

IF want to pass others parameters of Pepipost SendEmail API use embedData function and include below code as below Add parameters as per your requirement. Do not use multiple to's,cc's,bcc's with this method.

function sendMail(){

Mail::send('viewname.name',$data, function ($message) {
    $message
        ->to('[email protected]', 'foo_name')
        ->from('[email protected]', 'sender_name')
        ->subject('subject')
        ->cc('[email protected]','recipient_cc_name')
        ->bcc('[email protected]','recipient_bcc_name')
        ->replyTo('[email protected]','recipient_bcc')
        ->attach('/myfilename.pdf')
        ->embedData([
            'personalizations' => ['attributes'=>['ACCOUNT_BAL'=>'String','NAME'=>'NAME'],'x-apiheader'=>'x-apiheader_value','x-apiheader_cc'=>'x-apiheader_cc_value'],'settings' => ['bcc'=>'[email protected]','clicktrack'=>1,'footer'=>1,'opentrack'=>1,'unsubscribe'=>1 ],'tags'=>'tags_value','templateId'=>''
        ],'pepipostapi');
        
 return 'Email sent successfully';
}       

For multiple to's,cc's,bcc's pass recipient,recipient_cc,recipient_bcc as below, create personalizations as required

function sendMail(){

Mail::send('viewname.name',$data, function ($message) {
    $message
        ->from('[email protected]', 'sender_name')
        ->subject('subject')
        ->replyTo('reply_to'@example.com,'recipient_bcc')
        ->attach('/myfilename.pdf')
        ->embedData([
                    'personalizations' => [['recipient'=>'[email protected]','attributes'=>['ACCOUNT_BAL'=>'String','NAME'=>'name'],'recipient_cc'=>['[email protected]','[email protected]'],'recipient_bcc'=>['[email protected]','[email protected]'],'x-apiheader'=>'x-apiheader_value','x-apiheader_cc'=>'x-apiheader_cc_value'],['recipient'=>'[email protected]','attributes'=>['ACCOUNT_BAL'=>'String','NAME'=>'name'],'x-apiheader'=>'x-apiheader_value','x-apiheader_cc'=>'x-apiheader_cc_value']],'settings' => ['bcc'=>'[email protected]','clicktrack'=>1,'footer'=>1,'opentrack'=>1,'unsubscribe'=>1 ],'tags'=>'tags_value','templateId'=>''
                ],'pepipostapi');
        });
        
return 'Email sent successfully';
}

Announcements

v1.0.0 has been released! Please see the release notes for details.

All updates to this library are documented in our releases. For any queries, feel free to reach out us at [email protected]

Roadmap

If you are interested in the future direction of this project, please take a look at our open issues and pull requests. We would love to hear your feedback.

About

pepipost-laravel library is guided and supported by the Pepipost Developer Experience Team . This pepipost library is maintained and funded by Pepipost Ltd. The names and logos for pepipost gem are trademarks of Pepipost Ltd.

License

MIT

About

The Official Pepipost Laravel Driver Library

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages