(AGPL-3.0) $pfqdn = str_replace(['autoconfig.', 'autodiscover.'], '', $_SERVER['HTTP_HOST']); $mhost = dns_get_record($pfqdn, DNS_MX)[0]['target']; $configXML = explode('?', $_SERVER['REQUEST_URI']); $configXML = $configXML[0]; switch(strtolower($configXML)) { case '/autodiscover': case '/autodiscover/': case '/autodiscover/autodiscover.xml': { $data = file_get_contents('php://input'); preg_match("/\(.*?)\<\/EMailAddress\>/", $data, $matches); $output = autodiscover(@$matches[1], $mhost, $pfqdn); break; } case '/mail/config-v1.1.xml': case '/.well-known/autoconfig/mail/config-v1.1.xml': { $output = autoconfig(@$_GET['emailaddress'], $mhost, $pfqdn); break; } default: { header("HTTP/1.0 404 Not Found"); exit; break; } } header("Content-type: text/xml; charset=utf-8"); print $output; exit; function autodiscover($email, $mhost, $pfqdn) { return << email settings IMAP $mhost 993 on off on on $email SMTP $mhost 465 on off on on on off $email XML; } function autoconfig($emailaddress = null, $mhost, $pfqdn) { return << $pfqdn $pfqdn $pfqdn $mhost 993 SSL password-cleartext %EMAILADDRESS% $mhost 465 SSL password-cleartext %EMAILADDRESS% Getting started with IMAP and POP3 XML; }