function fn_send_mail($to, $from, $subj, $body, $attachments = array(), $lang_code = CART_LANGUAGE, $reply_to = '', $is_html = true) { $__from = array(); $__to = array(); fn_init_mailer(); $mailer =& Registry::get('mailer'); $languages = Registry::get('languages'); if (!is_array($from)) { $__from['email'] = $from; $__from['name'] = Registry::get('settings.Company.company_name'); } else { $__from = $from; } Registry::get('view_mail')->setLanguage($lang_code); $mailer->ClearAttachments(); //$mailer->IsMail(); $mailer->From = $__from['email']; $mailer->FromName = $__from['name']; if (!empty($reply_to)) { $mailer->ClearReplyTos(); $mailer->AddReplyTo($reply_to); } $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); } } if (!is_array($to)) { $__to = str_replace(';', ',', $to); $__to = explode(',', $__to); } else { $__to = $to; } foreach ($__to as $v) { $mailer->ClearAddresses(); $mailer->AddAddress(trim($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 $result; }
function fn_override_mailer($restore = false) { static $saved_mailer; fn_init_mailer(); // restore default mailer if ($restore && !empty($saved_mailer)) { Registry::set('mailer', $saved_mailer); unset($saved_mailer); return; } // override default mailer by mailer with newsletter settings $mailer_settings = Registry::get('addons.news_and_emails'); if ($mailer_settings['mailer_send_method'] != 'default') { $default_mailer = Registry::get('mailer'); $saved_mailer = $default_mailer; $new_mailer = new Mailer(); $new_mailer->LE = defined('IS_WINDOWS') ? "\r\n" : "\n"; $new_mailer->PluginDir = DIR_LIB . 'phpmailer/'; if ($mailer_settings['mailer_send_method'] == 'smtp') { $new_mailer->IsSMTP(); $new_mailer->SMTPAuth = $mailer_settings['mailer_smtp_auth'] == 'Y' ? true : false; $new_mailer->Host = $mailer_settings['mailer_smtp_host']; $new_mailer->Username = $mailer_settings['mailer_smtp_username']; $new_mailer->Password = $mailer_settings['mailer_smtp_password']; } elseif ($mailer_settings['mailer_send_method'] == 'sendmail') { $new_mailer->IsSendmail(); $new_mailer->Sendmail = $mailer_settings['mailer_sendmail_path']; } else { $new_mailer->IsMail(); } Registry::set('mailer', $new_mailer); } }