Extension:ContactPage/SiteGround and SES

This page details a potentially common issue users may encounter when running this extension with the hosting provider SiteGround (and possibly others), and provides an option for fixing the issue. This guide should also work for other providers that exhibit the same issue (such as Amazon SES).

Issue
The user sending the form gets an error saying that Unknown error in PHP's mail function MediaWiki if Manual:$wgSMTP has not been configured (see below for a screenshot):



If Manual:$wgSMTP has been configured, then the user may get an error saying that the from address is not configured in the server.

Cause
SiteGround doesn't appear to allow sending emails where the from address is not in the list of email addresses in the corresponding SiteGround account. This is normally used to prevent spam, but has an adverse effect in this case. Notice that other email functionality (such as password reset) is not affected because the FROM address in this case is the same as $wgPasswordSender, which would usually be the same email address in the SiteGround account.

A useful way to check if the email address itself is valid to reset the password of any user. If that works, then this guide should help you with the ContactPage issue. If that does not work, then you should look into fixing that first (by following the suggestion at Manual:$wgSMTP for instance).

Fix
This will involve changing the code of a file in that extension, and was taken from https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ContactPage/+/679450, and by extension, here. In the wiki root directory, go to the file. Then, locate the below line:

This would usually be in line 286 or so (the exact line will depend on the ContactPage version you have). Then comment the below lines:

and replace it with

This fixes the main issue. However, if you stop here, the user will get an error (an exception of type "Error") if they choose the option to send a copy of the message to themselves. To fix that, we need to make some changes to another section of the file. Look for the string (in about line 450 or so)

Then comment the below lines:

and replace with

That's it. Save the file, and the problem should no longer occur. What the fix does is forcefully set the FROM address to the email address in the SiteGround account, while setting the "replyto" to the email the user sets when they contact your wiki. This means that you can still reply to the user despite this change, and the email will go back to the user who sent the contact form.