Skip to content

Instantly share code, notes, and snippets.

@pjaudiomv
Created June 23, 2024 00:24
Show Gist options
  • Save pjaudiomv/b2a4024ff958778ae3642cda8c65bb17 to your computer and use it in GitHub Desktop.
Save pjaudiomv/b2a4024ff958778ae3642cda8c65bb17 to your computer and use it in GitHub Desktop.
WordPress with SMTP using mailpit for local dev
services:
wordpress:
depends_on:
- db
- mailpit
image: wordpress:6.5.3-php8.3-apache
restart: always
ports:
- 8080:80
- 7443:443
environment:
WORDPRESS_DEBUG: true
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_SMTP_HOST: mailpit
WORDPRESS_SMTP_PORT: 1025
SMTP_HOSTNAME: mailpit
SMTP_PORT: "1025"
SMTP_USER: email@xyz.com
SMTP_FROM: email@xyz.com
WORDPRESS_CONFIG_EXTRA: |
// SMTP Settings
require_once( ABSPATH .'wp-includes/plugin.php' );
add_action( 'phpmailer_init', 'mail_smtp' );
function mail_smtp( $$phpmailer ) {
$$phpmailer->isSMTP();
$$phpmailer->Host = getenv('SMTP_HOSTNAME');
$$phpmailer->Port = getenv('SMTP_PORT');
$$phpmailer->From = getenv('SMTP_FROM');
$$phpmailer->FromName = getenv('SMTP_FROM_NAME');
// Additional settings
$$phpmailer->SMTPAuth = false;
$$phpmailer->SMTPSecure = "";
$$phpmailer->SMTPAutoTLS = false;
// Filter out client message body and output debug info to the logs
// NOTE: Log level must be set to '2' or higher in order for the filter to work
$$phpmailer->SMTPDebug = 2;
$$phpmailer->Debugoutput = function($$str) {
static $$logging = true;
if ($$logging === false && strpos($$str, 'SERVER -> CLIENT') !== false) {
$$logging = true;
}
if ($$logging) {
error_log("SMTP " . "$$str");
}
if (strpos($$str, 'SERVER -> CLIENT: 354') !== false) {
$$logging = false;
}
};
}
// Prevent Wordpress from overriding the SMTP FROM address (Office 365 compatibility)
add_filter( 'wp_mail_from', function( $$email ) {
return $$_ENV["SMTP_FROM"];
});
volumes:
- ../:/var/www/html/wp-content/plugins
- ./logs/:/var/log/apache2
db:
image: mariadb:10.11
restart: always
ports:
- 3306:3306
environment:
MARIADB_ROOT_PASSWORD: somewordpress
MARIADB_DATABASE: wordpress
MARIADB_USER: wordpress
MARIADB_PASSWORD: wordpress
mailpit:
image: axllent/mailpit
ports:
- "1025:1025"
- "8025:8025"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment