Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.86% |
13 / 14 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
Smtp | |
92.86% |
13 / 14 |
|
66.67% |
2 / 3 |
9.03 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
create | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
6 | |||
send | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Mail\Transport; |
15 | |
16 | use Pop\Mail\Message; |
17 | use Pop\Mail\Transport\Smtp\Stream\BufferInterface; |
18 | |
19 | /** |
20 | * SMTP transport class |
21 | * |
22 | * @category Pop |
23 | * @package Pop\Mail |
24 | * @author Nick Sagona, III <dev@nolainteractive.com> |
25 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
26 | * @license http://www.popphp.org/license New BSD License |
27 | * @version 4.0.0 |
28 | */ |
29 | class Smtp extends Smtp\EsmtpTransport implements TransportInterface |
30 | { |
31 | |
32 | /** |
33 | * Create a new SMTP transport |
34 | * |
35 | * @param string $host |
36 | * @param int $port |
37 | * @param ?string $security |
38 | * @param ?BufferInterface $buffer |
39 | * @param ?array $handlers |
40 | */ |
41 | public function __construct( |
42 | string $host = 'localhost', int $port = 25, ?string $security = null, ?BufferInterface $buffer = null, ?array $handlers = null |
43 | ) |
44 | { |
45 | parent::__construct($buffer, $handlers); |
46 | |
47 | $this->setHost($host); |
48 | $this->setPort($port); |
49 | if ($security !== null) { |
50 | $this->setEncryption($security); |
51 | } |
52 | } |
53 | |
54 | |
55 | /** |
56 | * Create the SMTP transport |
57 | * |
58 | * @param array $options |
59 | * @throws Exception |
60 | * @return Smtp |
61 | */ |
62 | public static function create(array $options): Smtp |
63 | { |
64 | if (empty($options['host']) || empty($options['port']) || empty($options['username']) || empty($options['password'])) { |
65 | throw new Exception('Error: The required credentials were not provided.'); |
66 | } |
67 | |
68 | $smtp = new Smtp($options['host'], $options['port']); |
69 | $smtp->setUsername($options['username']) |
70 | ->setPassword($options['password']); |
71 | |
72 | if (isset($options['encryption'])) { |
73 | $smtp->setEncryption($options['encryption']); |
74 | } |
75 | |
76 | return $smtp; |
77 | } |
78 | |
79 | /** |
80 | * Send the message |
81 | * |
82 | * @param Message $message |
83 | * @return int |
84 | */ |
85 | public function send(Message $message): int |
86 | { |
87 | return parent::send($message); |
88 | } |
89 | |
90 | } |