1. Go to this page and download the library: Download webiny/mailer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webiny / mailer example snippets
class MyClass
{
use \Webiny\Component\Mailer\Bridge\MailerTrait;
function sendEmail() {
// get the Mailer instance
$mailer = $this->mailer('Default');
// let's build our message
$msg = $mailer->getMessage();
$msg->setSubject('Hello email')
->setBody('This is my test email body')
->setTo(new Email('[email protected]', 'Jack'));
// send it
$mailer->send($msg);
}
}
class MyClass
{
use \Webiny\Component\Mailer\Bridge\MailerTrait;
function sendEmail() {
// get the Mailer instance
$mailer = $this->mailer('Default');
// let's build our message
$msg = $mailer->getMessage();
$msg->setSubject('Hello email')
->setBody('Hi {name},
This is your new password: <strong>{password}</strong>.')
->setTo([
new Email('[email protected]'),
new Email('[email protected]')
]);
// before sending, let's define the decorator replacements
$replacements = [
'[email protected]' => [
'name' => 'Jack',
'password' => 'seCre!'
],
'[email protected]' => [
'name' => 'Sara',
'password' => 'Log!n'
]
];
$mailer->setDecorators($replacements);
// send it
$mailer->send($msg);
}
}