fgiardina/mailer

Laravel email sender

v1.2.53 2020-09-01 15:44 UTC

This package is auto-updated.

Last update: 2025-03-01 00:19:53 UTC


README

Software License Travis Total Downloads

Installation

composer require fgiardina/mailer

If you are using Laravel 5.5+, there is no need to manually register the service provider. However, if you are using an earlier version of Laravel, register the MailerServiceProvider in your app configuration file:

'providers' => [
    // Other service providers...

    Fgiardina\Mailer\MailerServiceProvider::class,
],

Publish

php artisan vendor:publish --provider="Fgiardina\Mailer\MailerServiceProvider"

Configure email settings

.env file:

  MAIL_DRIVER=smtp
  MAIL_HOST=smtp.mailtrap.io
  MAIL_PORT=2525
  MAIL_USERNAME=xxxxxxxxxxxx
  MAIL_PASSWORD=xxxxxxxxxxxx
  MAIL_ENCRYPTION=null
  MAIL_FROM_ADDRESS=example@mail.com
  MAIL_FROM_NAME="example"

  MAILER_VIEWS_FOLDER=vendor.mailer #change custom path
  MAILER_SEND_ROUTE="/mailer/sendemail" #change custom route
  MAILER_TEST_ROUTE="/mailer/testemail" #change custom route
  MAILER_TEST_MAIL_FORM_ENABLE=true #false: disabled public access test from {MAILER_TEST_ROUTE}

Usage

  • Web form
http://YOUR-DOMAIN/mailer/testemail
  • Terminal or Postman client
curl -X POST \
  http://YOUR-DOMAIN/mailer/sendemail \
  -H 'Content-Type: application/json' \
  -d '{
    "to_name": "John Doe",
    "to_email": "john@doe.com",
    "to_bcc_email": "john2@doe.com",
    "subject": "Email title",
    "header": "Header Info",
    "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
    "footer": "Footer Info",
    "template": "format"
}'
  • URL default: http://YOUR-DOMAIN/mailer/sendemail
  • URL custom: http://YOUR-DOMAIN/{MAILER_SEND_ROUTE} replace by value in .env file

Required: to_email, subject, body, template

Templates

HTML template without format

  "template": "basic"

HTML formatted template

  "template": "format"

Custom templates:

Path: MAILER_VIEWS_FOLDER

  "template": "mycustomtemplate"

mycustomtemplate.blade.php

// ...HTML
<body>

    @isset($data->header)
        <header>{{ $data->header }}</header>  
    @endisset

    <div>{{ $data->body }}</div>

    @isset($data->footer)
        <footer>{{ $data->footer }}</footer>  
    @endisset

</body>  
// ...HTML
Attention!
Never use {!! !!} in template. This can cause security problems

License

The MIT License (MIT). Please see License File for more information.