Files
portal-api/app/Support/EmailTemplateShell.php
T
2026-09-23 15:17:18 +07:00

93 lines
7.5 KiB
PHP

<?php
namespace App\Support;
/**
* Khung 700px dùng chung cho template email trong tbl.template: header (banner) + footer
* (menu dịch vụ + thông tin công ty). Mỗi scenario chỉ cần viết phần <tr class="NoiDungKM">.
*
* Thông tin công ty hardcode ở footer vì EmailTemplateRenderer chỉ thay placeholder dạng
* {{key}} đã khai báo trong metadata.variables — mọi scenario đều phải khai lại nếu muốn
* footer động, không đáng.
*/
class EmailTemplateShell
{
/** Bọc phần nội dung vào khung chuẩn. */
public static function wrap(string $bodyHtml): string
{
return self::header() . $bodyHtml . self::footer();
}
/**
* Mở khối NoiDungKM với style chữ chuẩn, để scenario chỉ viết nội dung bên trong.
*/
public static function body(string $innerHtml): string
{
return '<tr class="NoiDungKM"><td style="width: 700px; padding: 32px 48px; background-color: #ffffff; font-family: Montserrat,-apple-system,sans-serif; font-size: 15px; line-height: 24px; color: #626262;" valign="top">'
. $innerHtml
. '</td></tr>';
}
/** Khối "Lưu ý: email tự động" dùng ở cuối hầu hết scenario. */
public static function autoNotice(): string
{
return <<<'HTML'
<table style="width: 100%; border-collapse: collapse;" role="presentation" cellspacing="0" cellpadding="0"><tbody><tr>
<td style="padding: 14px 16px; border-left: 3px solid #f16723; background-color: #f8fafc; font-size: 13px; line-height: 20px; color: #626262;"><strong style="color: #374151;">Lưu ý:</strong> Đây là email được gửi tự động. Vui lòng không trả lời email này.</td>
</tr></tbody></table>
HTML;
}
public static function header(): string
{
return <<<'HTML'
<table style="border-collapse: collapse; width: 100%; background-color: #efefef;" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td style="padding: 20px;" align="center" valign="top"><table style="padding-top: 20px; padding-bottom: 20px; border-collapse: collapse; background-color: #ffffff; width: 700px;" border="0" cellspacing="0" cellpadding="0"><tbody>
<tr class="Header"><td style="width: 700px;" valign="top"><table align="center" width="700" bgcolor="#ffffff" style="border-collapse: collapse; width: 700px; max-width: 100%; text-align: center; background-color: #ffffff; border-top: 5px solid #f16723;" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td style="padding: 0;"><a href="https://tgs.com.vn" style="display: block;" target="_blank" rel="noopener"><img src="https://res.cloudinary.com/izpast9i/image/upload/v1786499308/email_header.png" alt="Thư gửi từ CÔNG TY CỔ PHẦN GIẢI PHÁP CÔNG NGHỆ THẾ GIỚI SỐ" style="width: 100%; display: block; border: none;" width="700"></a></td></tr></tbody></table></td></tr>
HTML;
}
public static function footer(): string
{
return <<<'HTML'
<tr class="Footer"><td align="center" valign="top"><table border="0" cellpadding="0" cellspacing="0" width="700" align="center" background="https://res.cloudinary.com/izpast9i/image/upload/v1786500298/email_footer.png" bgcolor="#F16723" style="border-collapse: collapse; width: 700px; background-image: url(&quot;https://res.cloudinary.com/izpast9i/image/upload/v1786500298/email_footer.png&quot;); background-size: cover; background-position: center; background-repeat: no-repeat;"><tbody>
<tr><td style="padding: 40px 30px 20px 30px; text-align: center;"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: separate; border-spacing: 8px 0; width: 100%;"><tbody><tr>
<td width="25%" style="border: 1px solid rgba(255,255,255,0.35); border-radius: 8px; padding: 6px 4px; font-size: 12px; line-height: 16px; color: #ffffff; text-align: center; background-color: rgba(255,255,255,0.18);"><a href="https://tgs.com.vn/premium-hosting/" target="_blank" rel="noopener" style="color: #ffffff; text-decoration: none;">Premium Hosting</a></td>
<td width="25%" style="border: 1px solid rgba(255,255,255,0.35); border-radius: 8px; padding: 6px 4px; font-size: 12px; line-height: 16px; color: #ffffff; text-align: center; background-color: rgba(255,255,255,0.18);"><a href="https://tgs.com.vn/cloud-server/" target="_blank" rel="noopener" style="color: #ffffff; text-decoration: none;">Cloud Server</a></td>
<td width="25%" style="border: 1px solid rgba(255,255,255,0.35); border-radius: 8px; padding: 6px 4px; font-size: 12px; line-height: 16px; color: #ffffff; text-align: center; background-color: rgba(255,255,255,0.18);"><a href="https://cloudemail.vn/" target="_blank" rel="noopener" style="color: #ffffff; text-decoration: none;">Email doanh nghiệp</a></td>
<td width="25%" style="border: 1px solid rgba(255,255,255,0.35); border-radius: 8px; padding: 6px 4px; font-size: 12px; line-height: 16px; color: #ffffff; text-align: center; background-color: rgba(255,255,255,0.18);"><a href="https://tgs.com.vn/thiet-ke-website/" target="_blank" rel="noopener" style="color: #ffffff; text-decoration: none;">Thiết kế website</a></td>
</tr></tbody></table></td></tr>
<tr><td style="padding: 6px 30px 0 30px; text-align: center;"><strong style="font-size: 14px; line-height: 22px; color: #ffffff;">CÔNG TY CỔ PHẦN GIẢI PHÁP CÔNG NGHỆ THẾ GIỚI SỐ</strong></td></tr>
<tr><td style="padding: 6px 30px 0 30px; text-align: center;"><span style="font-size: 12px; line-height: 18px; color: #ffffff;">Địa chỉ: 128/38 Tân Hương, Phường Phú Thọ Hòa, Thành Phố Hồ Chí Minh</span></td></tr>
<tr><td style="padding: 6px 30px 0 30px; text-align: center;"><span style="font-size: 12px; line-height: 18px; color: #ffffff;">Tel: (028) 7309. 7379 &nbsp;-&nbsp; MST: 0318443116</span></td></tr>
<tr><td style="padding: 6px 30px 0 30px; text-align: center;"><span style="font-size: 12px; line-height: 18px; color: #ffffff;">Email: <a href="mailto:support@tgs.com.vn" style="color: #ffffff; text-decoration: none;">support@tgs.com.vn</a></span></td></tr>
<tr><td style="padding: 6px 30px 0 30px; text-align: center;"><span style="font-size: 12px; line-height: 18px; color: #ffffff;"><a href="https://www.tgs.com.vn" style="color: #ffffff; text-decoration: underline;">www.TGS.com.vn</a> &nbsp;&amp;&nbsp; <a href="https://www.thegioiso.cloud" style="color: #ffffff; text-decoration: underline;">www.thegioiso.CLOUD</a> &nbsp;&amp;&nbsp; <a href="https://www.thegioiserver.com" style="color: #ffffff; text-decoration: underline;">www.thegioiSERVER.com</a> &nbsp;&amp;&nbsp; <a href="https://www.cloudemail.vn" style="color: #ffffff; text-decoration: underline;">www.CloudEmail.vn</a></span></td></tr>
<tr><td style="padding: 6px 30px 16px 30px; text-align: center;"><span style="font-size: 12px; line-height: 20px; color: #ffffff; font-weight: bold;">Thế Giới Số - Premium HOSTING &bull; CLOUD &bull; SERVER &amp; WEBSITE | 15+ năm Phụng Sự</span></td></tr>
</tbody></table></td></tr>
</tbody></table></td></tr></tbody></table>
HTML;
}
/**
* Bọc một đoạn HTML thành email hoàn chỉnh (doctype + head). Thay cho blade
* emails.customer.template-envelope — để không còn mail nào đi qua Blade.
*/
public static function document(?string $title, string $bodyHtml): string
{
$safeTitle = htmlspecialchars((string) $title, ENT_QUOTES, 'UTF-8');
return <<<HTML
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{$safeTitle}</title>
</head>
<body style="margin:0;padding:0;">
{$bodyHtml}
</body>
</html>
HTML;
}
}