Reference

Guide

$kirby->email()

Returns the Email singleton

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

Parameters

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

Return type

Kirby\Email\PHPMailer

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

from with name

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

Source code

kirby/src/Cms/App.php#L538