SendMailWrapper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 18.18%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 10
c 4
b 0
f 0
dl 0
loc 34
ccs 2
cts 11
cp 0.1818
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 19 3
A schema() 0 3 1
1
<?php
2
3
namespace ByJG\Mail\Wrapper;
4
5
use ByJG\Mail\Envelope;
6
use ByJG\Mail\Exception\InvalidEMailException;
7
use ByJG\Mail\Exception\InvalidMessageFormatException;
8
9
/**
10
 * Class SendMailWrapper
11
 *
12
 * sendmail://localhost
13
 *
14
 * @package ByJG\Mail\Wrapper
15
 */
16
class SendMailWrapper extends PHPMailerWrapper
17
{
18
19 1
    public static function schema()
20
    {
21 1
        return ['sendmail'];
22
    }
23
24
    /**
25
     * @param \ByJG\Mail\Envelope $envelope
26
     * @return bool
27
     * @throws InvalidEMailException
28
     * @throws InvalidMessageFormatException
29
     * @throws \PHPMailer\PHPMailer\Exception
30
     */
31
    public function send(Envelope $envelope)
32
    {
33
        $this->validate($envelope);
34
35
        $mail = $this->prepareMailer($envelope);
36
37
        // Call the preSend to set all PHPMailer variables and get the correct header and body;
38
        $messageParts = $mail->getMessageEnvelopeParts();
39
40
        // Fix BCC header because PHPMailer does not send to us
41
        foreach ((array)$envelope->getBCC() as $bccEmail) {
42
            $messageParts['header'] .= 'Bcc: ' . $bccEmail . "\n";
43
        }
44
45
        foreach ($envelope->getTo() as $toEmail) {
46
            mail($toEmail, $envelope->getSubject(), $messageParts['body'], $messageParts['header']);
47
        }
48
49
        return true;
50
    }
51
}
52