Skip to main content

Adding a banner

Halon can add a message banner to emails being sent or received. If you'd like the banner to appear at the bottom of the message, simply replace prependPart with appendPart. The example provided includes two versions: one for HTML emails and one for plain text. Keep in mind that while this generally works well in practice, there’s no absolute guarantee that all mail user agents (email clients) will display the banner consistently or correctly.

End of Data
// Adding a HTML part
foreach ($mail->findByType(#/^text\/html$/) ?: $mail->getType() == "text/html" ? [$mail] : [] as $a)
{
$a->prependPart(MIME()
->setType("text/html")
->setBody(''<html><div style="background-color:yellow;border:1px solid red;padding:5px;margin:10px;">This mail is from an external source</div></html>''));
break;
}

// Adding a text part
foreach ($mail->findByType(#/^text\/plain$/) ?: $mail->getType() == "text/plain" ? [$mail] : [] as $a)
{
$a->prependPart(MIME()
->setType("text/plain")
->setBody("This mail is from an external source"));
break;
}