Skip to content

[Mailer] Support getting sendmail path from php.ini #51749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[Mailer] Support getting sendmail path from php.ini
Not all environments have sendmail installed in `/usr/sbin`.
Let’s ask for the path using `ini_get`.
See also symfony/swiftmailer-bundle#302
  • Loading branch information
jtojnar committed Sep 26, 2023
commit 7788dc6ee2d23e85ecd73ffec277cd0736b30f4e
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,24 @@ protected function tearDown(): void

public function testToString()
{
$previousSendmailPath = \ini_set('sendmail_path', '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should happen in setUp().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we should use $this->iniSet()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not relevant to all tests, though.

$t = new SendmailTransport();
$this->assertEquals('smtp://sendmail', (string) $t);
}

public function testToStringNonSmtp()
{
$previousSendmailPath = \ini_set('sendmail_path', '');
$t = new SendmailTransport('/usr/sbin/sendmail -t -i');
\ini_set('sendmail_path', $previousSendmailPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should happen in tearDown().

$this->assertEquals('sendmail://default', (string) $t);
}

public function testToStringPhpConfig()
{
$previousSendmailPath = \ini_set('sendmail_path', '/usr/sbin/sendmail -t -i');
$t = new SendmailTransport();
\ini_set('sendmail_path', $previousSendmailPath);
$this->assertEquals('sendmail://default', (string) $t);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Mailer/Transport/SendmailTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
*/
class SendmailTransport extends AbstractTransport
{
private string $command = '/usr/sbin/sendmail -bs';
private const SENDMAIL_FHS_PATH = '/usr/sbin/sendmail -bs';
private string $command;
private ProcessStream $stream;
private ?SmtpTransport $transport = null;

Expand All @@ -59,6 +60,8 @@ public function __construct(string $command = null, EventDispatcherInterface $di
}

$this->command = $command;
} else {
$this->command = \ini_get('sendmail_path') ?: self::SENDMAIL_FHS_PATH;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will change the default behavior: before: -bs, after -t -i on my Ubuntu.
We need another way to opt-in for reading from ini

}

$this->stream = new ProcessStream();
Expand Down