// website builders and cms
Via APIMoodle email verification with pingutil
Moodle sites with email-based self-registration collect spam accounts on throwaway inboxes and accounts with mistyped addresses whose confirmation email never arrives. A local plugin can implement the validate_extend_signup_form callback, which Moodle calls from the signup form validation, verify the address with pingutil, and return an error on the email field. If pingutil does not answer within 6 seconds, the callback returns no errors and Moodle carries on with its normal confirmation flow.
Where it connects: validate_extend_signup_form callback in a local plugin (email-based self-registration, login/signup.php)
What goes wrong without it
- Self-registration is on for our open courses, and the user list fills with spam accounts that post links in forums.
- Learners type their address wrong, never get the confirmation email, and then email the help desk or register again.
- We have hundreds of unconfirmed accounts on disposable domains that we have to clean up by hand.
What you can do with Moodle and pingutil
Reject disposable and dead addresses on login/signup.php
The callback calls /v1/verify and returns an error for the email field when status is invalid, so Moodle never creates the unconfirmed account or sends the confirmation email.
Fix typos before the confirmation email goes out
When did_you_mean is set, show the suggested address in the error so the learner corrects it on the spot instead of waiting for a link that never comes.
Keep risky addresses but watch them
accept_all domains (common for school and company mail) come back as risky. Let them register; Moodle's own confirmation email still proves the inbox works.
Set it up
- 1
Enable email-based self-registration under Site administration → Plugins → Authentication → Manage authentication if it is not already on, and create an API key in the pingutil dashboard.
- 2
Create local/pingutil with version.php (component local_pingutil), lang/en/local_pingutil.php (pluginname, didyoumean, emailrejected strings), settings.php with an apikey setting, and the lib.php below.
- 3
Visit Site administration → Notifications to install the plugin, then paste the key into its settings.
- 4
Purge caches so Moodle finds the new callback, then sign up with test@mailinator.com and a mistyped Gmail address to confirm the email field shows the error.
- 5
Sign up with your own address to confirm the confirmation email still arrives.
<?php
defined('MOODLE_INTERNAL') || die();
/**
* Called by core_login_validate_extend_signup_form() from login/signup_form.php.
* Returns field => message; an empty array lets the signup continue.
*
* @param array $data submitted signup form values
* @return array
*/
function local_pingutil_validate_extend_signup_form($data) {
global $CFG;
require_once($CFG->libdir . '/filelib.php');
$email = trim((string) ($data['email'] ?? ''));
$key = (string) get_config('local_pingutil', 'apikey');
if ($email === '' || $key === '') {
return [];
}
$curl = new \curl();
$curl->setHeader(['Authorization: Bearer ' . $key, 'Content-Type: application/json']);
$body = $curl->post('https://pingutil.com/v1/verify', json_encode(['email' => $email]), [
'CURLOPT_CONNECTTIMEOUT' => 2,
'CURLOPT_TIMEOUT' => 6,
]);
$info = $curl->get_info();
// Timeout, network error, 429 quota_exceeded or 5xx: fail open.
if ($curl->get_errno() || (int) ($info['http_code'] ?? 0) !== 200) {
return [];
}
$result = json_decode($body, true);
if (!is_array($result)) {
return [];
}
if (!empty($result['did_you_mean']) && $result['status'] !== 'valid') {
return ['email' => get_string('didyoumean', 'local_pingutil', s($result['did_you_mean']))];
}
if ($result['status'] === 'invalid') {
return ['email' => get_string('emailrejected', 'local_pingutil')];
}
return [];
}What to do with each result
| pingutil result | Action in Moodle |
|---|---|
| status: "invalid" (disposable_domain, no_mx, mailbox_not_found) | Return an error for the email field; no account is created and no confirmation email is sent. |
| did_you_mean set and status not "valid" | Return the didyoumean string with the suggested address. |
| status: "risky" (accept_all, role_based) | Return no error; Moodle's confirmation email does the final check. |
| status: "unknown", timeout, 429 or 5xx | Return an empty array so the signup continues. |
Limits to plan for
- Moodle's developer docs mark validate_extend_signup_form as a work-in-progress callback and say it is not used by the web services API or the Moodle app. Signups through auth_email_signup_user (the mobile app) skip this check.
- A mailbox check can take several seconds on slow servers, so the callback waits at most 6 seconds and then lets the signup through unchecked.
- Each checked signup uses one of the Free plan's 300 verifications a day (3,000 a month); during a spam wave the budget can run out and the check fails open until 00:00 UTC.
Moodle documentation
- docs.moodle.org/dev/Login_callbacks
- moodledev.io/docs/apis/plugintypes/local
- docs.moodle.org/405/en/Email-based_self-registration
Moodle is a trademark of its owner. This integration uses Moodle's documented extension points; it is not an official Moodle app.
Common questions
- Why validate_extend_signup_form and not pre_signup_requests?
- pre_signup_requests runs before the form and takes no data, so it cannot see the address. validate_extend_signup_form receives the submitted values and its returned errors are merged into the form validation, which is what puts the message under the email field.
- Does Moodle's "allowed email domains" setting do the same thing?
- It restricts signups to domains you list, which suits a single school. For an open site you cannot list every acceptable domain, and the setting does not know which domains are disposable or which mailboxes exist.
Stop bad addresses in Moodle today
Sign in with your email, create an API key and paste it into the step above. Test on a few real addresses first: the live demo shows exactly what your Moodle setup will receive.