If your website has a contact form or sends automated emails (such as order confirmations or registration emails) and those messages are not being delivered, the most common cause is that the form is using PHP’s built-in mail() function, which is disabled or unreliable on shared hosting. This article explains why that happens and how to fix it by configuring your form to send via SMTP instead.
Why PHP mail() often does not work on shared hosting
PHP mail() sends messages through the server’s local mail agent without authentication. On shared hosting, this approach is frequently blocked or silently discarded by receiving mail servers because the messages lack proper authentication headers (SPF, DKIM). Major email providers including Gmail, Outlook, Yahoo and iCloud now reject unauthenticated mail by default.
The solution is to configure your website to send mail via authenticated SMTP using an email account set up in your hosting control panel.
Step 1: Create or identify an email account to send from
You will need a mailbox on your hosting account to use as the sender. If you have not already created one:
- cPanel hosting: log in to cPanel and go to Email > Email Accounts
- DirectAdmin hosting: log in to DirectAdmin and go to Email Manager > Create Email
- Cloud hosting: create a mailbox via your Cloud control panel under the email management section
Create an address such as [email protected] or [email protected] and make a note of the password.
Step 2: Find your SMTP settings
Use the settings below with your email address and password from Step 1. Replace yourdomain.com with your actual domain name.
| Setting | cPanel hosting | DirectAdmin hosting | Cloud hosting |
|---|---|---|---|
| SMTP server | mail.yourdomain.com | mail.yourdomain.com | smtp.yourdomain.com |
| SMTP port (recommended) | 587 | 587 | 587 |
| Encryption | STARTTLS | STARTTLS | STARTTLS |
| Alternative port | 465 (SSL/TLS) | 465 (SSL/TLS) | 465 (SSL/TLS) |
| SMTP username | Full email address | Full email address | Full email address |
yourdomain.com with your actual domain name. The hostname prefix differs between platforms: cPanel and DirectAdmin use mail., while Cloud hosting uses smtp. for outgoing mail.Step 3: Configure your contact form or application to use SMTP
WordPress (WP Mail SMTP or similar plugin)
- Install a plugin such as WP Mail SMTP or FluentSMTP from the WordPress plugin directory
- In the plugin settings, select Other SMTP as the mailer type
- Enter the SMTP host, port, encryption, username and password from Step 2
- Use the built-in test tool to send a test email and confirm delivery
Custom PHP application (PHPMailer)
Use the PHPMailer library rather than the built-in mail() function. A basic configuration looks like this:
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'mail.yourdomain.com'; // use smtp.yourdomain.com for Cloud hosting
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'your-password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
composer require phpmailer/phpmailerContact Form 7 (WordPress)
Contact Form 7 relies on WordPress’s built-in mail function. Install an SMTP plugin such as WP Mail SMTP alongside it and configure the SMTP settings as above. The plugin will automatically handle all outgoing mail from Contact Form 7.
Common errors and what they mean
| Error message | What to check |
|---|---|
| SMTP connect() failed | Check your SMTP hostname and port. Try port 465 if 587 is not working. |
| Authentication failed | Double-check your username (full email address) and password. |
| Could not connect to SMTP host | Your IP may be temporarily blocked. See our article on IP blocking. |
| 550 Sender not authorised | Your sending domain may be missing SPF or DKIM records. See our article on email authentication. |