diff --git a/application/config/mail.php b/application/config/mail.php index 9d577720d..4f1baa85d 100644 --- a/application/config/mail.php +++ b/application/config/mail.php @@ -32,3 +32,18 @@ $config['validate'] = false; // If true then the email address will be validated // If enabled will be logged info about emails in Codeigniter error logs $config['enable_debug'] = false; + +// default sender +$config['sancho_mail_default_sender'] = defined('SANCHO_MAIL_DEFAULT_SENDER') ? SANCHO_MAIL_DEFAULT_SENDER : ''; + +// If to use images for custom mails +$config['sancho_mail_use_images'] = defined('SANCHO_MAIL_USE_IMAGES') ? SANCHO_MAIL_USE_IMAGES : false; + +// image path for sancho mail, relativ to document root +$config['sancho_mail_img_path'] = defined('SANCHO_MAIL_IMG_PATH') ? SANCHO_MAIL_IMG_PATH : ''; + +// header image for custom mails +$config['sancho_mail_header_img'] = defined('SANCHO_MAIL_HEADER_IMG') ? SANCHO_MAIL_HEADER_IMG : ''; + +// footer image for custom mails +$config['sancho_mail_footer_img'] = defined('SANCHO_MAIL_FOOTER_IMG') ? SANCHO_MAIL_FOOTER_IMG : ''; diff --git a/application/controllers/jobs/AnrechnungJob.php b/application/controllers/jobs/AnrechnungJob.php index 5784830b6..52bf972e3 100644 --- a/application/controllers/jobs/AnrechnungJob.php +++ b/application/controllers/jobs/AnrechnungJob.php @@ -195,10 +195,10 @@ class AnrechnungJob extends JOB_Controller $studiengang_bezeichnung = $this->StudiengangModel->load($studiengang_kz)->retval[0]->stg_bezeichnung; // Get STGL mail address - $stglMailReceiver_arr = self::_getSTGLMailAddress($studiengang_kz); + $stglMailReceiver_arr = $this->_getSTGLMailAddress($studiengang_kz); // Get HTML table with new Anrechnungen of that STG plus amount of them - list ($anrechnungen_amount, $anrechnungen_table) = self::_getSTGLMailDataTable($studiengang_kz, $anrechnungen); + list ($anrechnungen_amount, $anrechnungen_table) = $this->_getSTGLMailDataTable($studiengang_kz, $anrechnungen); // Link to Antrag genehmigen dashboard $url = @@ -514,8 +514,6 @@ html; 'vorname' => $stgl->vorname ); } - - return $stglMailAdress_arr; } // If not available, get assistance mail address else @@ -524,12 +522,13 @@ html; if (hasData($result)) { - return array( - $result->retval[0]->email, - '' + $stglMailAdress_arr[]= array( + 'to' => $result->retval[0]->email, + 'vorname' => '' ); } } + return $stglMailAdress_arr; } // Build HTML table with yesterdays new Anrechnungen of the given STG diff --git a/application/controllers/jobs/AntragJob.php b/application/controllers/jobs/AntragJob.php index 46a31f3d6..11b950174 100644 --- a/application/controllers/jobs/AntragJob.php +++ b/application/controllers/jobs/AntragJob.php @@ -183,8 +183,8 @@ class AntragJob extends JOB_Controller $data, $to, 'Anträge - Aktion(en) erforderlich', - DEFAULT_SANCHO_HEADER_IMG, - DEFAULT_SANCHO_FOOTER_IMG, + '', + '', '', $cc )) diff --git a/application/controllers/jobs/ReihungstestJob.php b/application/controllers/jobs/ReihungstestJob.php index b55287439..996354bb5 100644 --- a/application/controllers/jobs/ReihungstestJob.php +++ b/application/controllers/jobs/ReihungstestJob.php @@ -431,8 +431,8 @@ class ReihungstestJob extends JOB_Controller $mailcontent_data_arr, $applicant->email, 'Ihre Anmeldung zum Reihungstest - Reminder / Your registration for the placement test - Reminder', - DEFAULT_SANCHO_HEADER_IMG, - DEFAULT_SANCHO_FOOTER_IMG, + '', + '', $from, '', $bcc); diff --git a/application/helpers/hlp_sancho_helper.php b/application/helpers/hlp_sancho_helper.php index d599e40bc..9a32f5e1a 100644 --- a/application/helpers/hlp_sancho_helper.php +++ b/application/helpers/hlp_sancho_helper.php @@ -23,9 +23,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); // Functions needed in the view FHC-Header // ------------------------------------------------------------------------ -const DEFAULT_SANCHO_HEADER_IMG = 'sancho_header_DEFAULT.jpg'; -const DEFAULT_SANCHO_FOOTER_IMG = 'sancho_footer_DEFAULT.jpg'; - /** * Send single Mail with Sancho Design and Layout. * @param string $vorlage_kurzbz Name of the template for specific mail content. @@ -38,27 +35,88 @@ const DEFAULT_SANCHO_FOOTER_IMG = 'sancho_footer_DEFAULT.jpg'; * @param string $bcc Sets BCC of mail. * @return void */ -function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerImg = DEFAULT_SANCHO_HEADER_IMG, $footerImg = DEFAULT_SANCHO_FOOTER_IMG, $from = null, $cc = null, $bcc = null) +function sendSanchoMail( + $vorlage_kurzbz, + $vorlage_data, + $to, + $subject, + $headerImg = '', + $footerImg = '', + $from = null, + $cc = null, + $bcc = null +) { $ci =& get_instance(); $ci->load->library('email'); $ci->load->library('MailLib'); - $sanchoHeader_img = 'skin/images/sancho/'. $headerImg; - $sanchoFooter_img = 'skin/images/sancho/'. $footerImg; + $sancho_mail_config = $ci->config->item('mail'); + if ($from == '') { - $from = 'sancho@'.DOMAIN; + $from = ((isset($sancho_mail_config['sancho_mail_default_sender']) + && $sancho_mail_config['sancho_mail_default_sender']) + ? $sancho_mail_config['sancho_mail_default_sender'] + : 'noreply') + . '@' . DOMAIN; } // Embed sancho header and footer image // reset important to ensure embedding of images when called in a loop $ci->email->clear(true); // clear vars and attachments - $ci->email->attach($sanchoHeader_img); - $ci->email->attach($sanchoFooter_img); - $cid_header = $ci->email->attachment_cid($sanchoHeader_img); // sets unique content id for embedding - $cid_footer = $ci->email->attachment_cid($sanchoFooter_img); // sets unique content id for embedding + + $cid_header = ''; + $cid_footer = ''; + + if (isset($sancho_mail_config['sancho_mail_use_images']) && $sancho_mail_config['sancho_mail_use_images']) + { + $sanchoHeader_img = ''; + $sanchoFooter_img = ''; + + if (isset($headerImg) && $headerImg != '') + { + // use provided header image + $sanchoHeader_img = $headerImg; + } + elseif (isset($sancho_mail_config['sancho_mail_header_img']) && $sancho_mail_config['sancho_mail_header_img']) + { + // use default header image + $sanchoHeader_img = $sancho_mail_config['sancho_mail_header_img']; + } + + if (isset($footerImg) && $footerImg != '') + { + // use provided footer image + $sanchoFooter_img = $footerImg; + } + elseif (isset($sancho_mail_config['sancho_mail_footer_img']) && $sancho_mail_config['sancho_mail_footer_img']) + { + // use default footer image + $sanchoFooter_img = $sancho_mail_config['sancho_mail_footer_img']; + } + + // add image file paths + if (isset($sancho_mail_config['sancho_mail_img_path'])) + { + if ($sanchoHeader_img != '') + { + $sanchoHeader_img = $sancho_mail_config['sancho_mail_img_path'].$sanchoHeader_img; + } + + if ($sanchoFooter_img != '') + { + $sanchoFooter_img = $sancho_mail_config['sancho_mail_img_path'].$sanchoFooter_img; + } + } + + // attach header and footer + $ci->email->attach($sanchoHeader_img, 'inline'); + $ci->email->attach($sanchoFooter_img, 'inline'); + $cid_header = $ci->email->attachment_cid($sanchoHeader_img); // sets unique content id for embedding + $cid_footer = $ci->email->attachment_cid($sanchoFooter_img); // sets unique content id for embedding + } // Set specific mail content into specific content template $content = _parseMailContent($vorlage_kurzbz, $vorlage_data); @@ -74,7 +132,18 @@ function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerIm $body = _parseMailContent('Sancho_Mail_Template', $layout); // Send mail - return $ci->maillib->send($from, $to, $subject, $body, $alias = '', $cc, $bcc, $altMessage = '', $bulk = true, $autogenerated = true); + return $ci->maillib->send( + $from, + $to, + $subject, + $body, + '', // alias + $cc, + $bcc, + '', // altMessage + true, // bulk + true // autogenerated + ); } /** diff --git a/config/global.config-default.inc.php b/config/global.config-default.inc.php index 64d6d3a60..0d4158b48 100644 --- a/config/global.config-default.inc.php +++ b/config/global.config-default.inc.php @@ -338,4 +338,19 @@ define('DIENSTVERHAELTNIS_SUPPORT', false); // Falls Studstatus (Abmeldung, AbmeldungStg, Unterbrechung, Wiederholung) verwendet wird zeige Hinweistext bei Eingabe einer kommissionellen oder zusaetzlichen kommissionellen Pruefung define('FAS_STUDSTATUS_SHOW_KOMM_PRFG_HINT', false); + +// default absender (@DOMAIN wird hinzugefuegt daher ohne angeben) +define('SANCHO_MAIL_DEFAULT_SENDER', 'noreply'); + +// header und footer Bilder für eigene Mails verwenden +define('SANCHO_MAIL_USE_IMAGES', true); + +// Pfad für Bilder für eigene Mails, relativ zu document root +define('SANCHO_MAIL_IMG_PATH', 'skin/images/sancho/'); + +// header Bild für eigene Mails +define('SANCHO_MAIL_HEADER_IMG', 'sancho_header_DEFAULT.jpg'); + +// footer image for eigene Mails +define('SANCHO_MAIL_FOOTER_IMG', 'sancho_footer_DEFAULT.jpg'); ?> diff --git a/include/sancho.inc.php b/include/sancho.inc.php index 5fc6fcdab..4da3768b5 100644 --- a/include/sancho.inc.php +++ b/include/sancho.inc.php @@ -18,12 +18,13 @@ * * Authors: Cristina Hainberger */ + +require_once(dirname(__FILE__).'/../config/global.config.inc.php'); require_once(dirname(__FILE__).'/basis_db.class.php'); require_once(dirname(__FILE__).'/mail.class.php'); require_once(dirname(__FILE__).'/vorlage.class.php'); -const DEFAULT_SANCHO_HEADER_IMG = 'sancho_header_DEFAULT.jpg'; -const DEFAULT_SANCHO_FOOTER_IMG = 'sancho_footer_DEFAULT.jpg'; +const FALLBACK_SENDER = 'noreply'; /** * Send single Mail with Sancho Design and Layout. @@ -32,22 +33,66 @@ const DEFAULT_SANCHO_FOOTER_IMG = 'sancho_footer_DEFAULT.jpg'; * to be replaced in the content template. * @param string $to Email-adress. * @param string $subject Subject of mail. - * @param string $headerImg Filename of the specific Sancho header image. - * @param string $footerImg + * @param string $headerImg Filename of the specific Sancho header image, false if no header image + * @param string $footerImg - false if no footer image * @param string $replyTo default Email-adress for reply. * @param string | array $cc * @return boolean True, if succeeded. */ -function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerImg = DEFAULT_SANCHO_HEADER_IMG, $footerImg = DEFAULT_SANCHO_FOOTER_IMG, $replyTo = '', $cc = '') -{ - $from = 'sancho@'. DOMAIN; - $sanchoHeader_img = dirname(__FILE__). '/../skin/images/sancho/'. $headerImg; - $sanchoFooter_img = dirname(__FILE__). '/../skin/images/sancho/'. $footerImg; +function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerImg = '', $footerImg = '', $replyTo = '', $cc = '') +{ + $from = ((defined('SANCHO_MAIL_DEFAULT_SENDER') && SANCHO_MAIL_DEFAULT_SENDER != '') + ? SANCHO_MAIL_DEFAULT_SENDER + : FALLBACK_SENDER) + . '@' . DOMAIN; + + $image_path_prefix = dirname(__DIR__).'/'.(defined('SANCHO_MAIL_IMG_PATH') ? SANCHO_MAIL_IMG_PATH : ''); + $sanchoHeader_img = ''; + $sanchoFooter_img = ''; + $cid_header = ''; + $cid_footer = ''; + + if (!defined('SANCHO_MAIL_USE_IMAGES') || SANCHO_MAIL_USE_IMAGES) + { + if (isset($headerImg) && $headerImg != '') + { + // use provided header image + $sanchoHeader_img = $headerImg; + } + elseif (defined('SANCHO_MAIL_HEADER_IMG') && SANCHO_MAIL_HEADER_IMG != '') + { + // use default header image + $sanchoHeader_img = SANCHO_MAIL_HEADER_IMG; + } + + if ($sanchoHeader_img != '') + { + // set full image path + $sanchoHeader_img = $image_path_prefix.$sanchoHeader_img; + } + + if (isset($footerImg) && $footerImg != '') + { + // use provided footer image + $sanchoFooter_img = $footerImg; + } + elseif (defined('SANCHO_MAIL_FOOTER_IMG') && SANCHO_MAIL_FOOTER_IMG != '') + { + // use default footer image + $sanchoFooter_img = SANCHO_MAIL_FOOTER_IMG; + } + + if ($sanchoFooter_img !== '') + { + // set full image path + $sanchoFooter_img = $image_path_prefix.$sanchoFooter_img; + } + + // Set unique content id for embedding header and footer image + $cid_header = uniqid(); + $cid_footer = uniqid(); + } - // Set unique content id for embedding header and footer image - $cid_header = uniqid(); - $cid_footer = uniqid(); - // Set specific mail content into specific content template $content = parseMailContent($vorlage_kurzbz, $vorlage_data); @@ -63,22 +108,22 @@ function sendSanchoMail($vorlage_kurzbz, $vorlage_data, $to, $subject, $headerIm // Send mail $mail = new Mail($to, $from, $subject, $body); - - // * embed the images - $mail->addEmbeddedImage($sanchoHeader_img, 'image/jpg', '', $cid_header); - $mail->addEmbeddedImage($sanchoFooter_img, 'image/jpg', '', $cid_footer); + + // * embed the images if needed + if ($sanchoHeader_img != '') $mail->addEmbeddedImage($sanchoHeader_img, 'image/jpg', '', $cid_header); + if ($sanchoFooter_img != '') $mail->addEmbeddedImage($sanchoFooter_img, 'image/jpg', '', $cid_footer); // * Set reply-to if (isset($replyTo) && $replyTo != '') $mail->setReplyTo($replyTo); - + // * Set cc if (isset($cc) && $cc != '') $mail->setCCRecievers($cc); // * embed the html content $mail->setHTMLContent($body); - + return $mail->send(); } @@ -95,7 +140,7 @@ function parseMailContent($vorlage_kurzbz, $vorlage_data) { $vorlage = new Vorlage(); $vorlage->getAktuelleVorlage('etw', $vorlage_kurzbz); - + // If the text and the subject of the template are not empty if (!empty($vorlage->text)) {