vajexal / amp-mailer
SMTP mailer for amphp
0.1.1
2021-05-26 16:51 UTC
Requires
- php: ^7.4|^8.0
- ext-iconv: *
- ext-intl: *
- amphp/file: ^1.0
- amphp/log: ^1.1
- amphp/socket: ^1.1
- egulias/email-validator: ^3.0
- vajexal/amp-mime-type: ^0.1.0
Requires (Dev)
- ext-json: *
- amphp/http-client: ^4.5
- amphp/php-cs-fixer-config: dev-master
- amphp/phpunit-util: ^1.4
- amphp/process: ^1.1
- sebastian/diff: ^4.0
This package is auto-updated.
Last update: 2025-03-27 01:52:19 UTC
README
Sending mail using SMTP and amphp
Installation
composer require vajexal/amp-mailer
Usage
<?php declare(strict_types=1); use Amp\Loop; use Vajexal\AmpMailer\Mail; use Vajexal\AmpMailer\MailerBuilder; require_once 'vendor/autoload.php'; Loop::run(function () { $mailer = (new MailerBuilder) ->host('...') ->port(2525) ->username('...') ->password('...') ->build(); $mail = (new Mail) ->from('from@example.com') ->to('to@example.com') ->subject('Test') ->text('Test'); yield $mailer->send($mail); });
More complex mail
use Vajexal\AmpMailer\Mail; $mail = (new Mail) ->from('from@example.com', 'from') // email and username ->replyTo('reply1@example.com', 'reply1') ->replyTo('reply2@example.com') ->to('to1@example.com', 'to1') ->to('to2@example.com') ->cc('cc1@example.com', 'cc1') ->cc('cc2@example.com') ->bcc('bcc1@example.com', 'bcc1') ->bcc('bcc2@example.com') ->subject('Test') ->text('Test') ->html('<b>Test</b>');
Attaching files
use Vajexal\AmpMailer\Attachment; use Vajexal\AmpMailer\Mail; $mail = (new Mail) ->attach(yield Attachment::fromPath('doc.pdf'));
Embedding files
use Vajexal\AmpMailer\Attachment; use Vajexal\AmpMailer\Mail; $mail = new Mail; $mail->html('<img src="' . $mail->embed(yield Attachment::fromPath('image.png')) . '" alt="Embedding example">');
Sending few emails
use Vajexal\AmpMailer\Mail; $mails = \array_map( fn ($name) => (new Mail) ->from('from@example.com') ->to(\sprintf('%s@example.com', \mb_strtolower($name))) ->subject('Hello') ->text(\sprintf('Hello %s', $name)), ['Bar', 'Baz'] ); yield $mailer->sendMany($mails);