Disco uses the swiftmailer library to handle email related tasks. The library will be installed when you install Disco using composer.

You must configure your email settings to use the email service.

Basic Examples #

try {


    // As basic as it gets
    Email::send('recepient@mailbox.com', 'The awesome subject line', 'The awesome body');

    // Force plaintext
    Email::plainText()->send('user@mail.com','So Plain','Because it lacks html');

    // Maybe you want to add attachments
    $attach = [
        '/home/user/documents/attach1.docx',
        '/home/user/documents/attach2.jpg'
    ];

    Email::send('user@mail.com', 'Your files', 'Hope your happy', $attach);


    // You can break this down
    // First get a new swift message pre-loaded with the to, subject, and body
    $swiftMessage = Email::getMessage(['user1@mail.com','user2@mail.com'],'Subject','Body');

    // Then add the attachments
    Email::addAttachments($swiftMessage, $attach);

    // Then perhaps perform some native \Swift_Message functions
    $swiftMessage->nativeFunction();

    // Now send out the message
    Email::sendMessage($swiftMessage);


    // Dont be scared you can use templates!
    $body = Template::build('email/baseTemplate');
    Email::send('bob@mail.com', 'Nice', $body);


} catch(Exception $e){
    // Unable to send
    // Handle error
}

Get/Set Configuration Options #

// Register a new account on the fly
Email::setSetting('johns-email',[
        'EMAIL' => 'john@mail.com',
        'PASSWORD' => 'johnspassword',
        'ALIAS' => 'John Smith'
    ]);


// Define the account to send emails through
Email::setCurrentAccount('johns-email');


// Register a new server on the fly
Email::setSetting('magic-server',[
        'HOST' => 'mail.com',
        'PORT' => 447,
        'PROTOCOL' => 'tls'
    ]);

// Define the server to send emails through
Email::setCurrentServer('magic-server');


// Get the current account used to send emails
$account = Email::getCurrentAccount();

// Get the current server used to send emails
$server = Email::getCurrentServer();

// Get any setting
$setting = Email::getSetting('DEFAULT_ACCOUNT');

Send In Parallel #

Use the delay function to send emails in parallel (creating no lag, but also taking away your ability to know if the email was sent) by providing a number of seconds to wait and then send the email. Pass `0` to send it immediately.

Email::delay(0)->send('bob@mail.com','That was fast!','Yep we used delay');