Skip to content

Kirby 3.5.7.1

$kirby->email()

Returns the Email singleton

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

Parameters

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

Return type

Kirby\Email\PHPMailer

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

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

from with user object

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

'from'     => $from,
Since 3.3.2

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',
Since 3.3.2

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')
]);
Since 3.3.2

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']
],