Page 1 of 1

Email template for new email

Posted: Tue Mar 28, 2017 9:01 pm
by asia
I am using Advanced Professional Email Template, and i am sending an email from catelog account/customer page for auto reward notification. How could i set the template here.

Re: Email template for new email

Posted: Fri Mar 31, 2017 12:55 am
by opencart-templates
Let me know what code you have so far to send the email but here's an example.

1. Load template

Code: Select all

$this->load->model('extension/mail/template');
$load_data = array(
  'emailtemplate_key' => 'order.customer',
  'language_id' => $order_info['language_id'],
  'store_id' => $order_info['store_id']
);
$template = $this->model_extension_mail_template->load($load_data);
2. Add data (can be used as shortcodes e.g {$foo})

Code: Select all

$template->data['foo']  = 'test';
// Or pass full array
$template->addData($data);
3. Attach html template to mail object. Calling hook method to merge mail properties and sets html template.

Code: Select all

$mail = new Mail();
$mail->setTo($order_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($order_info['store_name']);
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
$mail = $template->hook($mail);
$mail->send();
4. Called after email is sent. Cleans up attachments and other sent tasks

Code: Select all

$template->sent();

Re: Email template for new email

Posted: Sun May 20, 2018 3:30 am
by estand
Can you tell me how i can fix this with this code ?

//$this->template = 'mailtemplates/product_email.html';
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setFrom($fromID);
$mail->setTo($product_info['customer_email']);
$mail->setSender($store_name);
$mail->setSubject("product from " .$order_info['store_name']. " - Ref : ".$invoice_no);
$mail->setHtml($this->load->view('mailtemplates/product', $data));
$mail->send();

Re: Email template for new email

Posted: Sun Jun 03, 2018 4:30 pm
by opencart-templates
See below example. Please open support ticket if you need support with this.

Code: Select all

$this->load->model('extension/mail/template');

// Load email template
$load_data = array(
  'emailtemplate_key' => 'order.customer',
  'language_id' => $order_info['language_id'],
  'store_id' => $order_info['store_id']
);

$template = $this->model_extension_mail_template->load($load_data);

// Optional add data
$template->data['foo']  = 'test';
// Or pass full array
$template->addData($data);

$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setFrom($fromID);
$mail->setTo($product_info['customer_email']);
$mail->setSender($store_name);
$mail->setSubject("product from " .$order_info['store_name']. " - Ref : ".$invoice_no); 

//$mail->setHtml($this->load->view('mailtemplates/product', $data));

// Merge template and mail settings.
$mail = $template->hook($mail);

// Optional wrap text inside email template
$html = $template->fetch(null, $this->load->view('mailtemplates/product', $data));
$mail->setHtml($html);

$mail->send();

$template->sent();