• Developer guides

Sending emails

The Includable platform also contains the ability to easily send emails through the EmailComposer class.

Quick example

$email = new EmailComposer();

$email->setFrom($this->user); // User object, optional
$email->setTo($u); // User object

$email->setSubject('A nice subject line');
$email->setContent('Some <b>HTML</b> Here');


Adding attachments

For adding attachments, there is the method EmailComposer::addAttachment(), which takes an instance of the Attachment class:


use \Services\Email\Attachment;

$email = new EmailComposer();
$email->setTo('Demo Person', 'demo@example.com');
$email->setSubject('Demo with attachment!');
$email->setContent('There is an attachment attached to this email. Have a look!');

// Add from local file
$attachment1 = Attachment::fromFile('/path/to/file.txt');

// Or add from string
$attachment2 = Attachment::fromString('Hi! I am a text file', 'simple-text-file.txt');

$email->send(); // Don't forget this!