From cce2055c03cbe5152fcc2b29a7d17c86f5706c9b Mon Sep 17 00:00:00 2001 From: zabous Date: Sat, 5 Oct 2024 00:48:10 +0200 Subject: [PATCH] SendmailMailer: the use of -f option in the mail command can be disabled (#98) --- src/Mail/SendmailMailer.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Mail/SendmailMailer.php b/src/Mail/SendmailMailer.php index 534e572..8bbe6c6 100644 --- a/src/Mail/SendmailMailer.php +++ b/src/Mail/SendmailMailer.php @@ -19,6 +19,7 @@ class SendmailMailer implements Mailer { public string $commandArgs = ''; private ?Signer $signer = null; + private bool $envelopeSender = true; public function setSigner(Signer $signer): static @@ -28,6 +29,16 @@ public function setSigner(Signer $signer): static } + /** + * Sets whether to use the envelope sender (-f option) in the mail command. + */ + public function setEnvelopeSender(bool $state = true): static + { + $this->envelopeSender = $state; + return $this; + } + + /** * Sends email. * @throws SendException @@ -48,7 +59,7 @@ public function send(Message $mail): void $parts = explode(Message::EOL . Message::EOL, $data, 2); $cmd = $this->commandArgs; - if ($from = $mail->getFrom()) { + if ($this->envelopeSender && ($from = $mail->getFrom())) { $cmd .= ' -f' . key($from); }