Troubleshooting & Common Errors

Comprehensive Guide to Configuring Contact Forms

By the Domain India teamPublished 5 min read
Knowledge base article
Contents (5 sections)

A contact form is only useful if its messages arrive. On Domain India shared hosting the method that works is PHP mail() with an envelope sender on your own domain, not the SMTP settings most older guides give. This page sums up the working setup and points you to the full guides.

Key takeaways

On Domain India cPanel hosting, SMTP from PHP fails because the socket functions it needs are disabled; on DirectAdmin, test on your plan. Build the message (with PHPMailer if you like) and send it with PHP mail() and -f set to a mailbox on your own domain. Send from your own domain, put the visitor's address in Reply-To, protect the form with a CAPTCHA or honeypot, and publish SPF, DKIM and DMARC.

For the full guide, see How to use PHPMailer for contact forms

The complete, tested handler code is in How to use PHPMailer for contact forms. For every other way of sending email from PHP, including WordPress and frameworks, read Sending email from PHP.

1. Why the classic SMTP setup fails on shared hosting

Many contact form tutorials tell you to enter an SMTP host, port 587 or 465, a mailbox username and its password. From PHP on our cPanel servers that route does not work: shared hosting disables the PHP socket functions (fsockopen, stream_socket_client) that an SMTP connection needs, and the form fails with an error such as:

text
stream_socket_client() has been disabled for security reasons

PHP's own mail() function is not affected. It hands the message to the server's local mail system, which is the reliable route on shared hosting. The reasons and the full list are in PHP disabled functions on shared hosting.

Those ports are still right for an email program such as Outlook; they are just not how a PHP form on shared hosting should send.

2. The setup that works

  1. Create a sending mailbox.
    In your control panel, create a real mailbox such as [email protected], and decide which address should receive enquiries.
  2. Install PHPMailer on your computer, if you use it.
    Composer cannot run on shared hosting, so run composer require phpmailer/phpmailer locally and upload the project with its vendor/ folder.
  3. Build the message, then send it with mail().
    Let PHPMailer compose the message with preSend(), then call mail() yourself with -f set to your sending mailbox. PHPMailer's own isMail() mode drops the -f value on our cPanel servers.
  4. Keep the visitor in Reply-To.
    Put the visitor's address only in Reply-To. Putting it in From makes the message fail SPF and DMARC.
  5. Validate every field on the server.
    Reject invalid addresses and any line breaks in the name or subject (used to inject headers).
  6. Test.
    Send an enquiry to a Gmail address you own and choose Show original: SPF, DKIM and DMARC should show PASS, and the Return-Path should be your own address.

3. Stop spam before it uses up your sending limit

An open form is found by bots quickly, and every message it sends counts towards your account's limit: 200 messages per hour per account on cPanel and 1,000 per day on DirectAdmin.

4. WordPress contact forms

WordPress form plugins send through wp_mail(), which uses PHP mail(). Set the From address to a real mailbox on your domain and check that DKIM is valid. SMTP mailer plugins fail on our cPanel servers when they try a direct SMTP connection; if you use one, choose its HTTPS API option instead. The details are in section 9 of Sending email from PHP.

5. Deliverability: SPF, DKIM and DMARC

Form messages are far less likely to land in spam when your domain publishes SPF, DKIM and DMARC. DKIM is on by default for new cPanel accounts. See Email authentication: SPF, DKIM and DMARC.

What SMTP settings should my contact form use on Domain India hosting?

On Domain India cPanel hosting, a PHP contact form should not use SMTP, because the socket functions SMTP needs are disabled. Send with PHP mail() and the -f envelope sender set to a mailbox on your domain; PHPMailer can build the message. On DirectAdmin, test SMTP on your plan before relying on it.

Why does my contact form say stream_socket_client() has been disabled?

The form is trying to send over SMTP, which needs PHP socket functions that shared hosting disables for security. Switch to PHP mail() with the -f envelope sender, as shown in the PHPMailer contact form guide.

Which From address should a contact form use?

A real mailbox on your own domain, such as [email protected]. Put the visitor's email address in Reply-To so that replying still reaches them.

How many emails can my contact form send?

Every message counts towards your hosting account's limit: 200 messages per hour per account on cPanel and 1,000 per day on DirectAdmin. Protect the form with a CAPTCHA or honeypot so bots can't use it up.

Why do my contact form emails go to spam?

Usually because the From address is not on your domain, the envelope sender is missing, or SPF, DKIM and DMARC are not set up. Send from your own domain with -f, and check the three records in your control panel.

Ready to fix your form? Follow How to use PHPMailer for contact forms, compare cPanel hosting and DirectAdmin hosting, or open a support ticket if your form still won't send.

Hosting that sends your website's email

Email accounts on your own domain, PHP mail() that works on every shared plan, and 24/7 live chat support to check your mail setup with you.

See hosting plans

Ready when you are

Get cPanel hosting from ₹125/mo + GST

See plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app
Configure a Contact Form on Shared Hosting | Domain India