Many shared hosting accounts require custom flags that are passed to sendmail in order for them to work properly.

Since Craft 3 uses Swiftmailer for its mailing library and Swiftmailer's default Sendmail command is /usr/sbin/sendmail -bs (https://github.com/swiftmailer/swiftmailer/blob/master/lib/classes/Swift/Transport/SendmailTransport.php#L30), is there a way to override that from Craft's config/app.php to set a custom sendmail command?

  • Are you aware that -bs makes sendmail talk SMTP over stdin&stdout? – AnFi Nov 1 '18 at 21:00
  • I had no idea @AnFi! – Brad Bell Nov 2 '18 at 22:10

There are some examples of how to override the mailer component and transport settings in the official Craft docs here: https://docs.craftcms.com/v3/config/#mailer-component

For this particular sendmail example, you'd need to do something like this from config/app.php:

'components' => [
    'mailer' => function() {
        // Get the stored email settings
        $settings = Craft::$app->systemSettings->getEmailSettings();

        // Override the transport adapter class
        $settings->transportType = craft\mail\transportadapters\Sendmail::class;

        // Create a Mailer component config with these settings
        $config = craft\helpers\App::mailerConfig($settings);
        $config['transport']['command'] = '/usr/bin/sendmail -customflags';

        // Instantiate and return it
        return Craft::createObject($config);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.