• Developer guides

Sending emails

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

Quick example

<?php
$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');

$email->send();

Adding attachments

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

<?php

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');
$email->addAttachment($attachment1);

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


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