summaryrefslogtreecommitdiff
path: root/src/Mail/Transport/LogTransport.php
blob: 6e351302a596f6deaa39e27a4f4719d3135fa41e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

namespace Engelsystem\Mail\Transport;

use Psr\Log\LoggerInterface;
use Swift_Mime_SimpleMessage as SimpleMessage;

class LogTransport extends Transport
{
    /** @var LoggerInterface */
    protected $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * Send the given Message.
     *
     * Recipient/sender data will be retrieved from the Message API.
     * The return value is the number of recipients
     *
     * @param SimpleMessage $message
     * @param string[]      $failedRecipients An array of failures by-reference
     *
     * @return int
     */
    public function send(
        SimpleMessage $message,
        &$failedRecipients = null
    ): int {
        $this->logger->debug(
            'Mail: Send mail "{title}" to "{recipients}":' . PHP_EOL . '{content}',
            [
                'title'      => $message->getSubject(),
                'recipients' => $this->getTo($message),
                'content'    => (string)$message->getHeaders() . PHP_EOL . PHP_EOL . $message->toString(),
            ]
        );

        return count($this->allRecipients($message));
    }
}