Print Magento Email Body before you send it
You can use this code to display the html conent
$transport = $this->transportBuilder
->setTemplateIdentifier($templateId) // string id or numeric DB id both supported
->setTemplateOptions([
'area' => Area::AREA_FRONTEND,
'store' => $storeId,
])
->setTemplateVars([
'customer' => $customer,
'customer_firstname' => (string) $customer->getFirstname(),
'customer_lastname' => (string) $customer->getLastname(),
'customer_email' => (string) $customer->getEmail(),
'store' => $store,
'store_name' => $store->getName(),
])
->setFromByScope($sender, $storeId)
->addTo(
(string) $customer->getEmail(),
trim((string) $customer->getFirstname() . ' ' . (string) $customer->getLastname())
)
->getTransport();
{
$body = $transport->getMessage()->getBody();
if ($body instanceof \Symfony\Component\Mime\Part\Multipart\AbstractMultipartPart) {
// Multipart message (old behavior)
$parts = $body->getParts();
$html = '';
foreach ($parts as $part) {
if ($part->getMediaType() === 'text' && $part->getSubType() === 'html') {
$html = $part->getBody();
break;
}
}
echo $html;
} elseif ($body instanceof \Symfony\Component\Mime\Part\TextPart) {
// Single part message (new behavior)
echo $body->getBody();
} else {
// Fallback
echo (string)$body;
}
}$transport->sendMessage();