For local development, so that I can test outgoing email safely, I use the Drupal settings.php file to store my MailHog email server settings e.g.

$conf['smtp_host'] = 'mail'; //Docker container
$conf['smtp_port'] = '1025'; //MailHog port 

This way I can refresh the local database and it will immediately work in my local environment.

I cannot see an obvious way of doing this for CiviCRM? Looking at the API explorer, I have experimented with a few things like:


But does this not seem to work. Can this be done? It would be nice to not have to change my SMTP setting each time.

1 Answer 1


Use something like:

$civicrm_setting['Mailing Preferences']['mailing_backend']['smtpPort'] = '587';

I think the group name 'Mailing Preferences' is obsolete and could be 'domain', but the above works.

You could also use the define('CIVICRM_MAIL_LOG') which you'll find lower down in civicrm.settings.php to dump all mail raw to a file without sending it.

  • 2
    Thanks so much for that - works perfectly. Tested with ['domain'] and this works so I have used this in preference to ['Mailing Preferences']. I need to see the results of the various HTML templated emails that go out so this is ideal. For those using MailHog with Docker my civicrm.settings.php file now has: $civicrm_setting['domain']['mailing_backend']['smtpPort'] = '1025'; //MailHog smtp port $civicrm_setting['domain']['mailing_backend']['smtpServer'] = 'mail'; //Docker container $civicrm_setting['domain']['mailing_backend']['smtpAuth'] = 0; //No auth required
    – ChumKui
    Feb 23, 2022 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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