• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / mail / 24862033768

23 Apr 2026 10:27PM UTC coverage: 80.194% (+3.3%) from 76.863%
24862033768

push

github

dg
added CLAUDE.md

413 of 515 relevant lines covered (80.19%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.37
/src/Mail/SendmailMailer.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Nette\Mail;
9

10
use Nette;
11

12

13
/**
14
 * Sends emails via the PHP internal mail() function.
15
 */
16
class SendmailMailer implements Mailer
17
{
18
        public string $commandArgs = '';
19
        private ?Signer $signer = null;
20
        private bool $envelopeSender = true;
21

22

23
        public function setSigner(Signer $signer): static
1✔
24
        {
25
                $this->signer = $signer;
1✔
26
                return $this;
1✔
27
        }
28

29

30
        /**
31
         * Sets whether to use the envelope sender (-f option) in the mail command.
32
         */
33
        public function setEnvelopeSender(bool $state = true): static
34
        {
35
                $this->envelopeSender = $state;
×
36
                return $this;
×
37
        }
38

39

40
        /**
41
         * Sends email.
42
         * @throws SendException
43
         */
44
        public function send(Message $mail): void
1✔
45
        {
46
                if (!function_exists('mail')) {
1✔
47
                        throw new SendException('Unable to send email: mail() has been disabled.');
1✔
48
                }
49

50
                $data = $this->signer
1✔
51
                        ? $this->signer->generateSignedMessage($mail)
1✔
52
                        : $mail->generateMessage();
×
53
                [$headers, $body] = explode(Message::EOL . Message::EOL, $data, 2);
1✔
54

55
                // mail() adds 'To' and 'Subject' itself, remove them from the header block (after DKIM signing)
56
                $lines = preg_split('#\r\n(?![ \t])#', $headers);
1✔
57
                $lines = array_filter($lines, fn($line) => !preg_match('#^(?:To|Subject):#', $line));
1✔
58
                $headers = implode(Message::EOL, $lines);
1✔
59

60
                $cmd = $this->commandArgs;
1✔
61
                if ($this->envelopeSender && ($from = $mail->getFrom())) {
1✔
62
                        $cmd .= ' -f' . key($from);
1✔
63
                }
64

65
                $this->invokeMail(
1✔
66
                        (string) $mail->getEncodedHeader('To'),
1✔
67
                        (string) $mail->getEncodedHeader('Subject'),
1✔
68
                        $body,
69
                        $headers,
70
                        $cmd,
71
                );
72
        }
1✔
73

74

75
        /** @throws SendException */
76
        protected function invokeMail(string $to, string $subject, string $body, string $headers, string $cmd): void
77
        {
78
                $info = '';
×
79
                $res = Nette\Utils\Callback::invokeSafe('mail', [$to, $subject, $body, $headers, $cmd], function (string $message) use (&$info): void {
×
80
                        $info = ": $message";
81
                });
×
82
                if ($res === false) {
×
83
                        throw new SendException("Unable to send email$info.");
×
84
                }
85
        }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc