Skip to content

Kirby 3.6.6

$kirby->email()

Returns the Email singleton

$kirby->email(mixed $preset = [ ], array $props = [ ]): Kirby\Email\Email

Parameters

Name Type Default
$preset mixed [ ]
$props array [ ]

Return type

Kirby\Email\Email

Parent class

Kirby\Cms\App

Examples

Basic example

try {
  $kirby->email([
    'from' => 'welcome@supercompany.com',
    'replyTo' => 'no-reply@supercompany.com',
    'to' => 'someone@gmail.com',
    'cc' => 'anotherone@gmail.com',
    'bcc' => 'secret@gmail.com',
    'subject' => 'Welcome!',
    'body'=> 'It\'s great to have you with us',
  ]);
} catch (Exception $error) {
  echo $error;
}

from & replyTo

'from'    => 'no-reply@supercompany.com',
'replyTo' => 'jane@supercompany.com'

from with name

'from'     => 'no-reply@supercompany.com',
'fromName' => 'Jane Doe'

from with user object

$from = new \Kirby\Cms\User([
  'email' => 'jane@mail.com',
  'name' => 'Jane Doe',
]);

'from'     => $from,

replyTo with name

'replyTo'     => 'jane@supercompany.com',
'replyToName' => 'Jane Doe'

to , cc and bcc

Single recipient

'to'  => 'jane@example.com',
'cc'  => 'hanna@example.com',
'bcc' => 'simone@example.com',

Single recipient with name

'to' => ['jane@example.com', 'Super Company'],

Multiple recipients

'to' => [
    'jane@doe.com',
    'mark@otto.com'
],

Collection of users

$kirby->email([
  'to' => $kirby->users()->role('newbies'),
  'cc' => $kirby->users()->role('members')
]);

Multiple recipients with name

'to' => [
    ['jane@doe.com', 'Jane Doe'],
    ['mark@otto.com', 'Mark Otto']
],
'cc' => [
    ['jane@doe.com', 'Jane Doe'],
    ['mark@otto.com', 'Mark Otto']
],