1. Go to this page and download the library: Download baraja-core/emailer 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/ */
baraja-core / emailer example snippets
use Baraja\Emailer\Emailer;
use Baraja\Emailer\Message;
class OrderService
{
public function __construct(
private Emailer $emailer,
) {}
public function sendConfirmation(string $to): void
{
$message = new Message;
$message->setFrom('[email protected]');
$message->addTo($to);
$message->setSubject('Order Confirmation');
$message->setHtmlBody('<h1>Thank you for your order!</h1>');
$this->emailer->send($message);
}
}
$message = new Message;
$message->setPriority(Message::URGENT);
$message->setSubject('Critical Alert');
// ...
$this->emailer->send($message); // Sent immediately
use Baraja\Emailer\Email\BaseEmail;
use Baraja\Emailer\Message;
class WelcomeEmail extends BaseEmail
{
public function getName(): string
{
return 'Welcome Email';
}
public function getDescription(): ?string
{
return 'Sent to new users after registration';
}
public function getTemplate(string $locale): ?string
{
return __DIR__ . "/templates/welcome.{$locale}.latte";
}
public function getMessage(): Message
{
$message = parent::getMessage();
$message->setSubject('Welcome to Our Service');
return $message;
}
}
$message = new Message;
$message->setSendEarliestAt('tomorrow 9:00');
// or
$message->setSendEarliestAt(new \DateTimeImmutable('+2 hours'));
$this->emailer->send($message);
$this->emailer->sendMessageToAdministrators(
subject: 'Server Alert',
message: 'Disk space is running low!',
additionalEmails: ['[email protected]'],
);
use Baraja\Emailer\RecipientFixer\Fixer;
class MyFixer implements Fixer
{
public function fix(string $email): string
{
// Your correction logic
return $email;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.