SendMailWrapper::send()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 4
b 0
f 0
nc 4
nop 1
dl 0
loc 19
ccs 0
cts 9
cp 0
crap 12
rs 10
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