Skip to content

Commit 9cb7b69

Browse files
committed
fix: stop forwarding PhpMailer SMTP handshake to the logger
Sentry issue PHP-SYMFONY-2B accumulated 1034 events, each containing the full PhpMailer SMTP debug dump: base64-encoded auth password, recipient addresses and the message body. This happened because when SMTP_DEBUG_LEVEL > 0, PhpMailer's Debugoutput callback was wired into the Symfony logger, which then forwarded everything to Sentry at notice level. Fix: remove the Debugoutput -> logger wiring and the in-memory sendLog buffer entirely. SMTPDebug still works for local debugging — PhpMailer prints to stdout / error_log by default. Replace it with a single info-level "Email sent" log carrying only recipient and subject. Leaves the monolog Sentry handler threshold untouched.
1 parent a29c31b commit 9cb7b69

1 file changed

Lines changed: 5 additions & 22 deletions

File tree

src/Mail/PHPMailerMailSender.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
class PHPMailerMailSender implements MailSenderInterface
1111
{
12-
private array $sendLog = [];
13-
1412
public function __construct(
1513
private readonly string $fromEmail,
1614
private readonly string $fromName,
@@ -26,10 +24,7 @@ public function sendMail($recipient, $subject, $message)
2624
$this->mailer->clearAllRecipients();
2725

2826
$this->mailer->isSMTP(); // Set mailer to use SMTP
29-
$this->mailer->SMTPDebug = $this->debugLevel;
30-
if ($this->debugLevel > 0 && $this->logger) {
31-
$this->mailer->Debugoutput = $this->debugOutput(...);
32-
}
27+
$this->mailer->SMTPDebug = $this->debugLevel;
3328

3429
$this->mailer->Host = $this->emailConfig["smtp_host"]; // Specify main and backup SMTP servers
3530
$this->mailer->Port = $this->emailConfig["smtp_port"]; // TCP port to connect to
@@ -44,23 +39,11 @@ public function sendMail($recipient, $subject, $message)
4439
$this->mailer->Subject = $subject;
4540
$this->mailer->Body = $message;
4641

47-
$this->sendLog = [];
4842
$this->mailer->send();
49-
if ($this->debugLevel > 0 && $this->logger && $this->sendLog !== []) {
50-
$this->saveSendLog();
51-
}
52-
}
53-
54-
/**
55-
* @internal
56-
*/
57-
public function debugOutput($str, $level): void
58-
{
59-
$this->sendLog[] = sprintf('[%s] %s', $level, $str);
60-
}
6143

62-
private function saveSendLog(): void
63-
{
64-
$this->logger->notice('PhpMailer Debug', ['sendLog' => $this->sendLog]);
44+
$this->logger?->info('Email sent', [
45+
'recipient' => $recipient,
46+
'subject' => $subject,
47+
]);
6548
}
6649
}

0 commit comments

Comments
 (0)