From f3f58dbf953f717684457e93e667290c3d4a0037 Mon Sep 17 00:00:00 2001 From: Andy Dixon Date: Fri, 11 Sep 2026 18:10:16 +0100 Subject: [PATCH] Set webhook email sender identity --- index.php | 13 +++++----- tests/test_mail_sender.sh | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100755 tests/test_mail_sender.sh diff --git a/index.php b/index.php index e1645d3..ea801e2 100755 --- a/index.php +++ b/index.php @@ -319,12 +319,13 @@ HTML; $emailHeaders = "MIME-Version: 1.0\r\n"; // Content-type specifies HTML email with UTF-8 character encoding $emailHeaders .= "Content-type: text/html; charset=UTF-8\r\n"; -// From header sets the sender address to a no-reply address at wh.dixon.cx -$emailHeaders .= "From: no-reply@wh.dixon.cx\r\n"; - -// Send the email using PHP's built-in mail function -// Parameters: recipient, subject, message body, headers -$mailSent = mail($email, $subject, $html, $emailHeaders); +// Keep both the visible sender and SMTP envelope sender on the public domain. +$envelopeSender = 'no-reply@dixon.cx'; +$emailHeaders .= "From: Webhook Call <$envelopeSender>\r\n"; + +// Send the email using PHP's built-in mail function +// The -f option prevents sendmail from deriving www-data@. +$mailSent = mail($email, $subject, $html, $emailHeaders, '-f' . $envelopeSender); // Check if the email was sent successfully if (!$mailSent) { diff --git a/tests/test_mail_sender.sh b/tests/test_mail_sender.sh new file mode 100755 index 0000000..e905b42 --- /dev/null +++ b/tests/test_mail_sender.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -euo pipefail + +project_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) +test_dir=$(mktemp -d) +trap 'rm -rf "$test_dir"' EXIT + +sendmail_args="$test_dir/sendmail.args" +sendmail_message="$test_dir/sendmail.message" +fake_sendmail="$test_dir/sendmail" +prepend_file="$test_dir/prepend.php" + +cat > "$fake_sendmail" <<'FAKE_SENDMAIL' +#!/usr/bin/env bash +printf '%s\n' "$@" > "$MAIL_TEST_ARGS" +cat > "$MAIL_TEST_MESSAGE" +FAKE_SENDMAIL +chmod +x "$fake_sendmail" + +cat > "$prepend_file" <<'PHP' +/dev/null + +if ! grep -Fxq -- '-fno-reply@dixon.cx' "$sendmail_args"; then + echo 'Expected the envelope sender to be no-reply@dixon.cx.' >&2 + echo 'Actual sendmail arguments:' >&2 + sed 's/^/ /' "$sendmail_args" >&2 + exit 1 +fi + +if ! grep -Fq $'From: Webhook Call \r' "$sendmail_message"; then + echo 'Expected the From header to be Webhook Call .' >&2 + exit 1 +fi + +echo 'Mail sender test passed.'