name = 'Singletest'; $this->data = []; } public function defaultTask() { $this->layout = 'default'; $this->breadcrumb[__('Single test', 'acychecker')] = Url::completeLink('singletest'); $this->display(); } public function ajaxGetSingleTest(): void { $apiService = new ApiService(); $email = Security::getVar('string', 'email', ''); if (!empty($email)) { $user = new \stdClass(); $user->email = $email; $conditions = 'disposable,accept_all,domain_not_exists,free_domain,invalid_smtp,not_existing,role_based'; $result = $apiService->testUser($user, $conditions, true); } else { $result = []; } if (empty($result) || !is_array($result)) { Ajax::sendAjaxResponse(__('Could not call the api', 'acychecker'), [], false); return; } $this->data['tests'] = [ ApiService::API_TEST_KEY_VALID_ADDRESS => [ 'status' => $result[ApiService::API_TEST_KEY_VALID_ADDRESS] ? self::STATUS_SUCCESS : self::STATUS_INVALID, 'label' => $result[ApiService::API_TEST_KEY_VALID_ADDRESS] ? __('Valid email syntax', 'acychecker') : __('Invalid email syntax', 'acychecker'), 'description' => $result[ApiService::API_TEST_KEY_VALID_ADDRESS] ? __('The syntax of the email address is correct', 'acychecker') : __('The syntax of the email address is incorrect', 'acychecker'), ], ApiService::API_TEST_KEY_DOMAIN_EXISTS => [ 'status' => $result[ApiService::API_TEST_KEY_DOMAIN_EXISTS] ? self::STATUS_SUCCESS : self::STATUS_INVALID, 'label' => $result[ApiService::API_TEST_KEY_DOMAIN_EXISTS] ? __('The domain exists', 'acychecker') : __('The domain doesn\'t exist', 'acychecker'), 'description' => $result[ApiService::API_TEST_KEY_DOMAIN_EXISTS] ? __('The domain of the email address exists. It does not necessarily imply that the email address is valid.', 'acychecker') : __('This means that the domain doesn\'t exist and therefore the email address doesn\'t exist either. It is highly discouraged to send emails to addresses that don\'t exist as it impacts your IP reputation and mail clients may ultimately consider you as a spammer.', 'acychecker'), ], ]; if ($result[ApiService::API_TEST_KEY_EMAIL_EXISTS] === ApiService::TRUST_RESULT_VALID) { $this->data['tests'][ApiService::API_TEST_KEY_EMAIL_EXISTS] = [ 'status' => self::STATUS_SUCCESS, 'label' => __('The email address exists', 'acychecker'), 'description' => __('We asked via SMTP protocol if we can send an email to this email address and the server confirmed that the email address exists.', 'acychecker'), ]; } elseif ($result[ApiService::API_TEST_KEY_EMAIL_EXISTS] === ApiService::TRUST_RESULT_POSSIBLE) { $this->data['tests'][ApiService::API_TEST_KEY_EMAIL_EXISTS] = [ 'status' => self::STATUS_SUCCESS, 'label' => __('The email address probably exists', 'acychecker'), 'description' => __('The domain exists but its server didn\'t answer when we asked if the address exists, or the domain is an accept all.', 'acychecker'), ]; } elseif ($result[ApiService::API_TEST_KEY_EMAIL_EXISTS] === ApiService::TRUST_RESULT_RISKY) { $this->data['tests'][ApiService::API_TEST_KEY_EMAIL_EXISTS] = [ 'status' => self::STATUS_WARNING, 'label' => __('The address most likely doesn\'t exist', 'acychecker'), 'description' => __('The domain exists but we couldn\'t contact it, or it is a disposable address service.', 'acychecker'), ]; } else { $this->data['tests'][ApiService::API_TEST_KEY_EMAIL_EXISTS] = [ 'status' => self::STATUS_INVALID, 'label' => __('The email address doesn\'t exist', 'acychecker'), 'description' => __('This means that the email address doesn\'t exist. We couldn\'t contact the SMTP server of the domain, the domain doesn\'t exist or the domain told us that the email address doesn\'t exist.', 'acychecker'), ]; } if ($result[ApiService::API_TEST_KEY_DOMAIN_EXISTS]) { $this->data['tests'][ApiService::API_TEST_KEY_DISPOSABLE] = [ 'status' => $result[ApiService::API_TEST_KEY_DISPOSABLE] ? self::STATUS_WARNING : self::STATUS_INFO, 'label' => $result[ApiService::API_TEST_KEY_DISPOSABLE] ? __('It is a disposable address', 'acychecker') : __('It is not a disposable address', 'acychecker'), 'description' => __('A disposable email address is temporary. It\'s convenient for people who don\'t want to give their real email address on a website. For your email marketing it isn\'t great as you send emails to non-existing users.', 'acychecker'), ]; $this->data['tests'][ApiService::API_TEST_KEY_FREE_MAILBOX] = [ 'status' => self::STATUS_INFO, 'label' => $result[ApiService::API_TEST_KEY_FREE_MAILBOX] ? __('It is a free email address', 'acychecker') : __('It is a paid email address', 'acychecker'), 'description' => __('A free email address has been created on a free service like Gmail or Yahoo for example. There are no cons on your side if you want to send marketing emails to them.', 'acychecker'), ]; $this->data['tests'][ApiService::API_TEST_KEY_ROLE_BASED] = [ 'status' => self::STATUS_INFO, 'label' => $result[ApiService::API_TEST_KEY_ROLE_BASED] ? __('It is a role based address', 'acychecker') : __('It isn\'t a role based address', 'acychecker'), 'description' => __('Role-based email addresses are addresses that do not belong to a specific user but more to a role, for example support@example.com is a role-based email address. These addresses can be shared by multiple people.', 'acychecker'), ]; $this->data['tests'][ApiService::API_TEST_KEY_ACCEPT_ALL] = [ 'status' => self::STATUS_INFO, 'label' => $result[ApiService::API_TEST_KEY_ACCEPT_ALL] ? __('It is an accept all domain', 'acychecker') : __('It isn\'t an accept all domain', 'acychecker'), 'description' => __('An accept all domain means that all email addresses on that domain will work. Your emails will be sent correctly but there are potentially no one receiving them.', 'acychecker'), ]; } else { $this->data['tests'][ApiService::API_TEST_KEY_DISPOSABLE] = [ 'status' => self::STATUS_NOT_TESTED, 'label' => __('Disposable', 'acychecker'), 'description' => __('A disposable email address is temporary. It\'s convenient for people who don\'t want to give their real email address on a website. For your email marketing it isn\'t great as you send emails to non-existing users.', 'acychecker'), ]; $this->data['tests'][ApiService::API_TEST_KEY_FREE_MAILBOX] = [ 'status' => self::STATUS_NOT_TESTED, 'label' => __('Free email address', 'acychecker'), 'description' => __('A free email address has been created on a free service like Gmail or Yahoo for example. There are no cons on your side if you want to send marketing emails to them.', 'acychecker'), ]; $this->data['tests'][ApiService::API_TEST_KEY_ROLE_BASED] = [ 'status' => self::STATUS_NOT_TESTED, 'label' => __('Role based email address', 'acychecker'), 'description' => __('Role-based email addresses are addresses that do not belong to a specific user but more to a role, for example support@example.com is a role-based email address. These addresses can be shared by multiple people.', 'acychecker'), ]; $this->data['tests'][ApiService::API_TEST_KEY_ACCEPT_ALL] = [ 'status' => self::STATUS_NOT_TESTED, 'label' => __('Accept all domain', 'acychecker'), 'description' => __('An accept all domain means that all email addresses on that domain will work. Your emails will be sent correctly but there are potentially no one receiving them.', 'acychecker'), ]; } $this->data['result'] = $result; $this->data['colorMap'] = [ self::STATUS_SUCCESS => 'green', self::STATUS_INVALID => 'red', self::STATUS_WARNING => 'orange', self::STATUS_INFO => 'blue', self::STATUS_NOT_TESTED => 'gray', ]; $this->data['isValid'] = $result[ApiService::API_TEST_KEY_EMAIL_EXISTS]; ob_start(); include ViewService::getView('Singletest', 'default_results'); $resultsHtml = ob_get_clean(); ob_start(); include ViewService::getView('Singletest', 'default_details'); $detailsHtml = ob_get_clean(); Ajax::sendAjaxResponse('', [ 'results' => $result, 'html' => [ 'results' => $resultsHtml, 'details' => $detailsHtml, ], ]); } }