diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php
index f9868ee69..76b3a8bfe 100644
--- a/app/Controllers/Sales.php
+++ b/app/Controllers/Sales.php
@@ -937,7 +937,10 @@ class Sales extends Secure_Controller
new Token_customer((array)$sale_data)
];
$text = $this->token_lib->render($text, $tokens);
- $sale_data['mimetype'] = mime_content_type(FCPATH . 'uploads/' . $this->config['company_logo']);
+ $sale_data['mimetype'] = $this->email_lib->getLogoMimeType();
+
+ // Build img_tag for email views that need it (receipt_email.php)
+ $sale_data['img_tag'] = $this->email_lib->buildLogoImgTag();
// Generate email attachment: invoice in PDF format
$view = Services::renderer();
@@ -974,13 +977,7 @@ class Sales extends Secure_Controller
if (!empty($sale_data['customer_email'])) {
$sale_data['barcode'] = $this->barcode_lib->generate_receipt_barcode($sale_data['sale_id']);
- $sale_data['img_tag'] = '';
-
- $logo_path = FCPATH . 'uploads/' . $this->config['company_logo'];
- if (!empty($this->config['company_logo']) && file_exists($logo_path)) {
- $logo_data = base64_encode(file_get_contents($logo_path));
- $sale_data['img_tag'] = '
';
- }
+ $sale_data['img_tag'] = $this->email_lib->buildLogoImgTag();
$to = $sale_data['customer_email'];
$subject = lang('Sales.receipt');
diff --git a/app/Libraries/Email_lib.php b/app/Libraries/Email_lib.php
index 914344567..eb8a9c24c 100644
--- a/app/Libraries/Email_lib.php
+++ b/app/Libraries/Email_lib.php
@@ -82,4 +82,40 @@ class Email_lib
return $result;
}
+
+ /**
+ * Gets the mime type of the company logo file.
+ *
+ * @return string Mime type or empty string if logo doesn't exist
+ */
+ public function getLogoMimeType(): string
+ {
+ $logo_path = FCPATH . 'uploads/' . $this->config['company_logo'];
+
+ if (!empty($this->config['company_logo']) && file_exists($logo_path)) {
+ $mimeType = mime_content_type($logo_path);
+ return $mimeType !== false ? $mimeType : '';
+ }
+
+ return '';
+ }
+
+ /**
+ * Builds an img tag for the company logo to use in email templates.
+ *
+ * @return string HTML img tag with base64-encoded logo, or empty string if no logo
+ */
+ public function buildLogoImgTag(): string
+ {
+ $mimeType = $this->getLogoMimeType();
+
+ if ($mimeType === '') {
+ return '';
+ }
+
+ $logo_path = FCPATH . 'uploads/' . $this->config['company_logo'];
+ $logo_data = base64_encode(file_get_contents($logo_path));
+
+ return '
';
+ }
}