Automatically use the configured sendmail_path #2236
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A long time ago, Swiftmailer dropped support for the PHP
mail
function for security reasons and thus forcing you to use eithersendmail
orsmtp
. However, when usingsendmail
, Swiftmailer only uses a hard coded command by default, which might not work on all hosting environments. The PHPmail
function on the other hand uses the configuredsendmail_path
of the PHP configuration, which most likely will work in the respective hosting environment. Since then, there were a lot of cases within the community where emails suddenly did not work anymore, and still did not work with sendmail.Only recently I learned (and began to understand the implications) that this is because some hosting environments require either a specific
sendmail
path or specific parameters for the command - which would be appropriately defined in thesendmail_path
PHP setting.This PR automatically injects the
sendmail_path
into theswiftmailer
configuration. Therefore emails should work again out of the box, just like it was before when Swiftmailer still supported PHPmail
.Contao 4.10 is (currently) out of luck here, since Symfony Mailer only supports setting the command (see symfony/symfony#37432) and a native transport that uses the
sendmail_path
(see symfony/symfony#36131) in the upcoming Symfony 5.2 version (see also #2164).Note: this PR drops support for
swiftmailer/swiftmailer-bundle
in version2.x
and increases the version requirement to^3.2.8
, since the feature to set the command is only really available since3.2.8
(see symfony/swiftmailer-bundle#286). But only for thecontao/manager-bundle
, since automatically using thesendmail_path
is only happening there and thus, if you have a regular Symfony application requiringcontao/core-bundle
you can still choose to useswiftmailer/swiftmailer-bundle
in version2.x
. For the same reason we cannot fix this in Contao 4.4, because thereswiftmailer/swiftmailer-bundle
can only be installed in a maximum version of3.2.6
, due to other version conflicts.Note: the unit tests for this are a bit lacking as
sendmail_path
cannot be changed at runtime.Testing Needed ❗
As a Windows user 🎖️ I don't have access to the native
sendmail
binary, only to a "fake sendmail" binary for Windows. However, for some reason this binary (which is also not maintained any more by the original author, afaik) is not working any more (though it did work for me in the past). While I was able to test whether the command is set to the correct value, and the command is also executed without prior errors, I was not able to test whether an email is actually sent.So to be sure someone on a UNIX based system please test this ;)
mailer_*
parameters are set in yourparameters.yml
.swiftmailer
configuration is set in yourconfig.yml
.MAILER_URL
environment variable is used.sendmail_path
PHP setting is correct.sendmail_path
setting on the command line first.swiftmailer:email:send --from=foo@example.com --to=foo@example.com --subject=Test --body=Test
.