Sending email from your website reliably
Why contact forms and website notifications go missing, the difference between PHP mail() and authenticated SMTP, and how to set up a sending address.
On this page
Website email — contact forms, password resets, order confirmations — is the mail most likely to vanish, because it’s often sent in the way filters trust least.
The two ways a website sends mail
PHP mail() | Authenticated SMTP | |
|---|---|---|
| How | Hands mail to the server’s local mail system | Logs in to a mailbox like an email app |
| From address | Whatever the code sets, often unrelated | A real mailbox on your domain |
| Authentication | Often weak or misaligned | SPF and DKIM align with your domain |
| Deliverability | Unpredictable | Reliable |
Set up a sending mailbox
- Create an address such as
website@yourdomain.co.uk. How to create an email account in DirectAdmin - Use it as the From address for all website mail.
- Configure your site to send through SMTP with these settings:
| Setting | Value |
|---|---|
| Host | mail.yourdomain.co.uk |
| Port | 465 (SSL) or 587 (TLS) |
| Username | website@yourdomain.co.uk |
| Password | That mailbox’s password |
For WordPress, use an SMTP plugin. How to send WordPress email through SMTP
The contact form trap
A form that sets the From address to the visitor’s email (say, a Gmail address) makes your server send mail claiming to be from Gmail. DMARC at Gmail rejects it. Instead:
- From: your sending mailbox
- Reply-To: the visitor’s address
Replies still go to the visitor.
PHP example with PHPMailer
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'mail.yourdomain.co.uk';
$mail->SMTPAuth = true;
$mail->Username = 'website@yourdomain.co.uk';
$mail->Password = getenv('SMTP_PASSWORD');
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('website@yourdomain.co.uk', 'Your Site');
$mail->addReplyTo($visitorEmail);Keep the password out of files in public_html. Storing configuration and secrets outside public_html
Prefer to follow along?
- Diagnose email delivery problems
Advanced · 40 min - Make WordPress emails arrive (SMTP setup)
Intermediate · 20 min
If it doesn’t work
These guides cover the most common problems, starting with what you can see. Or browse every fix for a common problem.
- Understanding email bounce messagesRead an email bounce (non-delivery report): the common 4xx and 5xx codes, what ‘mailbox full’, ‘relay denied’ and ‘rejected by policy’ mean, and what to do.
- Why are my emails going to spam?The real reasons email lands in junk folders — authentication, content, reputation and recipient behaviour — and a checklist to fix each one.
- Can’t send email: how to fix outgoing mailFix email that won’t send from your app or phone: SMTP authentication, port and encryption mismatches, blocked networks and sending limits.
Common questions
Can my website send email — contact forms, order confirmations?
Yes, but send it through a real mailbox using SMTP rather than through PHP’s built-in mail function. Mail sent the built-in way is frequently discarded without warning, which is why form submissions seem to vanish.
Spotted something out of date or unclear? Tell us and we’ll fix it.