如何在cs购物车中return邮件html?

How to return the mail html in cscart?

我正在使用以下功能在 cscart 中发送 html 邮件。

  $value = fn_send_mail($user_data['email'], Registry::get('settings.Company.company_users_department'), 'addons/test/test_subj.tpl', 'addons/test/test_body.tpl');

如果我打印 $value 意味着它只有 return 1。我如何 return html 在这个函数中。

我找到了:)

要display/retrun html 模板,请使用以下代码。

$body = Registry::get('view_mail')->display($body, false);
print_r($body);

您有 2 个选择:

选项 1 你创建你的邮件发件人功能,它将 return 正文,并在你的附加组件中使用它。例如:

function custom_send_mail($to, $from, $subj, $body, $attachments = array(), $lang_code = CART_LANGUAGE, $reply_to = '', $is_html = true)
{
    fn_disable_translation_mode();
    $__from = array();
    $__to = array();

    fn_init_mailer();
    $mailer = & Registry::get('mailer');
    $languages = Registry::get('languages');
    Registry::get('view_mail')->setLanguage($lang_code);

    fn_set_hook('send_mail_pre', $mailer, $to, $from, $subj, $body, $attachments, $lang_code, $reply_to, $is_html);

    if (!empty($reply_to)) {
        $mailer->ClearReplyTos();
        $reply_to = fn_format_emails($reply_to);
        foreach ($reply_to as $rep_to) {
            $mailer->AddReplyTo($rep_to);
        }
    }

    if (!is_array($from)) {
        $__from['email'] = $from;
    } else {
        $__from = $from;
    }
    if (empty($__from['email'])) {
        $__from['email'] = Registry::get('settings.Company.company_site_administrator');
    }
    if (empty($__from['name'])) {
        $__from['name'] = Registry::get('settings.Company.company_name');
    }
    $mailer->SetFrom($__from['email'], $__from['name']);

    $mailer->IsHTML($is_html);
    $mailer->CharSet = CHARSET;
    $mailer->Subject = Registry::get('view_mail')->display($subj, false);
    $mailer->Subject = trim($mailer->Subject);
    $body = Registry::get('view_mail')->display($body, false);
    $mailer->Body = fn_attach_images($body, $mailer);

    if (!empty($attachments)) {
        foreach ($attachments as $name => $file) {
            $mailer->AddAttachment($file, $name);
        }
    }

    $__to = fn_format_emails($to);

    foreach ($__to as $v) {
        $mailer->ClearAddresses();
        $mailer->AddAddress($v, '');
        $result = $mailer->Send(); 
        if (!$result) {
            fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_message_not_sent') . ' ' . $mailer->ErrorInfo);
        }

        fn_set_hook('send_mail', $mailer);
    }
    return $body;
}

选项 2 您可以通过附加组件连接到 send_mail_pre 挂钩:

function fn_youraddonname_send_mail_pre($mailer, $to, $from, $subj, $body, $attachments, $lang_code, $reply_to, $is_html) {
    $rendered_body = Registry::get('view_mail')->display($body, false);
    // use your custom code, to do anything you want
    // this code will run everytime CS-Cart use the fn_send_mail function
}