Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Sendmail | |
100.00% |
12 / 12 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| setParams | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getParams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| send | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <dev@noladev.com> |
| 8 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Mail\Transport; |
| 16 | |
| 17 | use Pop\Mail\Message; |
| 18 | |
| 19 | /** |
| 20 | * Sendmail transport class |
| 21 | * |
| 22 | * @category Pop |
| 23 | * @package Pop\Mail |
| 24 | * @author Nick Sagona, III <dev@noladev.com> |
| 25 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 26 | * @license https://www.popphp.org/license New BSD License |
| 27 | * @version 5.0.0 |
| 28 | */ |
| 29 | class Sendmail extends AbstractTransport |
| 30 | { |
| 31 | |
| 32 | /** |
| 33 | * Sendmail params |
| 34 | * @var ?string |
| 35 | */ |
| 36 | protected ?string $params = null; |
| 37 | |
| 38 | /** |
| 39 | * Constructor |
| 40 | * |
| 41 | * Instantiate the Sendmail transport object |
| 42 | * |
| 43 | * @param ?string $params |
| 44 | */ |
| 45 | public function __construct(?string $params = null) |
| 46 | { |
| 47 | if ($params !== null) { |
| 48 | $this->setParams($params); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Set the params |
| 54 | * |
| 55 | * @param string $params |
| 56 | * @return Sendmail |
| 57 | */ |
| 58 | public function setParams(string $params): Sendmail |
| 59 | { |
| 60 | $this->params = $params; |
| 61 | return $this; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get the params |
| 66 | * |
| 67 | * @return ?string |
| 68 | */ |
| 69 | public function getParams(): ?string |
| 70 | { |
| 71 | return $this->params; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Send the message |
| 76 | * |
| 77 | * Body must be computed (and, when the message has parts, the boundary |
| 78 | * triggered) BEFORE the headers are stringified: getBodyContent() -> |
| 79 | * Part::renderParts() is what lazily synthesizes the Content-Type: |
| 80 | * multipart/...; boundary=... header, and Message::getBoundary() is what |
| 81 | * emits MIME-Version as a side effect. Computing $headers first (the |
| 82 | * prior ordering) would stringify the header set before those side |
| 83 | * effects fire, silently dropping Content-Type/MIME-Version from every |
| 84 | * multipart message sent through this transport. See Message::render() |
| 85 | * for the same pattern. |
| 86 | * |
| 87 | * @param Message $message |
| 88 | * @return bool |
| 89 | */ |
| 90 | public function send(Message $message): bool |
| 91 | { |
| 92 | if ($message->hasParts()) { |
| 93 | $message->getBoundary(); |
| 94 | } |
| 95 | |
| 96 | $body = $message->getBodyContent(); |
| 97 | $headers = $message->getHeadersAsString(['Subject', 'To']); |
| 98 | |
| 99 | if ($this->params !== null) { |
| 100 | return mail($message->getHeaderValue('To'), $message->getSubject(), $body, $headers, $this->params); |
| 101 | } else { |
| 102 | return mail($message->getHeaderValue('To'), $message->getSubject(), $body, $headers); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | } |