diff --git a/modules/smtp/actions.php b/modules/smtp/actions.php index 77205f9b2..2ec0be77e 100644 --- a/modules/smtp/actions.php +++ b/modules/smtp/actions.php @@ -38,18 +38,38 @@ switch (post('op')) { $_SESSION['infos'][] = tr('Informazioni salvate correttamente!'); // Validazione indirizzo email mittente - $check_email = Validate::isValidEmail($post['from_address'], 1, 1); + $check_email = Validate::isValidEmail($post['from_address'], 1, 0); + // Se $check_email non è null e la riposta è negativa --> mostro il messaggio di avviso. - if ((!is_null($check_email)) && (!$check_email->smtp_check)) { - if (!empty($check_email->error->info)) { - $_SESSION['errors'][] = $check_email->error->info; - } else { + if (!is_null($check_email)){ + + if ($check_email->format_valid) { + $_SESSION['infos'][] = tr('Sintassi email verificata.'); + } + else { $_SESSION['errors'][] = tr("Attenzione: l'indirizzo email _EMAIL_ sembra non essere valido", [ - '_EMAIL_' => $post['from_address'], - ]); + '_EMAIL_' => $check_email->email, + ]); + } + + if ($check_email->smtp) { + if ($check_email->smtp_check) { + $_SESSION['infos'][] = tr('SMTP email verificato.'); + } + elseif (!$check_email->smtp_check) { + $_SESSION['warnings'][] = tr('SMTP email non verificato.'); + } + else { + $_SESSION['errors'][] = tr("Attenzione: l'SMTP email _EMAIL_ sembra non essere valido", [ + '_EMAIL_' => $check_email->email, + ]); + } + } + + if (!empty($check_email->error->info)) { + $_SESSION['errors'][] = $check_email->error->info; } } - break; case 'delete': diff --git a/src/Validate.php b/src/Validate.php index a2e867af6..85e72a388 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -68,20 +68,38 @@ class Validate ];*/ if ((!empty($email)) && (!empty($access_key))) { - $ch = curl_init(); + + if(!function_exists("curl_init")) die("cURL extension is not installed"); $qs = '&email='.urlencode($email); $qs .= "&smtp=$smtp"; $qs .= "&format=$format"; + $qs .= "&resource=check_email"; - $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); + $url = "https://services.osmcloud.it/api/?token=$access_key".$qs; + + $curl_options = array( + CURLOPT_URL => $url, + CURLOPT_HEADER => 0, + CURLOPT_RETURNTRANSFER => TRUE, + CURLOPT_TIMEOUT => 0, + CURLOPT_SSL_VERIFYPEER => 0, + CURLOPT_FOLLOWLOCATION => TRUE, + CURLOPT_ENCODING => 'gzip,deflate', + ); - $data = json_decode(curl_exec($ch)); + $ch = curl_init(); + curl_setopt_array( $ch, $curl_options ); + $output = curl_exec( $ch ); curl_close($ch); + $data = json_decode($output,false); + + //var_dump ($data); + //echo "format_valid: ".$data->format_valid; + //echo $url; + //exit; + /*se la riposta è null verficando il formato, il record mx o il server smtp imposto la relativa proprietà dell'oggetto a 0*/ if (($data->format_valid == null) && ($format)) { $data->format_valid = 0; @@ -103,11 +121,13 @@ class Validate $data->mx_found = 0; */ /* --- */ - + $data->smtp = $smtp; + $data->json_last_error = json_last_error(); $data->json_last_error_msg = json_last_error_msg(); } + return $data; } }