Moodle Error: Could not instantiate mail function

We came across an error with our Moodle install when trying to send user registration emails. When clicking the link we got the error ‘Could not instantiate mail function. ERROR: Could not instantiate mail function’

We’re running Moodle on a Windows Server 2008 R2 box, so we had to do a few workarounds to get it working. The database is also running on Microsoft SQL 2008 R2 and not MySQL.

This error proved to be a simple one to fix, it turned out we didn’t configure the smtphosts value in the database table mdl_config. Running the SQL script below against dbo.mdl_config fixed it for us (change mymailserver.com to your mail servers details)