Microsoft Bad Request Errors

Problem

WHMCS fails to import emails using a Microsoft® email service (for example, Microsoft Outlook® or Microsoft 365®).

Additionally, admins with the System email permission receive a POP3 Connection Error email with the following error:

Bad Request

Cause

The Redirect URI that you specified during app registration in the Microsoft Azure® Portal is invalid. It does not resolve to the callback handler file in your WHMCS installation.

This may be due to one of several causes:

  • Your WHMCS System URL setting begins with http://.
  • You have misconfigured the Friendly URL settings.
  • The WHMCS installation URL changed after you registered the app.

Solution

To resolve this issue:

  1. Make certain that you have installed a valid SSL certificate on your website.
  2. Update the WHMCS System URL setting to use https:// in the General tab at Configuration () > System Settings > General Settings.
    For more information, see Update the System URL.
  3. Resynchronise your .htaccess file and confirm that Full Friendly Rewrite mode operates correctly. To do this:
    1. Go to the General tab at Configuration () > System Settings > General Settings.
      If the 404 error prevents you from accessing Configuration () > System Settings, type the filename into your browser’s URL bar: configgeneral.php
    2. Scroll to the Friendly URLs section. You may see that this setting is being manually overridden.
      • By default, WHMCS will detect and pick the best option for your server environment.
      • If it has been manually overridden, there may be a problem in your configuration.
    3. Click Advanced Settings to the right of the Friendly URLs menu. A new window will display important URI-related information. You may see an indication that Full Friendly Rewrite did not pass the environment mode tests:
      An environment mode test failure.
    4. Click the Rewrite File tab. If you see an OUT OF SYNC message under WHMCS Rules, the .htaccess rules are out-of-date:
      Out-of-sync WHMCS rules.
    5. Enable Auto-Managed Rewrite to ensure that the rules stay up-to-date in the future.
    6. Click Synchronize to close the window.
    7. Click the Refresh icon for Friendly URLs to refresh the menu. If the issue is resolved, Full Friendly Rewrite will display in the menu and the sections that displayed the 404 error will be accessible again.
      The Friendly URLs setting.
  4. Edit the support department at the Configuration () > System Settings > Support Departments.
  5. Under Mail Importing Configuration, copy the new Redirect URL value.
  6. Update your app registration in the Microsoft Azure Portal to use the new redirect URL.
    The redirect URL must use the following format, where example.com is your website and whmcs is the directory that stores WHMCS’s files:
    https://example.com/whmcs/admin/setup/mail/oauth2/callback
    For more information, see Set Up Email Importing - Microsoft.

Last modified: June 14, 2024