Created
May 17, 2026 09:20
-
-
Save gebeer/3335785f3f35906621b925e1b746c282 to your computer and use it in GitHub Desktop.
WireMailSmtp BCC sendSingle demo script — demonstrates multi-BCC handling in default vs sendSingle mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace ProcessWire; | |
| include __DIR__ . '/../index.php'; | |
| config()->wiremailsmtp = [ | |
| 'smtp_host' => '127.0.0.1', | |
| 'smtp_port' => 1025, | |
| 'smtp_ssl' => 0, | |
| 'smtp_start_tls' => 0, | |
| 'allow_without_authentication' => 1, | |
| 'smtp_user' => '', | |
| 'smtp_password' => '', | |
| ]; | |
| $runId = date('Ymd-His'); | |
| $from = 'sender@example.test'; | |
| $fromName = 'WireMailSmtp Demo'; | |
| $to = 'primary@example.test'; | |
| $ccRecipients = [ | |
| 'cc-one@example.test', | |
| 'cc-two@example.test', | |
| ]; | |
| $bccRecipients = [ | |
| 'bcc-one@example.test', | |
| 'bcc-two@example.test', | |
| ]; | |
| $sendCase = static function (string $label, string $mode, array $recipients, bool $sendSingle) use ($runId, $from, $fromName, $to): array { | |
| $mail = wireMail(); | |
| $subject = sprintf('[wiremailsmtp-bcc-demo %s] %s sendSingle=%s', $runId, $label, $sendSingle ? 'true' : 'false'); | |
| $mail->to($to); | |
| if ($mode === 'cc') { | |
| $mail->cc($recipients); | |
| } elseif ($mode === 'bcc') { | |
| $mail->bcc($recipients); | |
| } else { | |
| throw new WireException('Unsupported recipient mode: ' . $mode); | |
| } | |
| $mail->from($from, $fromName); | |
| $mail->subject($subject); | |
| $mail->body(sprintf( | |
| "WireMailSmtp CC/BCC demo\n\nRun ID: %s\nCase: %s\nMode: %s\nsendSingle: %s\nRecipients: %s\n", | |
| $runId, | |
| $label, | |
| strtoupper($mode), | |
| $sendSingle ? 'true' : 'false', | |
| implode(', ', $recipients) | |
| )); | |
| if ($sendSingle && method_exists($mail, 'sendSingle')) { | |
| $mail->sendSingle(true); | |
| } | |
| $sent = $mail->send(); | |
| if (!$sent) { | |
| throw new WireException('Failed sending case: ' . $label); | |
| } | |
| return [ | |
| 'label' => $label, | |
| 'subject' => $subject, | |
| 'to' => $to, | |
| 'mode' => $mode, | |
| 'recipients' => $recipients, | |
| 'sendSingle' => $sendSingle, | |
| 'sendReturnValue' => $sent, | |
| ]; | |
| }; | |
| $results = [ | |
| $sendCase('cc-default', 'cc', $ccRecipients, false), | |
| $sendCase('bcc-default', 'bcc', $bccRecipients, false), | |
| $sendCase('cc-send-single', 'cc', $ccRecipients, true), | |
| $sendCase('bcc-send-single', 'bcc', $bccRecipients, true), | |
| ]; | |
| echo PHP_EOL . wireEncodeJSON([ | |
| 'runId' => $runId, | |
| 'mailpit' => 'http://127.0.0.1:8025', | |
| 'expectedObservation' => 'Compare Mailpit To/Cc/Bcc fields for default sendSingle=false vs sendSingle=true. WireMailSmtp default handling is expected to differ between CC and BCC; sendSingle=true should preserve all CC/BCC recipients for a single TO message.', | |
| 'results' => $results, | |
| ], true) . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment