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 3.0.0 version of this library provides is fully compatible with the latest Pepipost v5.1 API.
For any update of this library check Releases.
- Installation
- Quick Start
- Usage of library in Project
- Sample Example
- Announcements
- Roadmap
- About
- License
A free account on Pepipost. If you don't have a one, click here to signup.
laravel new testproject
"require": {
"pepipost/pepipost-laravel-driver": "~3.0.0"
},
$ composer require pepipost/pepipost-laravel-driver
-
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', ],
-
Add following in .env file
MAIL_MAILER=pepipost # Needed to send through pepipipost api PEPIPOST_API_KEY='YOUR_PEPIPOST_API_KEY'
-
Add following in config/mail.php
'mailers' => [ 'pepipost' => [ 'transport' => 'pepipost', ], ],
-
Define Controller
php artisan make:controller TestController
-
Update the controller Include following function sendMail in TestController:
<?php 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(); } } }
-
create file in resources/views/mailtemplates/test.blade.php And include your email content
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="utf-8" /> </head> <body> <h2>Test Email</h2> <p>{{ $test_message }}</p> </body> </html>
-
Create a new route in routes/web.php
Route::get('/send/email', [TestController::class, 'sendMail'])->name('sendEmail');
-
Create a mailable template
php artisan make:mail TestEmail
This command will create a new file under app/Mail/TestEmail.php
-
Update your mailable template Update the mailable to the following code:
<?php 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'] ]); } }
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.
IF want to pass others parameters of Pepipost SendEmail, you have to update the mailable template. Add parameters as per your requirement. You can use multiple to's,cc's,bcc's with this method. Please refer the official Netcore api doc for more details on adavanced parameters.
This will be under app/Mail/TestEmail.php that we created.
<?php
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 required for this example
// ->cc('[email protected]', 'username')
->subject("Demo email from laravel")
# Store attachment in the "storage" path
->attach(storage_path('Discussions.pdf'))
->pepipost(
[
# Optional. For no options provide an empty array
"personalizations" => [
[
// This will override the recipient specified in the mailer method "to"
"to" => [
[
"email" => "[email protected]",
"name" => "John Doe"
],
[
"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
]
);
}
}
v3.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]
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.
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.