Search code examples
phpemailsendmailswiftmailersymfony4

How to configure MAILER_URL in .env file of Symfony 4 to send e-mails via sendmail with Swift_Mailer?


I am working on a Symfony 4 app using Swift_Mailer to send e-mails with. Since there is no possibility in my case to use SMTP (don't ask why…) I have to use something like sendmail.

By default the config of Swift Mailer is done in Symfony's .env file in URL notation in an option named MAILER_URL. The default value is "null://localhost" which doesn't send mails at all.

All I could find for what the value has to be is an example for Gmail or for SMTP in general as documented in the Symfony docs as well as in the sample .env as generated by Composer.

Default content of .env:

# …

###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###

# …

What I don't know and therefore what my question is:

What do I need to do to make sendmail work with this?

I already tried something like:

MAILER_URL=sendmail://localhost

and

MAILER_URL=sendmail://my-domain.com

but without success so far.

When using the console command

bin/console swiftmailer:email:send

I even get an "[OK] 1 emails were successfully sent." as result, but in fact no e-mail is sent.
(… No spooling, by the way. bin/console swiftmailer:spool:send returns "0 emails sent".) Mail delivery seems to be interupted or so, since the mails won't arraive at my mail account, also my SPAM is empty.

Directly invoking the sendmail command on the other hand does work. (My test mails arrive at my SPAM though, but still: The mails are sent.)

Again, how do I have to configure the MAILER_URL for Swift_Mailer in my .env in Symfony 4 to use sendmail?

Is it possible at all?


Solution

  • Alright, the notation already was correct. So this one is valid for using sendmail:

    MAILER_URL=sendmail://my-domain.com
    

    My actual problem was that spooling of mails was active. I commented out the spool entry from my swiftmailer.yaml config.

    Having a look into the Symfony Profiler helped me a lot here, by the way.

    … My mails are still not arriving, but I am sure this has nothing to do with the MAILER_URL. So, my question is answered.