wyzen-packages / mailer-factory
Simple mailer factory
v3.0.0
2023-12-04 16:32 UTC
Requires
- php: >=8.2
- ext-mbstring: *
- symfony/mailer: ^6.4
- symfony/mailjet-mailer: ^6.4
- wyzen-packages/helper: ^1.6
Requires (Dev)
- phpunit/php-code-coverage: ^10.1
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.7
- symfony/dotenv: ^7.0
- symfony/var-dumper: ^7.0
README
Mailer factory
Changelog
- 3.0.0 : upgrade to symfony/mailjet-mailer >= 6.4. !!! changement de port de 465 à 587 par défaut
- Ajout de la prise en compte de MAILERFACTORY_PORT pour remettre le port à 465
- 2.1.0 : Add attachFromContent & embedFromContent methods
- 2.0.0 : php 8.2 mini
- 1.0.5 : Add 'name' => 'name@email.com' format
- 1.0.4 : Fix bugs
Tests
- Require : php 8.2 minimum
- use docker/composer.sh to use the correct release of php.
Import
composer require wyzen-packages/mailer-factory
Usage
Env variables
Common
MAILERFACTORY_FROM="Support<support@email.com>"
With DSN
MAILERFACTORY_DSN=smtp://user:pass@host:port?verify_peer=1
- verify_peer:
- 1 (default) => TLS
- 0 => NO TLS
With explicit var
MAILERFACTORY_PROVIDER=smtp | mailjet
MAILERFACTORY_HOST=host
MAILERFACTORY_TLS=true
MAILERFACTORY_PORT=1025
MAILERFACTORY_USER=user | api_public_key
MAILERFACTORY_PASSWORD=password | api_private_key
emails Format without duplicate mail
All mails are uniq
$to = [
'vde<vde@email.com>',
'user1@email.com, user2@email.com ; user3<user3@email.com>',
'other@email.com',
'duplicate<other@email.com>',
'user5 name' => 'user5@email.com',
];
// OR
$to = 'user1@email.com, user2@email.com ; user3<user3@email.com>';
// Transform emails to array of Address
$tb_emails = $mailer::fixEmails($to);
Send Mail
$mailer = MailerFactory::getMailer($this->smtp);
$to = 'user1@email.com, user2@email.com ; user3<user3@email.com>';
$cc = [
'user1@email.com, user2@email.com ; user3<user3@email.com>',
'user4<user4@email.com>',
]
$mailer->setTo($to);
$mailer->setCc($to);
// $mailer->setBcc($to);
$mailer->setReplyTo('REPLY<reply@email.com>');
$mailer->setSubject('Subject message');
$mailer->setText('Only text format');
$mailer->setHtml('<h1>HTML format mail</h1>');
try{
$mailer->sendMessage();
}
catch (TransportExceptionInterface $ex){
}
Send Mail with attach
$mailer = MailerFactory::getMailer($this->smtp);
$to = 'user1@email.com';
$mailer->setTo($to);
$mailer->setReplyTo('REPLY<reply@email.com>');
$mailer->attach(__DIR__ . '/../images/approved.png', 'Image Approved');
$mailer->setSubject('Subject message');
$mailer->setText('Only text format');
$mailer->setHtml('<h1>HTML format mail</h1>');
try{
$mailer->sendMessage();
}
catch (TransportExceptionInterface $ex){
}
Send Mail with embed image
$mailer = MailerFactory::getMailer($this->smtp);
$to = 'user1@email.com';
$mailer->setTo($to);
$mailer->setReplyTo('REPLY<reply@email.com>');
$mailer->embedImage(__DIR__ . '/../images/suricate.jpg', 'embedimage');
$mailer->setSubject('Subject message');
$mailer->setText('Only text format');
$mailer->setHtml('<h1>HTML format mail</h1><img src="cid:embedimage">');
try{
$mailer->sendMessage();
}
catch (TransportExceptionInterface $ex){
}