你有两个选择:
选项 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
}