Skip to content

Commit 87d7ac2

Browse files
committed
feat: add simple smtp plugin
1 parent 6c1f3ee commit 87d7ac2

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ ARG PHP_EXTENSIONS
4747
RUN --mount=type=bind,from=ext-installer,src=/usr/bin/install-php-extensions,dst=/usr/bin/install-php-extensions <<EOT
4848
install-php-extensions $PHP_EXTENSIONS
4949
EOT
50+
51+
COPY --chown=www-data:www-data wp-content /usr/src/wordpress/wp-content

wp-content/mu-plugins/smtp.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
if (!defined('ABSPATH')) {
4+
exit;
5+
}
6+
7+
add_action('phpmailer_init', 'phpmailer_envconfig');
8+
9+
function phpmailer_envconfig($phpmailer) {
10+
$mailer = getenv_docker('MAIL_MAILER', '');
11+
12+
if ($mailer === 'smtp') {
13+
$phpmailer->isSMTP();
14+
$phpmailer->Host = getenv_docker('MAIL_HOST', '');
15+
$phpmailer->Port = getenv_docker('MAIL_PORT', 587);
16+
$phpmailer->SMTPSecure = getenv_docker('MAIL_SMTP_SECURE', 'tls');
17+
$phpmailer->SMTPAuth = getenv_docker('MAIL_SMTP_AUTH', true);
18+
$phpmailer->Username = getenv_docker('MAIL_USERNAME', '');
19+
$phpmailer->Password = getenv_docker('MAIL_PASSWORD', '');
20+
21+
$from = getenv_docker('MAIL_FROM_ADDRESS', '');
22+
if ($from) {
23+
$phpmailer->From = $from;
24+
}
25+
26+
$fromName = getenv_docker('MAIL_FROM_NAME', '');
27+
if ($fromName) {
28+
$phpmailer->FromName = getenv_docker('MAIL_FROM_NAME', '');
29+
}
30+
}
31+
}
32+
33+
add_action('wp_mail_failed', 'phpmailer_error_log');
34+
35+
function phpmailer_error_log($wp_error) {
36+
if (WP_DEBUG) {
37+
error_log('Mail failed: ' . $wp_error->get_error_message());
38+
}
39+
};

0 commit comments

Comments
 (0)