【问题标题】:How to return the mail html in cscart?如何返回cs购物车中的邮件html?
【发布时间】:2017-11-17 10:02:26
【问题描述】:

我正在使用以下函数在 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 意味着它只返回 1。我如何在这个函数中返回 html。

【问题讨论】:

  • 您使用哪个版本的 CS-Cart?因为从 4.x 开始,fn_send_mail 函数被替换为 Mailer::class
  • 我正在使用 CS-CART:2.2.1 专业版。

标签: php cs-cart


【解决方案1】:

我找到了:)

要显示/重新运行 html 模板,请使用以下代码。

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

【讨论】:

  • 你说得对,不过你可以查看我的详细回答。
【解决方案2】:

你有两个选择:

选项 1 您创建将返回正文的 on mail sender 函数,并在您的附加组件中使用它。例如:

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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多