Skip to content

Instantly share code, notes, and snippets.

@nullvariable
Created January 27, 2017 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nullvariable/5ed32739ddfb66d08577c8f877bb06b6 to your computer and use it in GitHub Desktop.
Save nullvariable/5ed32739ddfb66d08577c8f877bb06b6 to your computer and use it in GitHub Desktop.
set Craft to use local mailhog instance. Just drop in an existing plugin's init function, refresh and then remove (assumes you're using official Mailhog docker instance
<?php
$mailhog_name = getenv('MAILHOG_NAME');
$mailhog_port = getenv('MAILHOG_PORT');
if ($mailhog_name && $mailhog_port) {
$hostname = array_slice(explode('/', getenv('MAILHOG_NAME')), -1, 1)[0];
$port = array_slice(explode(':', getenv('MAILHOG_PORT')), -1, 1)[0];
$settings = craft()->systemSettings->getSettings('email');
$settings['protocol'] = 'smtp';
$settings['port'] = $port;
$settings['host'] = $hostname;
$settings['timeout'] = 10;
$settings['smtpKeepAlive'] = '';
$settings['smtpAuth'] = '';
$settings['smtpSecureTransportType'] = 'none';
craft()->systemSettings->saveSettings('email', $settings);
echo "Settings updated to use mailhog\n";
} else {
echo "Mailhog environment variables not found, skipping\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment