Opencart: modifying email layouts

2019-03-02 06:52发布

问题:

I'm running Opencart Version 2.0.1.1. I need a way of editing the layout of the registration and order update email.

By this, I mean control the full layout using HTML/CSS, not just edit the text definitions of the variables. I am aware these are located in:

./catalog/language/english/mail/customer.php and ../order.php respectively.

My theme came with a custom mail for the order email template located in ./catalog/view/theme/theme574/template/mail/order.tpl (see below).

I want that level of control for when the user registers and when I update the order status with a comment.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"       "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $title; ?></title>
</head>
  <body style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;">
    <div style="width: 680px;"><a href="<?php echo $store_url; ?>" title="<?php echo $store_name; ?>"><img src="<?php echo $logo; ?>" alt="<?php echo   $store_name; ?>" style="margin-bottom: 20px; border: none;" /></a>
      <p style="margin-top: 0px; margin-bottom: 20px;"><?php echo $text_greeting; ?></p>
        <?php if ($customer_id) { ?>
           <p style="margin-top: 0px; margin-bottom: 20px;"><?php echo $text_link; ?></p>
           <p style="margin-top: 0px; margin-bottom: 20px;"><a href="<?php echo $link; ?>"><?php echo $link; ?></a></p>
    ...
    ...
    ...

Could anyone help me out here? Any tips on where to start would be greatly appreciated.

Thank you.

回答1:

i had same problem but i used mailgun lib to send my mails and i can use html/css templates :)

if you like follow this steps: 1-download mailgun lib https://github.com/mailgun/mailgun-php

2- you have to edit system mail system or add your function to opencart system : (i change mail function opencart totaly) i add this codes to /system/library/mail.php rename send() to oldsend() or whatever you want

    //extracted mailgun lib address
    require 'mailgun/autoload.php';
    use Mailgun\Mailgun;

        public function send(){
        $mg = new Mailgun("mailgunkey goeshere");
        $domain = "your domain code";

        $mg->sendMessage($domain, array(
            'from'    => $this->from , 
            'to'      => $this->to , 
            'subject' => $this->subject , 
            'text'    => $this->text , 
            'html'    => $this->html
            ));
    }

as a example for sending mail:

     $data['text_discount'] = 'text';

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/welcome.tpl')) {
            $html = $this->load->view($this->config->get('config_template') . '/template/mail/welcome.tpl', $data);
        } else {
            $html = $this->load->view('default/template/mail/welcome.tpl', $data);
        }
$mail->setTo($data['email']);
        $mail->setFrom($this->config->get('config_email'));
        $mail->setSender(html_entity_decode($this->config->get('config_name'),ENT_QUOTES, 'UTF-8'));
        $mail->setSubject($subject);
        $mail->setHtml($html);
        $mail->send();

this is just basic example :)