Description
SwiftMailer handler's to_email
config parameter is supposed to accept an array of email addresses. It works ok when the array is given literally, like:
# config.yml
handlers:
email:
type: 'swift_mailer'
to_email:
- '[email protected]'
- '[email protected]'
However, it crashes if the array comes from an environment variable:
# .env
SUBSCRIBERS='["[email protected]", "[email protected]"]'
# config.yml
handlers:
email:
type: 'swift_mailer'
to_email: '%env(json:SUBSCRIBERS)%'
The error is:
Array to string conversion in /srv/www/acme/vendor/egulias/email-validator/EmailValidator/Validation/RFCValidation.php:30
I think the cause is that, this parameter being dynamic, its value gets replaced by a string placeholder, something like env_json_SUBSCRIBERS_d4fb785b4f5825b62c36d8476dab783b
. This is the value the Config component sees when it parses the bundle's configuration. Since it's a string, it converts it to array('env_json_SUBSCRIBERS_d4fb785b4f5825b62c36d8476dab783b')
. When the actual value is finally fetched, the param then equals array(array("[email protected]", "[email protected]"))
instead of the expected array("[email protected]", "[email protected]")
.