diff --git a/modules/smtp/actions.php b/modules/smtp/actions.php index 9a9cd1669..dc9e99cbb 100644 --- a/modules/smtp/actions.php +++ b/modules/smtp/actions.php @@ -36,6 +36,16 @@ switch (post('op')) { } $_SESSION['infos'][] = tr('Informazioni salvate correttamente!'); + + //validazione indirizzo email mittente. + $check_email = Validate::isValidEmail($post['from_address'],1,1); + //print_r($check_email); + //exit(); + //se $check_email non è null, l'indirizzo email è settato e la riposta è negativa --> mostro il messaggio di avviso. + if ((!is_null($check_email)) and (!$check_email->smtp_check) and (!empty($post['from_address']))){ + $_SESSION['errors'][] = tr('Attenzione questo indirizzo non sembra essere valido: ').$post['from_address']; + } + break; diff --git a/modules/smtp/add.php b/modules/smtp/add.php index ba8a7affe..9724ec638 100644 --- a/modules/smtp/add.php +++ b/modules/smtp/add.php @@ -18,7 +18,7 @@ include_once __DIR__.'/../../core.php';
- {[ "type": "email", "label": "", "name": "from_address" ]} + {[ "type": "email", "label": "", "name": "from_address", "required": 1 ]}
diff --git a/modules/smtp/edit.php b/modules/smtp/edit.php index cf64baa38..3472e7478 100644 --- a/modules/smtp/edit.php +++ b/modules/smtp/edit.php @@ -34,7 +34,7 @@ include_once __DIR__.'/../../core.php';
- {[ "type": "email", "label": "", "name": "from_address", "value": "$from_address$" ]} + {[ "type": "email", "label": "", "name": "from_address", "value": "$from_address$", "required": 1 ]}
diff --git a/src/Validate.php b/src/Validate.php new file mode 100644 index 000000000..0ca98933a --- /dev/null +++ b/src/Validate.php @@ -0,0 +1,94 @@ + NULL, + 'mx_found' => NULL, + 'smtp_check' => NULL, + ];*/ + + if ((!empty($email)) and (!empty($access_key))){ + + $ch = curl_init(); + + $qs = "&email=" . urlencode($email); + $qs .= "&smtp=$smtp"; + $qs .= "&format=$format"; + + $url = "http://apilayer.net/api/check?access_key=$access_key" . $qs; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + + $data = json_decode(curl_exec($ch)); + curl_close($ch); + + /*se la riposta è null verficando il formato, il record mx o il server smtp imposto a false*/ + if (($data->format_valid==null)and($format)) + $data->format_valid = 0; + + if (($data->mx_found==null)and($smtp)) + $data->mx_found = 0; + + if (($data->smtp_check==null)and($smtp)) + $data->smtp_check = 0; + + + /*controllo o meno smtp + if ($data->smtp_check==false) + $data->smtp_check = 0; + + if ($data->mx_found==false) + $data->mx_found = 0; + */ + /* --- */ + + /*echo "format_valid: ".$data->format_valid; + echo "
\n"; + echo "smtp_check: ".$data->smtp_check; + echo "
\n"; + echo "mx_found: ".$data->mx_found;*/ + + //echo json_last_error(); + //echo json_last_error_msg(); + + + + } + + + /*return [ + 'email' => $email, + 'format_valid' => $data->format_valid, + 'smtp_check' => $data->smtp_check, + 'mx_found' => $data->mx_found, + 'json_last_error_msg' => json_last_error_msg(), + 'json_last_error' => json_last_error(), + ];*/ + + return $data; + + + } +} diff --git a/update/2_4.sql b/update/2_4.sql index f799fcb48..4f596e244 100644 --- a/update/2_4.sql +++ b/update/2_4.sql @@ -268,3 +268,6 @@ INSERT INTO `zz_emails` (`id`, `id_module`, `id_smtp`, `name`, `icon`, `subject` INSERT INTO `zz_email_print` (`id`, `id_email`, `id_print`) VALUES (NULL, (SELECT `id` FROM `zz_emails` WHERE `name` = 'Consuntivo' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Contratti')), (SELECT `id` FROM `zz_prints` WHERE `name` = 'Consuntivo contratto')), (NULL, (SELECT `id` FROM `zz_emails` WHERE `name` = 'Consuntivo' AND `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Preventivi')), (SELECT `id` FROM `zz_prints` WHERE `name` = 'Consuntivo preventivo')); + +-- apilayer API key (per validazione email, piva, indirizzo ecc...) +INSERT INTO `zz_settings` (`idimpostazione`, `nome`, `valore`, `tipo`, `editable`, `sezione`) VALUES (NULL, 'apilayer API key', '', 'string', '1', 'Generali'); \ No newline at end of file