Using subdomain as SMTP server in Contact form

I’ve run into issues with my Contact form. It worked well with the standard “Self Hosted” settings when I used my Web hosting service as email provider.

However I’ve now updated the MX records for my domain to use another mail provider.

What I now would like to do is to use a subdomain (contactform.mydomainname.com, which I’ve created together with MX records pointing to the local server) as the mail server used. Is there a way to do that?

Just changing the Self Hosted form with a from email address like contact@contactform.mydomainname.com doesn’t work… and when I contacted my Web hosting service their thought is that the form still uses mydomainname.com to send the email from.

In theory you should just be able to change the mx records and set the routing to remote without needing to use a subdomain. You may have to update SPF records to allow for the IP configuration.

I’ve done this various times for clients using Office 365, but never needed to use SMTP. On my web host it works fine with the standard Blocs contact form.

Thanks @Flashman. I forwarded your response to my web hosting support - but got the reply that they doesn’t know how to configure it and that they don’t know how the Contact form is I’m using is working. Wondering if you know of a guide or something to how to set up the MX/SPF records for this to work?

And the Contact form set as Self Hosted is a PHP form, right? So everything gets sent through PHP rather than SMTP?

That’s a very strange answer from your web host, since this is a very common practice and I would imagine they receive requests like this every day.

I don’t know who you are hoping to use for the email hosting, but you should be able to approach them directly and ask for the required MX settings with guidance, then just edit them in the zone editor of cPanel. Here is a link showing how to do it for Office 365:

Two key points are that if you have edited the mx details properly, you need to make sure routing is set to remote, which tells the world that email is handled elsewhere. Secondly you may need to look at any SPF records to reflect the change in IP number for the mail server, but cPanel usually makes a valid suggestion after the MX settings are changed.

The standard Blocs contact form is self hosted PHP and I have no problems sending either to the same domain or something like gmail. Some of my clients use Office 365 for email and others have it hosted on my server. It works either way and just a case of spending a few minutes in the zone editor if it needs to be handled remotely.

One afterthought is that if you are using CloudFlare you might want to check the DNS settings there to make sure email is allowed to pass through freely.

2 Likes

Thanks alot @Flashman.

Since your last response I’ve been having two email conversations going with support from my web host and my email provider (Protonmail). Web host support updated the SPF records but then it also turned out that the messages got stuck because Protonmail don’t have SMTPUTF8 support, so they suggested that the form shouldn’t contain UTF-8 in the message headers, so that their auto-detection won’t require that extension.

So I needed to remove all non-english characters from the subject text and delete the following line from the form php file after export:

$headers = "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n";

And now it works!

I guess that’s not something I can specify Blocs to do (I got the sense that this is a bit of an unsual problem).

I know Protonmail and once set up an email account when they first launched, though I’ve never used it. Is the email delivered to the inbox on your computer or do you have to access it via their website?

I can see how you would need to update the SPF, but the rest is somewhat unusual, since the form mail is effectively bypassing your web host’s mail server and routing it immediately to Protonmail. They are basically making you jump through more hoops than usual and I haven’t encountered issues like this elsewhere.

The header for plain/text is a curious one. They obviously want things to be encrypted, but if your website has SSL and your email app connects over a secure port that would not normally be a problem, since the connection itself is encrypted. I would be wary of not restricting messages to plaintext going through the contact form, because in theory that might open the door to some sort of code injection, but this is all a bit beyond my basic knowledge.

The contact form in Blocs has always been dead simple for me, simply needing a send and receive email address then it works. I only have to alter the mx details etc on the server if routing remotely.

Blocs allows you to use other scripts by switching from self hosted to custom, so you may be able to tailor something specific to your needs and go like that. I believe @hendon52 is much better versed in these matters.

I’m accessing my Protonmail mainly from the webmail login. It’s also possible to use a desktop/mobile email client together with their app Protonmail Bridge (which creates some kind of tunnel, I guess).

Yea, that’s what I thought (of this process). Thanks a lot for your ideas!

I’m quite happy that the form is working now anyway. I’ve just have a bash post export script that I run which fixes the form to my current needs.