759 lines
26 KiB
PHP
759 lines
26 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* Class skrbi za pošiljanje mailov
|
||
|
* @author Peter Hrvatin
|
||
|
* 22.8.2019
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
class MailAdapter{
|
||
|
|
||
|
private $ank_id = null;
|
||
|
|
||
|
private $settings = array();
|
||
|
private $mailModes = array(0=>'1ka', 1=>'google', 2=>'smtp');
|
||
|
private $mailMode = '1ka'; // 1ka, google, smtp
|
||
|
private $recipients = array();
|
||
|
|
||
|
/** Tip posiljanja
|
||
|
* "invitation" - email vabilo
|
||
|
* "alert" - email obvescanje (aktivacija ankete, zakljucena anketa, arhiv ankete...)
|
||
|
* "admin" - email povezan z administracijo (alerti za admine)
|
||
|
* "account" - email povezan z upravljanjem racuna (dodan dostop do anket...)
|
||
|
*/
|
||
|
private $type = '';
|
||
|
|
||
|
private $password_hash_key = '#&_ww.9$.1ka#"%o';
|
||
|
|
||
|
private $phpMailerClass;
|
||
|
|
||
|
/** Debugging
|
||
|
* 0 = off (for production use)
|
||
|
* 1 = client messages
|
||
|
* 2 = client and server messages
|
||
|
*/
|
||
|
private $phpMailerDebug = 0;
|
||
|
|
||
|
|
||
|
public function __construct($anketa=null, $type=''){
|
||
|
global $admin_type;
|
||
|
global $mysql_database_name;
|
||
|
|
||
|
// Nastavimo tip posiljanja
|
||
|
$this->type = $type;
|
||
|
|
||
|
// Inicializiramo phpMailer razred
|
||
|
$this->prepareMailer();
|
||
|
|
||
|
|
||
|
// Posiljanje iz ankete
|
||
|
if ((int)$anketa > 0){
|
||
|
|
||
|
$this->ank_id = $anketa;
|
||
|
|
||
|
// Pripravimo nastavitve za posiljanje ankete
|
||
|
$this->prepareSurveySettings();
|
||
|
}
|
||
|
// Splosno posiljanje (brez id-ja ankete)
|
||
|
else{
|
||
|
|
||
|
// Pripravimo splosne nastavitve aplikacije za posiljanje
|
||
|
$this->prepareGeneralSettings();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
// Pripravimo nastavitve posiljanja za doloceno anketo
|
||
|
private function prepareSurveySettings(){
|
||
|
global $admin_type;
|
||
|
global $mysql_database_name;
|
||
|
global $email_server_settings;
|
||
|
global $email_server_fromSurvey;
|
||
|
|
||
|
|
||
|
// Polovimo nastavitve ce obstajajo v bazi
|
||
|
SurveySetting::getInstance()->Init($this->ank_id);
|
||
|
$mail1kaSavedConfig = unserialize(SurveySetting::getInstance()->getSurveyMiscSetting('send_mail_config'));
|
||
|
$this->settings = is_array($mail1kaSavedConfig) ? $mail1kaSavedConfig : array();
|
||
|
|
||
|
|
||
|
// Nastavitve imamo ze shranjene v bazi - samo nastavimo ustrezen "mode"
|
||
|
if(!empty($this->settings)){
|
||
|
|
||
|
// Nastavimo "mode" posiljanja (1ka, gmail ali smtp)
|
||
|
$mailMode = (int)$this->settings['SMTPMailMode'];
|
||
|
|
||
|
if ($mailMode === 2){
|
||
|
$this->mailMode = 'smtp';
|
||
|
}
|
||
|
else if ($mailMode === 1){
|
||
|
$this->mailMode = 'google';
|
||
|
}
|
||
|
else{
|
||
|
$this->mailMode = '1ka';
|
||
|
}
|
||
|
|
||
|
|
||
|
// Password dekodiramo
|
||
|
if (isset($this->settings['1ka']['SMTPPassword'])){
|
||
|
$this->settings['1ka']['SMTPPassword'] = $this->decryptPassword($this->settings['1ka']['SMTPPassword']);
|
||
|
}
|
||
|
if (isset($this->settings['google']['SMTPPassword'])){
|
||
|
$this->settings['google']['SMTPPassword'] = $this->decryptPassword($this->settings['google']['SMTPPassword']);
|
||
|
}
|
||
|
if (isset($this->settings['smtp']['SMTPPassword'])){
|
||
|
$this->settings['smtp']['SMTPPassword'] = $this->decryptPassword($this->settings['smtp']['SMTPPassword']);
|
||
|
}
|
||
|
|
||
|
|
||
|
// Pri 1ka nastavitvah lahko nastavljamo samo reply to, vse ostalo je veedno default
|
||
|
if($this->settings['1ka']['SMTPReplyTo'] == '')
|
||
|
$this->settings['1ka']['SMTPReplyTo'] = $email_server_settings['SMTPReplyTo'];
|
||
|
|
||
|
$this->settings['1ka']['SMTPFrom'] = $email_server_settings['SMTPFrom'];
|
||
|
$this->settings['1ka']['SMTPFromNice'] = $email_server_settings['SMTPFromNice'];
|
||
|
$this->settings['1ka']['SMTPHost'] = $email_server_settings['SMTPHost'];
|
||
|
$this->settings['1ka']['SMTPPort'] = $email_server_settings['SMTPPort'];
|
||
|
|
||
|
if(isset($email_server_settings['SMTPAuth']) && $email_server_settings['SMTPAuth'] == 1){
|
||
|
$this->settings['1ka']['SMTPAuth'] = $email_server_settings['SMTPAuth'];
|
||
|
$this->settings['1ka']['SMTPUsername'] = $email_server_settings['SMTPUsername'];
|
||
|
$this->settings['1ka']['SMTPPassword'] = $email_server_settings['SMTPPassword'];
|
||
|
}
|
||
|
|
||
|
if(isset($email_server_settings['SMTPSecure']))
|
||
|
$this->settings['1ka']['SMTPSecure'] = $email_server_settings['SMTPSecure'];
|
||
|
|
||
|
// Pri google smtp je username vedno email
|
||
|
if($this->mailMode == 'google')
|
||
|
$this->settings['google']['SMTPUsername'] = $this->settings['google']['SMTPFrom'];
|
||
|
|
||
|
// ce posiljamo mail vabila in smo na www.1ka.si oz. virutalkah in smo admin - posiljamo preko sekundarnega maila (raziskave@1ka.si)
|
||
|
if($this->type == 'invitation' && $admin_type == 0 && isset($email_server_settings['secondary_mail'])){
|
||
|
$this->settings['1ka']['SMTPFrom'] = $email_server_settings['secondary_mail']['SMTPFrom'];
|
||
|
$this->settings['1ka']['SMTPFromNice'] = $email_server_settings['secondary_mail']['SMTPFromNice'];
|
||
|
$this->settings['1ka']['SMTPReplyTo'] = $email_server_settings['secondary_mail']['SMTPReplyTo'];
|
||
|
$this->settings['1ka']['SMTPUsername'] = $email_server_settings['secondary_mail']['SMTPUsername'];
|
||
|
$this->settings['1ka']['SMTPPassword'] = $email_server_settings['secondary_mail']['SMTPPassword'];
|
||
|
}
|
||
|
}
|
||
|
// Nimamo se nicesar v bazi - nastavimo default nastavitve
|
||
|
else{
|
||
|
|
||
|
// Nastavimo 1ka smtp
|
||
|
$this->settings['1ka']['SMTPFrom'] = $email_server_settings['SMTPFrom'];
|
||
|
$this->settings['1ka']['SMTPFromNice'] = $email_server_settings['SMTPFromNice'];
|
||
|
$this->settings['1ka']['SMTPReplyTo'] = $email_server_settings['SMTPReplyTo'];
|
||
|
$this->settings['1ka']['SMTPHost'] = $email_server_settings['SMTPHost'];
|
||
|
$this->settings['1ka']['SMTPPort'] = $email_server_settings['SMTPPort'];
|
||
|
|
||
|
if(isset($email_server_settings['SMTPAuth']) && $email_server_settings['SMTPAuth'] == 1){
|
||
|
$this->settings['1ka']['SMTPAuth'] = $email_server_settings['SMTPAuth'];
|
||
|
$this->settings['1ka']['SMTPUsername'] = $email_server_settings['SMTPUsername'];
|
||
|
$this->settings['1ka']['SMTPPassword'] = $email_server_settings['SMTPPassword'];
|
||
|
}
|
||
|
|
||
|
if(isset($email_server_settings['SMTPSecure']))
|
||
|
$this->settings['1ka']['SMTPSecure'] = $email_server_settings['SMTPSecure'];
|
||
|
|
||
|
|
||
|
// Nastavimo gmail smtp
|
||
|
$this->settings['google']['SMTPHost'] = 'smtp.gmail.com';
|
||
|
$this->settings['google']['SMTPPort'] = '587';
|
||
|
$this->settings['google']['SMTPSecure'] = 'tls';
|
||
|
$this->settings['google']['SMTPAuth'] = 1;
|
||
|
|
||
|
|
||
|
// Ce imamo nastavljeno, da se za posiljanje iz ankete uporabi isti smtp streznik kot za generalno posiljanje
|
||
|
if($email_server_fromSurvey){
|
||
|
$this->prepareGeneralSettings();
|
||
|
}
|
||
|
else{
|
||
|
|
||
|
// ce posiljamo mail vabila (default razlicno za admine in ostale)
|
||
|
if($this->type == 'invitation'){
|
||
|
|
||
|
// Pri vabilih je default 1ka streznik samo na www.1ka.si in to samo za admine
|
||
|
if($admin_type == 0 && isset($email_server_settings['secondary_mail'])){
|
||
|
$this->mailMode = '1ka';
|
||
|
$this->settings['1ka']['SMTPFrom'] = $email_server_settings['secondary_mail']['SMTPFrom'];
|
||
|
$this->settings['1ka']['SMTPFromNice'] = $email_server_settings['secondary_mail']['SMTPFromNice'];
|
||
|
$this->settings['1ka']['SMTPReplyTo'] = $email_server_settings['secondary_mail']['SMTPReplyTo'];
|
||
|
$this->settings['1ka']['SMTPUsername'] = $email_server_settings['secondary_mail']['SMTPUsername'];
|
||
|
$this->settings['1ka']['SMTPPassword'] = $email_server_settings['secondary_mail']['SMTPPassword'];
|
||
|
}
|
||
|
// Drugace je potrebno nastaviti smtp
|
||
|
else{
|
||
|
$this->mailMode = 'smtp';
|
||
|
}
|
||
|
}
|
||
|
// Ce ne gre za vabila se uporabi kar 1ka streznik
|
||
|
else{
|
||
|
//$this->prepareGeneralSettings();
|
||
|
$this->mailMode = '1ka';
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Pripravimo nastavitve splosnega posiljanja v aplikaciji glede na nastavitve v settings_optional.php
|
||
|
private function prepareGeneralSettings(){
|
||
|
global $email_server_settings;
|
||
|
|
||
|
$this->mailMode = 'smtp';
|
||
|
$this->settings['SMTPMailMode'] = 2;
|
||
|
|
||
|
$this->settings['smtp'] = array(
|
||
|
'SMTPFrom' => $email_server_settings['SMTPFrom'],
|
||
|
'SMTPFromNice' => $email_server_settings['SMTPFromNice'],
|
||
|
'SMTPReplyTo' => $email_server_settings['SMTPReplyTo'],
|
||
|
|
||
|
'SMTPHost' => $email_server_settings['SMTPHost'],
|
||
|
'SMTPPort' => $email_server_settings['SMTPPort']
|
||
|
);
|
||
|
|
||
|
if(isset($email_server_settings['SMTPAuth']) && $email_server_settings['SMTPAuth'] == 1){
|
||
|
$this->settings['smtp']['SMTPAuth'] = $email_server_settings['SMTPAuth'];
|
||
|
$this->settings['smtp']['SMTPUsername'] = $email_server_settings['SMTPUsername'];
|
||
|
$this->settings['smtp']['SMTPPassword'] = $email_server_settings['SMTPPassword'];
|
||
|
}
|
||
|
|
||
|
if(isset($email_server_settings['SMTPSecure']))
|
||
|
$this->settings['smtp']['SMTPSecure'] = $email_server_settings['SMTPSecure'];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public function is1KA () {
|
||
|
return $this->mailMode == '1ka';
|
||
|
}
|
||
|
public function isGoogle () {
|
||
|
return $this->mailMode == 'google';
|
||
|
}
|
||
|
public function isSMTP () {
|
||
|
return $this->mailMode == 'smtp';
|
||
|
}
|
||
|
|
||
|
// Vrnemo nastavitve posiljanja za dolocen mode
|
||
|
public function getSettings($mailModeString = null){
|
||
|
|
||
|
// Pogledamo za kateri "mode" pridobivamo nastavitve
|
||
|
if ($mailModeString == null){
|
||
|
$mailModeString = $this->getMailMode($asString=true);
|
||
|
}
|
||
|
$result = $this->settings[$mailModeString];
|
||
|
|
||
|
if(isset($result) && is_array($result))
|
||
|
return $result;
|
||
|
else
|
||
|
return array();
|
||
|
}
|
||
|
|
||
|
// Vrnemo nastavitve posiljanja na podlagi requesta
|
||
|
public function getSettingsFromRequest($request){
|
||
|
|
||
|
$settings = array();
|
||
|
|
||
|
$mode = $request['SMTPMailMode'];
|
||
|
|
||
|
foreach ($request AS $pkey => $pvalue){
|
||
|
|
||
|
// if starts with SMTP && END WITH $_REQUEST['send_mail_mode']
|
||
|
if (!strncmp($pkey, "SMTP", strlen("SMTP")) && substr($pkey, -strlen($mode))===$mode){
|
||
|
$settings[rtrim($pkey, "{$mode}")] = $pvalue;
|
||
|
}
|
||
|
}
|
||
|
$settings['SMTPMailMode'] = $mode;
|
||
|
|
||
|
return $settings;
|
||
|
}
|
||
|
|
||
|
// Vrnemo nastavitev from (email)
|
||
|
public function getMailFrom(){
|
||
|
$s = $this->getSettings();
|
||
|
return $s['SMTPFrom'];
|
||
|
}
|
||
|
|
||
|
// Vrnemo nastavitev from (ime)
|
||
|
public function getMailFromNice(){
|
||
|
$s = $this->getSettings();
|
||
|
return $s['SMTPFromNice'];
|
||
|
}
|
||
|
|
||
|
// Vrnemo reply-to nastavitev
|
||
|
public function getMailReplyTo(){
|
||
|
$s = $this->getSettings();
|
||
|
return $s['SMTPReplyTo'];
|
||
|
}
|
||
|
|
||
|
|
||
|
// Vrnemo nastavitev mode-a posiljanja (1ka, google ali smtp)
|
||
|
public function getMailMode($asString=false){
|
||
|
|
||
|
if ($asString)
|
||
|
return $this->mailMode;
|
||
|
else
|
||
|
return (int)array_search($this->mailMode, $this->mailModes);
|
||
|
}
|
||
|
|
||
|
|
||
|
// Vrnemo nastavitve za dolocen mode
|
||
|
public function get1KASettings(){
|
||
|
|
||
|
$result = $this->settings['1ka'];
|
||
|
|
||
|
if(isset($result) && is_array($result))
|
||
|
return $result;
|
||
|
else
|
||
|
return array();
|
||
|
}
|
||
|
|
||
|
public function getGoogleSettings(){
|
||
|
|
||
|
$result = $this->settings['google'];
|
||
|
|
||
|
if(isset($result) && is_array($result))
|
||
|
return $result;
|
||
|
else
|
||
|
return array();
|
||
|
}
|
||
|
|
||
|
public function getSMTPSettings(){
|
||
|
|
||
|
$result = $this->settings['smtp'];
|
||
|
|
||
|
if(isset($result) && is_array($result))
|
||
|
return $result;
|
||
|
else
|
||
|
return array();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
// Nastavimo nastavitve za dolocen "mode" in jih shranimo v bazo
|
||
|
public function setSettings($mode, $settings){
|
||
|
|
||
|
foreach ($settings AS $key => $value){
|
||
|
|
||
|
if ( $key == 'SMTPMailMode' ){
|
||
|
$this->settings[$key] = $value;
|
||
|
}
|
||
|
|
||
|
// geslo shranimo samo če ni null
|
||
|
else if ( $key != 'SMTPPassword' || ($key == 'SMTPPassword' && !empty($value)) ){
|
||
|
|
||
|
$this->settings[$this->mailModes[(int)$mode]][$key] = $value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$this->saveSettings();
|
||
|
}
|
||
|
|
||
|
// Shranimo nastavitve v bazo
|
||
|
private function saveSettings(){
|
||
|
|
||
|
$settings = $this->settings;
|
||
|
|
||
|
// Passworde zakodiramo pred shranjevanjem v bazo
|
||
|
if (isset($settings['1ka']['SMTPPassword'])){
|
||
|
$settings['1ka']['SMTPPassword'] = $this->encryptPassword($settings['1ka']['SMTPPassword']);
|
||
|
}
|
||
|
if (isset($settings['google']['SMTPPassword'])){
|
||
|
$settings['google']['SMTPPassword'] = $this->encryptPassword($settings['google']['SMTPPassword']);
|
||
|
}
|
||
|
if (isset($settings['smtp']['SMTPPassword'])){
|
||
|
$settings['smtp']['SMTPPassword'] = $this->encryptPassword($settings['smtp']['SMTPPassword']);
|
||
|
}
|
||
|
|
||
|
$c = mysqli_real_escape_string($GLOBALS['connect_db'], serialize($settings));
|
||
|
$succ = SurveySetting::getInstance()->setSurveyMiscSetting('send_mail_config', $c);
|
||
|
}
|
||
|
|
||
|
// Nastavimo reply to mail
|
||
|
public function setMailReplyTo($reply_to){
|
||
|
|
||
|
if($this->validEmail($reply_to)){
|
||
|
$s = $this->getSettings();
|
||
|
$s['SMTPReplyTo'] = $reply_to;
|
||
|
|
||
|
$this->setSettings((int)$this->settings['SMTPMailMode'], $s);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Nastavimo from ime
|
||
|
public function setMailFromNice($from_nice){
|
||
|
|
||
|
$s = $this->getSettings();
|
||
|
$s['SMTPFromNice'] = $from_nice;
|
||
|
|
||
|
$this->setSettings((int)$this->settings['SMTPMailMode'], $s);
|
||
|
}
|
||
|
|
||
|
// Nastavimo from email
|
||
|
public function setMailFrom($from){
|
||
|
|
||
|
if($this->validEmail($from)){
|
||
|
$s = $this->getSettings();
|
||
|
$s['SMTPFrom'] = $from;
|
||
|
|
||
|
$this->setSettings((int)$this->settings['SMTPMailMode'], $s);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
// Dodamo respondenta emaila
|
||
|
public function addRecipients($recipient){
|
||
|
|
||
|
// Ce imamo vec prejemnikov
|
||
|
if(is_array($recipient)){
|
||
|
|
||
|
foreach($recipient as $email){
|
||
|
if ($this->validEmail($email))
|
||
|
$this->recipients[] = $email;
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
if ($this->validEmail($recipient))
|
||
|
$this->recipients[] = $recipient;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Dodamo attachment
|
||
|
public function addAttachment($file, $file_name){
|
||
|
|
||
|
$this->phpMailerClass->addStringAttachment($file, $file_name);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
// Inicializiramo phpmailer razred in nastavimo splosne nastavitve
|
||
|
private function prepareMailer(){
|
||
|
|
||
|
// Inicializiramo razred
|
||
|
$this->phpMailerClass = new PHPMailer\PHPMailer\PHPMailer();
|
||
|
|
||
|
// Nastavimo se debugging
|
||
|
$this->phpMailerClass->SMTPDebug = $this->phpMailerDebug;
|
||
|
|
||
|
|
||
|
// UTF8 encoding
|
||
|
$this->phpMailerClass->CharSet = 'UTF-8';
|
||
|
|
||
|
// Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
|
||
|
$this->phpMailerClass->Priority = 3;
|
||
|
|
||
|
// 8-bit encoding
|
||
|
//$this->phpMailerClass->Encoding = '8bit';
|
||
|
|
||
|
// RFC 2822 Compliant for Max 998 characters per line
|
||
|
$this->phpMailerClass->WordWrap = 900;
|
||
|
|
||
|
//$this->phpMailerClass->Helo = $settings["ServerHostname"];
|
||
|
|
||
|
|
||
|
// Vedno posiljamo preko smtp
|
||
|
$this->phpMailerClass->isSMTP();
|
||
|
}
|
||
|
|
||
|
// Posljemo mail
|
||
|
public function sendMail($email_msg, $email_subject){
|
||
|
global $mysql_database_name;
|
||
|
|
||
|
// Nastavimo ustrezen "mode"
|
||
|
$mailModeString = $this->mailMode;
|
||
|
|
||
|
// Dobimo nastavitve iz baze
|
||
|
$settings = $this->getSettings($mailModeString);
|
||
|
|
||
|
|
||
|
// Nastavimo mail server
|
||
|
$this->phpMailerClass->Host = $settings["SMTPHost"];
|
||
|
|
||
|
// Nastavimo SMTP port
|
||
|
$this->phpMailerClass->Port = $settings["SMTPPort"];
|
||
|
|
||
|
// Nastavimo ssl / tls
|
||
|
$this->phpMailerClass->SMTPSecure = $settings['SMTPSecure'];
|
||
|
|
||
|
// Nastavimo ce se uporablja SMTP avtentikacijo
|
||
|
if($settings["SMTPAuth"] == 1)
|
||
|
$this->phpMailerClass->SMTPAuth = true;
|
||
|
|
||
|
// Nastavimo username za SMTP avtentikacijo
|
||
|
$this->phpMailerClass->Username = $settings["SMTPUsername"];
|
||
|
|
||
|
// Nastavimo password za SMTP avtentikacijo
|
||
|
$this->phpMailerClass->Password = $settings["SMTPPassword"];
|
||
|
|
||
|
|
||
|
// Posebej vklopimo, ker drugace sisplet smtp ne deluje!
|
||
|
if($this->phpMailerClass->Host == 'mail.sisplet.org'){
|
||
|
$this->phpMailerClass->SMTPOptions = array(
|
||
|
'ssl' => array(
|
||
|
'verify_peer' => false
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
// Kdo posilja
|
||
|
if(isset($settings["SMTPFromNice"]) && $settings["SMTPFromNice"] != "") {
|
||
|
$this->phpMailerClass->SetFrom($settings["SMTPFrom"], $settings["SMTPFromNice"]);
|
||
|
}
|
||
|
else{
|
||
|
$this->phpMailerClass->SetFrom($settings["SMTPFrom"]);
|
||
|
}
|
||
|
|
||
|
// Reply-to naslov
|
||
|
$this->phpMailerClass->AddReplyTo($settings["SMTPReplyTo"]);
|
||
|
|
||
|
// Subject
|
||
|
$this->phpMailerClass->Subject = $email_subject;
|
||
|
|
||
|
// Vsebina maila
|
||
|
$this->phpMailerClass->msgHTML($email_msg);
|
||
|
|
||
|
|
||
|
// Loop cez prejemnike in posiljanje
|
||
|
if (!empty($this->recipients)){
|
||
|
|
||
|
// Loop cez vse prejemnike
|
||
|
foreach ($this->recipients AS $recipient){
|
||
|
$this->phpMailerClass->AddAddress($recipient);
|
||
|
}
|
||
|
|
||
|
// Posljemo mail
|
||
|
$success = $this->phpMailerClass->send();
|
||
|
|
||
|
|
||
|
// Logiramo posiljanje
|
||
|
$SL = new SurveyLog();
|
||
|
|
||
|
// Napaka
|
||
|
if (!$success) {
|
||
|
|
||
|
if((int)$this->ank_id > 0)
|
||
|
$SL->addMessage(SurveyLog::MAILER, "NAPAKA pri pošiljanju emaila iz ankete ".$this->ank_id." na naslove ".implode(",", $this->recipients)."! ".$this->phpMailerClass->ErrorInfo);
|
||
|
else
|
||
|
$SL->addMessage(SurveyLog::MAILER, "NAPAKA pri pošiljanju emaila na naslove ".implode(",", $this->recipients)."! ".$this->phpMailerClass->ErrorInfo);
|
||
|
|
||
|
if($this->phpMailerDebug > 0)
|
||
|
echo "<br />Mailer Error: " . $this->phpMailerClass->ErrorInfo.'<br /><br />';
|
||
|
}
|
||
|
// Uspesno posiljanje
|
||
|
else {
|
||
|
|
||
|
if((int)$this->ank_id > 0)
|
||
|
$SL->addMessage(SurveyLog::MAILER, "USPEŠNO pošiljanje emaila iz ankete ".$this->ank_id." na naslove ".implode(",", $this->recipients));
|
||
|
else
|
||
|
$SL->addMessage(SurveyLog::MAILER, "USPEŠNO pošiljanje emaila na naslove ".implode(",", $this->recipients));
|
||
|
|
||
|
if($this->phpMailerDebug > 0)
|
||
|
echo "Message sent!<br /><br />";
|
||
|
}
|
||
|
|
||
|
$SL->write();
|
||
|
|
||
|
|
||
|
// Dodamo pavzo po pošiljanju ce je nastavljena!
|
||
|
if (isset($settings['SMTPDelay']) && intval($settings['SMTPDelay']) > 0) {
|
||
|
usleep ($settings['SMTPDelay']);
|
||
|
}
|
||
|
|
||
|
return $success;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Posljemo testni mail pri testiranju nastavitev streznika
|
||
|
public function sendMailTest($email_msg, $email_subject, $mailMode=null, $settings=null){
|
||
|
global $mysql_database_name;
|
||
|
|
||
|
// Nastavimo ustrezen "mode"
|
||
|
$mailModeString = $this->mailModes[$mailMode];
|
||
|
|
||
|
|
||
|
// Ce gre za gmail ali 1ka napolnimo default podatke
|
||
|
if(!isset($settings["SMTPHost"]))
|
||
|
$settings["SMTPHost"] = $this->settings[$mailModeString]["SMTPHost"];
|
||
|
if(!isset($settings["SMTPPort"]))
|
||
|
$settings["SMTPPort"] = $this->settings[$mailModeString]["SMTPPort"];
|
||
|
if(!isset($settings["SMTPSecure"]))
|
||
|
$settings["SMTPSecure"] = $this->settings[$mailModeString]["SMTPSecure"];
|
||
|
if(!isset($settings["SMTPAuth"]))
|
||
|
$settings["SMTPAuth"] = $this->settings[$mailModeString]["SMTPAuth"];
|
||
|
|
||
|
if(!isset($settings["SMTPUsername"]))
|
||
|
$settings["SMTPUsername"] = $this->settings[$mailModeString]["SMTPUsername"];
|
||
|
if(!isset($settings["SMTPPassword"]))
|
||
|
$settings["SMTPPassword"] = $this->settings[$mailModeString]["SMTPPassword"];
|
||
|
|
||
|
// Pri google smtp je username vedno email
|
||
|
if($mailModeString == 'google')
|
||
|
$settings['SMTPUsername'] = $settings['SMTPFrom'];
|
||
|
|
||
|
|
||
|
// Nastavimo mail server
|
||
|
$this->phpMailerClass->Host = $settings["SMTPHost"];
|
||
|
|
||
|
// Nastavimo SMTP port
|
||
|
$this->phpMailerClass->Port = $settings["SMTPPort"];
|
||
|
|
||
|
// Nastavimo ssl / tls
|
||
|
$this->phpMailerClass->SMTPSecure = $settings['SMTPSecure'];
|
||
|
|
||
|
// Nastavimo ce se uporablja SMTP avtentikacijo
|
||
|
if($settings["SMTPAuth"] == 1)
|
||
|
$this->phpMailerClass->SMTPAuth = true;
|
||
|
|
||
|
// Nastavimo username za SMTP avtentikacijo
|
||
|
$this->phpMailerClass->Username = $settings["SMTPUsername"];
|
||
|
|
||
|
// Nastavimo password za SMTP avtentikacijo
|
||
|
$this->phpMailerClass->Password = $settings["SMTPPassword"];
|
||
|
|
||
|
|
||
|
// Posebej vklopimo, ker drugace sisplet smtp ne deluje!
|
||
|
if($this->phpMailerClass->Host == 'mail.sisplet.org'){
|
||
|
$this->phpMailerClass->SMTPOptions = array(
|
||
|
'ssl' => array(
|
||
|
'verify_peer' => false
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
// Kdo posilja
|
||
|
if(isset($settings["SMTPFromNice"]) && $settings["SMTPFromNice"] != "") {
|
||
|
$this->phpMailerClass->SetFrom($settings["SMTPFrom"], $settings["SMTPFromNice"]);
|
||
|
}
|
||
|
else{
|
||
|
$this->phpMailerClass->SetFrom($settings["SMTPFrom"]);
|
||
|
}
|
||
|
|
||
|
// Reply-to naslov
|
||
|
$this->phpMailerClass->AddReplyTo($settings["SMTPReplyTo"]);
|
||
|
|
||
|
// Subject
|
||
|
$this->phpMailerClass->Subject = $email_subject;
|
||
|
|
||
|
// Vsebina maila
|
||
|
$this->phpMailerClass->msgHTML($email_msg);
|
||
|
|
||
|
|
||
|
// Loop cez prejemnike in posiljanje
|
||
|
if (!empty($this->recipients)){
|
||
|
|
||
|
// Loop cez vse prejemnike
|
||
|
foreach ($this->recipients AS $recipient){
|
||
|
$this->phpMailerClass->AddAddress($recipient);
|
||
|
}
|
||
|
|
||
|
// Posljemo mail
|
||
|
$success = $this->phpMailerClass->send();
|
||
|
|
||
|
|
||
|
// Logiramo posiljanje
|
||
|
$SL = new SurveyLog();
|
||
|
|
||
|
// Napaka
|
||
|
if (!$success) {
|
||
|
|
||
|
if((int)$this->ank_id > 0)
|
||
|
$SL->addMessage(SurveyLog::MAILER, "NAPAKA pri pošiljanju pošiljanje testnega emaila na naslov ".implode(",", $this->recipients)."! ".$this->phpMailerClass->ErrorInfo);
|
||
|
|
||
|
//if($this->phpMailerDebug > 0)
|
||
|
echo "<br />Mailer Error: " . $this->phpMailerClass->ErrorInfo.'<br /><br />';
|
||
|
}
|
||
|
// Uspesno posiljanje
|
||
|
else {
|
||
|
|
||
|
$SL->addMessage(SurveyLog::MAILER, "USPEŠNO pošiljanje testnega emaila na naslov ".implode(",", $this->recipients));
|
||
|
|
||
|
if($this->phpMailerDebug > 0)
|
||
|
echo "Message sent!<br /><br />";
|
||
|
}
|
||
|
|
||
|
$SL->write();
|
||
|
|
||
|
|
||
|
return $success;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
// Preveri ce je mail veljaven
|
||
|
private function validEmail($email = null){
|
||
|
return Common::getInstance()->validEmail($email);
|
||
|
}
|
||
|
|
||
|
// Enkripcija gesla za mail streznik
|
||
|
private function encryptPassword($password){
|
||
|
|
||
|
// Kateri php modul uporabljamo (mcrypt ali openssl) - kasneje se bo vse preneslo na openssl
|
||
|
$php_encrypt_module = 'openssl';
|
||
|
|
||
|
// Star modul mcrypt, ki ni vec kompatibilen s php7.3
|
||
|
if($php_encrypt_module == 'mcrypt'){
|
||
|
|
||
|
$iv_size = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_ECB);
|
||
|
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
|
||
|
$encryptedPassword = mcrypt_encrypt(MCRYPT_CAST_256, $this->password_hash_key , $password, MCRYPT_MODE_ECB, $iv);
|
||
|
|
||
|
return $encryptedPassword;
|
||
|
}
|
||
|
// Prehod iz mcrypt na openssl - NI KOMPATIBILNO ZA NAZAJ! - DODATNO SE BASE_ENCODE
|
||
|
else{
|
||
|
|
||
|
|
||
|
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
||
|
$encryptedPassword = openssl_encrypt($password, 'AES-256-CBC', $this->password_hash_key, 0, $iv);
|
||
|
|
||
|
return base64_encode($encryptedPassword . '::' . $iv);
|
||
|
|
||
|
// Prehod iz mcrypt na openssl - NI KOMPATIBILNO ZA NAZAJ! - star openssl za gorenje
|
||
|
/*$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
||
|
$encryptedPassword = openssl_encrypt($password, 'AES-256-CBC', $this->password_hash_key, 0, $iv);
|
||
|
|
||
|
return $encryptedPassword . '::' . $iv;*/
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Dekripcija gesla za mail streznik
|
||
|
private function decryptPassword($encryptedPassword){
|
||
|
|
||
|
// Kateri php modul uporabljamo (mcrypt ali openssl) - kasneje se bo vse preneslo na openssl
|
||
|
$php_encrypt_module = 'openssl';
|
||
|
|
||
|
// Star modul mcrypt, ki ni vec kompatibilen s php7.3
|
||
|
if($php_encrypt_module == 'mcrypt'){
|
||
|
|
||
|
$iv_size = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_ECB);
|
||
|
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
|
||
|
$decryptedPassword = mcrypt_decrypt(MCRYPT_CAST_256, $this->password_hash_key , $encryptedPassword, MCRYPT_MODE_ECB, $iv);
|
||
|
|
||
|
return $decryptedPassword;
|
||
|
}
|
||
|
// Prehod iz mcrypt na openssl - NI KOMPATIBILNO ZA NAZAJ! - DODATNO SE BASE_ENCODE
|
||
|
else{
|
||
|
|
||
|
// Prehod iz mcrypt na openssl - NI KOMPATIBILNO ZA NAZAJ! - DODATNO SE BASE_DECODE
|
||
|
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
||
|
list($encrypted_data, $iv) = explode('::', base64_decode($encryptedPassword), 2);
|
||
|
$decryptedPassword = openssl_decrypt($encrypted_data, 'AES-256-CBC', $this->password_hash_key, 0, $iv);
|
||
|
|
||
|
return $decryptedPassword;
|
||
|
|
||
|
// Prehod iz mcrypt na openssl - NI KOMPATIBILNO ZA NAZAJ! - star openssl za gorenje
|
||
|
/*$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
||
|
list($encrypted_data, $iv) = explode('::', $encryptedPassword, 2);
|
||
|
$decryptedPassword = openssl_decrypt($encrypted_data, 'AES-256-CBC', $this->password_hash_key, 0, $iv);
|
||
|
|
||
|
return $decryptedPassword;*/
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|