我正在使用以下函数在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。
答案 0 :(得分:0)
我找到了它:)
要显示/重新显示html模板,请使用以下代码。
$body = Registry::get('view_mail')->display($body, false);
print_r($body);
答案 1 :(得分:0)
您有两个选择:
选项1 您创建了邮件发件人函数,它将返回正文,并在您的加载项中使用它。例如:
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
}