CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Namespace Mailer

Namespaces

  • Cake\Mailer\Exception
  • Cake\Mailer\Transport

Classes

  • AbstractTransport

    Abstract transport for sending email

  • Mailer

    Mailer base class.

    Mailer classes let you encapsulate related Email logic into a reusable and testable class.

    Defining Messages

    Mailers make it easy for you to define methods that handle email formatting logic. For example:

    class UserMailer extends Mailer
    {
        public function resetPassword($user)
        {
            $this
                ->setSubject('Reset Password')
                ->setTo($user->email)
                ->set(['token' => $user->token]);
        }
    }

    Is a trivial example but shows how a mailer could be declared.

    Sending Messages

    After you have defined some messages you will want to send them:

    $mailer = new UserMailer();
    $mailer->send('resetPassword', $user);

    Event Listener

    Mailers can also subscribe to application event allowing you to decouple email delivery from your application code. By re-declaring the implementedEvents() method you can define event handlers that can convert events into email. For example, if your application had a user registration event:

    public function implementedEvents(): array
    {
        return [
            'Model.afterSave' => 'onRegistration',
        ];
    }
    
    public function onRegistration(EventInterface $event, EntityInterface $entity, ArrayObject $options)
    {
        if ($entity->isNew()) {
             $this->send('welcome', [$entity]);
        }
    }

    The onRegistration method converts the application event into a mailer method. Our mailer could either be registered in the application bootstrap, or in the Table class' initialize() hook.

  • Message

    Email message class.

    This class is used for sending Internet Message Format based on the standard outlined in https://www.rfc-editor.org/rfc/rfc2822.txt

  • Renderer

    Class for rendering email message.

  • TransportFactory

    Factory class for generating email transport instances.

  • TransportRegistry

    An object registry for mailer transports.

Traits

  • MailerAwareTrait

    Provides functionality for loading mailer classes onto properties of the host object.

    Example users of this trait are Cake\Controller\Controller and Cake\Console\Command.

OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs