DEV Community

Jana
Jana

Posted on

Setting up contact form for site hosted on cPanel and GoDaddy

It took me a full day to get a contact form working on cPanel, here's what I learned.

The symptom was confusing: submitting the form returned a 200 and showed the success message, but nothing ever landed in the inbox. No error, no bounce, the email just quietly vanished.

My Setup

  • The site runs on cPanel hosting (GoDaddy, in my case).

  • contact.php sends mail with PHPMailer over SMTP to the local mail server (localhost).

  • The owner reads enquiries in a Microsoft 365 mailbox (provisioned through GoDaddy) on the same domain as the site.

What Went Wrong

It helps to understand what happens when you hit "Send" by picturing the two roles involved:

The sender. The mail server needs an address it's authorized to send as. It assumes that identity and hands your message off for delivery. It has to be an address the server is allowed to send for, not the visitor's address.

The receiver. The site owner, who reads and replies to enquiries. In my case that mailbox lives on Microsoft 365 and shares the site's domain.

Once PHPMailer authenticates and calls send(), the local server accepts the message and becomes responsible for delivering it onward. If that hand-off succeeds, PHPMailer reports success — even if the message never reaches a human. That's exactly why I saw a 200 with no email.

By default, cPanel treats your domain as local - it assumes the mailboxes for that domain live on the same server. So when the form sent to owner@mydomain.com, the local server dropped it into a local mailbox on the cPanel box... which nobody ever checks, because the real mailbox is on Microsoft 365. Delivery "succeeded" locally, so no error ever surfaced.

This is especially easy to hit when the sending and receiving addresses share the same domain, because the local server considers itself authoritative for that domain out of the box.

How to Fix This

  • Set Email Routing to Remote Mail Exchanger. In cPanel, go to Email → Email Routing and switch the domain from Local to Remote Mail Exchanger. This tells the server it is not the final destination for the domain — it should look up the MX records and deliver to Microsoft's servers, where the mailbox actually lives. This is the setting that gets your mail off the local box and onto M365.

  • Watch out for Microsoft 365's spoof protection. Because the message's From address is on your own domain but arrives at M365 from an outside source (the cPanel server), Microsoft may treat it as spoofed and quietly quarantine or reject it. If mail still doesn't arrive after step 1, make sure the sending server is allowed to send for your domain — check your SPF record, and add an allow/mail-flow rule in M365 if needed.

  • Set Reply-To. from has to stay an address the server can send as, so if you don't set Reply-To, clicking "Reply" on an enquiry would go back to the form's own sending address instead of the person who wrote in. Set the Reply-To header to the visitor's address so the owner can just hit Reply and reach the actual enquirer:

$mail->setFrom(FROM_EMAIL, FROM_NAME); // an address the server may send as
$mail->addReplyTo($email, $name); // the visitor who filled out the form

Hope this helps!

Top comments (1)

Collapse
 
topstar_ai profile image
Luis

Great practical guide. Contact forms are one of those features that seem simple but often become a source of issues when hosting environments, email delivery, and security settings are involved.

I like that you covered the real deployment side rather than just the frontend form. Reliable email delivery requires proper configuration, validation, spam protection, and testing across different hosting setups.

For production sites, adding measures like server-side validation, rate limiting, CAPTCHA alternatives, and email authentication (SPF/DKIM/DMARC) can make the workflow much more reliable. Great resource for anyone dealing with shared hosting and custom forms!