examples/BatchEmailJob.php
public function perform(array $args = []): int
    {
        // Store our args
        $this->args = $args;
        unset($this->args['messages']);

        // Create a new transport
        $transport = new Swift_SmtpTransport(
            $args['smtp']['host'],
            $args['smtp']['port']
        );
        $transport->setUsername($args['smtp']['username']);
        $transport->setPassword($args['smtp']['password']);

        // Make a copy of all of our messages, and interate over each message
        $this->messages = $args['messages'];
        foreach ($messages as &$message) {
            // If shutdown is called, abort what we are doing.
            if ($shutdown) {
                break;
            }

            // Create a message
            $mailer = new Swift_Mailer($transport);
            $m = (new Swift_Message($message['subject']))
                ->setFrom([$message['from']['email'] => $message['from']['email']])
                ->setTo([$message['to']['email'] => $message['to']['name']])
                ->setBody($message['message']);
            
            // Send the message, and indicate if it was sent
            $message['sent'] = ($mailer->send($m) === 1);
        }

        return 0;
    }
public function perform(array $args = []): int
    {
        // Store our args
        $this->args = $args;
        unset($this->args['messages']);

        // Create a new transport
        $transport = new Swift_SmtpTransport(
            $args['smtp']['host'],
            $args['smtp']['port']
        );
        $transport->setUsername($args['smtp']['username']);
        $transport->setPassword($args['smtp']['password']);

        // Make a copy of all of our messages, and interate over each message
        $this->messages = $args['messages'];
        foreach ($messages as &$message) {
            // If shutdown is called, abort what we are doing.
            if ($shutdown) {
                break;
            }

            // Create a message
            $mailer = new Swift_Mailer($transport);
            $m = (new Swift_Message($message['subject']))
                ->setFrom([$message['from']['email'] => $message['from']['email']])
                ->setTo([$message['to']['email'] => $message['to']['name']])
                ->setBody($message['message']);
            
            // Send the message, and indicate if it was sent
            $message['sent'] = ($mailer->send($m) === 1);
        }

        return 0;
    }
Sends batches of emails in a loop.

`$args` is an array of details pushed into Redis. In this example `$args` has the following
structure
@param array $args = [
'smtp' => [
'host' => '127.0.0.1',
'port' => 25
'username' => 'smtp_username',
'password' => 'smtp_password'
],
// This is an array of messages, where each message is it's own array
'messages' => [
[
'subject' => 'Hello Doctor!',
'message' => 'What are you doing for Christmas?',
'from' => [
'email' => 'clara.oswald@tardis.io',
'name' => 'Clara Oswald
],
'to' => [
'email' => 'doctor@tardis.io',
'name' => 'Doctor'
]
],
[ ... ] // More messages
]
];
@return int