Email sending — SMTP, API transports, attachments
Email builder and sender. SMTP transport, Resend API transport, attachment support, HTML + plain-text multipart, and a fluent interface.
composer require sugarcraft/sugar-post
use SugarCraft\Post\{Email, SmtpTransport, Attachment};
$email = (new Email())
->from('noreply@example.com')
->to('user@example.com')
->subject('Deployment complete')
->text('Your app was deployed successfully.')
->html('<p>Your app was deployed <strong>successfully</strong>.</p>')
->attach(Attachment::fromPath('/tmp/build.zip', 'build.zip'));
$transport = new SmtpTransport('smtp.example.com', 587);
$transport->send($email);
| Class | Method | Description |
|---|---|---|
| new() | Create email | |
| from(addr), to(addr), subject(text) | Set email fields | |
| text(body), html(body) | Set body content | |
| attach(attachment) | Add attachment | |
| SmtpTransport | new(host, port) | Create SMTP transport |
| SmtpTransport | send(email) | Send email |
| Attachment | fromPath(path, name) | Create from file |
VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.