1
我需要生成一個excel文件並通過電子郵件發送給店主所有新訂單。Opencart以新訂單發送自定義電子郵件
我已插入的public_html /目錄/模型/檢出此代碼/ order.php
//emails have been changed on purpose
$email_to = "my email";
$mail2 = new Mail();
$mail2->protocol = $this->config->get('config_mail_protocol');
$mail2->parameter = $this->config->get('config_mail_parameter');
$mail2->hostname = $this->config->get('config_smtp_host');
$mail2->username = $this->config->get('config_smtp_username');
$mail2->password = $this->config->get('config_smtp_password');
$mail2->port = $this->config->get('config_smtp_port');
$mail2->timeout = $this->config->get('config_smtp_timeout');
$mail2->setTo($email_to);
$mail2->setFrom("[email protected]");
$mail2->setSender("[email protected]");
$mail2->setSubject("test send mail");
$mail2->setText("test message body text");
$mail2->send();
我已插入上述右邊的代碼後此:
// Admin Alert Mail
if ($this->config->get('config_order_mail')) {
$subject = sprintf($language->get('text_new_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $order_id);
// HTML Mail
$data['text_greeting'] = $language->get('text_new_received');
if ($comment) {
if ($order_info['comment']) {
$data['comment'] = nl2br($comment) . '<br/><br/>' . $order_info['comment'];
} else {
$data['comment'] = nl2br($comment);
}
} else {
if ($order_info['comment']) {
$data['comment'] = $order_info['comment'];
} else {
$data['comment'] = '';
}
}
$data['text_download'] = '';
$data['text_footer'] = '';
$data['text_link'] = '';
$data['link'] = '';
$data['download'] = '';
// Text
$text = $language->get('text_new_received') . "\n\n";
$text .= $language->get('text_new_order_id') . ' ' . $order_id . "\n";
$text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n";
$text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n";
$text .= $language->get('text_new_products') . "\n";
foreach ($order_product_query->rows as $product) {
$text .= $product['quantity'] . 'x ' . $product['name'] . ' (' . $product['model'] . ') ' . html_entity_decode($this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n";
$order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . $product['order_product_id'] . "'");
foreach ($order_option_query->rows as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
}
$text .= chr(9) . '-' . $option['name'] . ' ' . (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value) . "\n";
}
}
foreach ($order_voucher_query->rows as $voucher) {
$text .= '1x ' . $voucher['description'] . ' ' . $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']);
}
$text .= "\n";
$text .= $language->get('text_new_order_total') . "\n";
foreach ($order_total_query->rows as $total) {
$text .= $total['title'] . ': ' . html_entity_decode($this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n";
}
$text .= "\n";
if ($order_info['comment']) {
$text .= $language->get('text_new_comment') . "\n\n";
$text .= $order_info['comment'] . "\n\n";
}
$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->setTo($this->config->get('config_email'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$mail->setHtml($this->load->view('mail/order', $data));
$mail->setText($text);
$mail->send();
我也有一個腳本生成excel文件,但我不知道如何將它們結合在一起。現在
問題:
- 定製郵件不能發送新的秩序,但新訂單一般電子郵件沒有問題影響深遠。
- 請給出任何想法如何生成excel在Opencart CMS上的代碼。