WordPress email notifications include password reset messages, new user alerts, order updates, form submissions, and administrator activity notices. If email is configured unreliably, messages may not arrive, end up in spam, or be forged in your domain’s name.
A reliable setup consists of several layers: the site sends messages through authenticated SMTP with encryption, the domain publishes SPF and DKIM, and DMARC determines what to do with messages that fail authentication. SMTP credentials must also be protected, and logs should be checked to ensure that they are not exposed.
Why WordPress Default Email Delivery Can Be a Problem
WordPress usually creates email through the wp_mail() function. It is responsible for building the message, but it is not a standalone mail server. Actual delivery may be handled by a local server mail service or the PHP mail() mechanism. On shared hosting, this approach often comes with restrictions, a shared IP reputation, and unpredictable deliverability.
The lack of SMTP authentication also makes it harder to control the source of messages. An attacker who gains access to the site or to a vulnerable plugin may try to send messages through the hosting provider’s mail infrastructure. Another issue is the visible From field: without SPF, DKIM, and DMARC, it is harder for recipients to distinguish a legitimate message from a fraudulent one.
SMTP does not replace WordPress security, but it creates a controlled delivery channel. The site sends mail to a specific provider, which then applies authentication, encryption, rate limits, and its own reputation mechanisms.
- Email sent through SMTP must be authenticated with an account or token.
- The connection must be encrypted with TLS: port 587 with STARTTLS or port 465 with TLS is typically used, depending on the provider’s requirements.
- Do not copy SMTP provider settings at random: the email service specifies the exact server, port, encryption type, and authentication method.
Create a Separate Mailbox and Use a Secure From Address
For a website, it is better to create a separate address on your own domain, such as wordpress@example.com or no-reply@example.com. Do not use the administrator’s personal mailbox or enter the password for the main corporate account in the site settings. If the site is compromised, the attacker should not gain access to the organization’s entire mailbox.
Use a separate password, an application password, or an OAuth token for SMTP, depending on what the provider supports. The account should have only the permissions it needs: the site should send email, but it should not read or delete messages unless a specific integration requires this.
The From address should belong to your domain and match the SMTP configuration. For example, if authentication is performed as wordpress@example.com, it is safer to send messages from that domain rather than replacing From with a Gmail address or the address submitted by a form visitor. The user’s address can be passed in Reply-To so that replies go to the appropriate recipient.
Fix the From address in the mail configuration and do not allow individual plugins to change it arbitrarily. Otherwise, some messages may be sent from another domain, which can weaken DMARC alignment and the sender’s reputation.
- Use a separate mailbox or service account for WordPress.
- Enable multifactor protection for the email account if the provider supports it.
- Do not use a visitor’s address in the From field; use Reply-To instead.
- After changing the password or revoking a token, update the site’s SMTP configuration.
Keep SMTP Credentials Outside the Theme and Public Code
Do not store an SMTP password in theme files, JavaScript, public repositories, or plugin code edited by several people. Such files often end up in backups, change logs, or version control systems.
The best option is to use environment variables available to the PHP process and pass the SMTP configuration through the secure mechanism provided by the specific mail solution. If environment variables are unavailable, credentials can be stored in wp-config.php, but the file must have restricted permissions and must not be downloadable through the web server.
WordPress itself does not provide universal standard constants for all SMTP providers. Parameter names depend on the plugin or mail integration, so do not simply add arbitrary constants and expect them to work automatically.
- Do not put the password in templates, functions.php, or client-side JavaScript.
- Check access permissions for wp-config.php and backups.
- Add files containing secrets to .gitignore, but do not rely on it alone: a secret that has already entered Git must be revoked.
- If a leak is suspected, immediately change the password or revoke the token and review SMTP logs.
define('SITE_SMTP_USER', getenv('SITE_SMTP_USER')); define('SITE_SMTP_PASSWORD', getenv('SITE_SMTP_PASSWORD'));
Add SPF: Allow the Domain to Send Email from the Correct Sources
SPF is a DNS TXT record that lists the servers or email services authorized to send messages on behalf of a domain. An SPF check determines whether the sender’s IP address is allowed to use the domain in the message envelope.
SPF does not encrypt messages and, by itself, does not prove that the visible From field has not been forged. It works together with DKIM and DMARC. If WordPress uses a third-party SMTP service, SPF must include that service’s instruction, usually through an include mechanism.
A domain should have one combined SPF record. Creating two TXT records that each begin with v=spf1 causes a validation error. SPF also limits the number of DNS lookups, so complex include chains should be reviewed periodically.
- Identify all legitimate email sources: WordPress, CRM, newsletters, support forms, and other services.
- Combine them into one SPF record instead of creating a separate record for each service.
- Do not add IP addresses or include mechanisms unless you understand which service they belong to.
- After changing DNS, check the record with a DNS diagnostic service and a test message.
Example format: v=spf1 include:_spf.mail-provider.example -all
Enable DKIM and DMARC Without Suddenly Blocking Legitimate Email
DKIM adds a cryptographic signature to an email. The private key is kept by the email service, while the public key is published in DNS under a special selector, such as selector1._domainkey.example.com. The recipient uses it to verify that the message was not modified and that the signature belongs to the stated domain.
DKIM is configured in the SMTP provider’s or corporate email service’s control panel. Do not create a record at random: the provider must supply the selector and the exact TXT or CNAME record value. If multiple services send email, each may require a separate selector.
DMARC defines the policy for messages that fail SPF or DKIM authentication with the required domain alignment. At the initial stage, it is reasonable to use p=none with reporting to identify all sending sources. After legitimate services have been verified, you can move to p=quarantine and then to p=reject.
DMARC reports help identify forgotten integrations, old servers, or attempts to impersonate the domain. Addresses for aggregate reports must be specified carefully: they may contain a significant amount of technical data and should be sent to a mailbox or a dedicated monitoring service.
- Publish the DKIM record provided by your email service and verify that real messages receive a signature.
- Start DMARC in monitoring mode if you do not have a complete list of services that send mail for the domain.
- Check domain alignment: the From address, DKIM domain, and SPF domain must be consistent with the DMARC policy.
- Move to p=reject only after analyzing reports and testing all forms, notifications, and integrations.
Example DMARC format: v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com
Test the Setup and Check Common Errors
After configuration, send test messages to several email services and inspect the message headers. They should contain SPF, DKIM, and DMARC results, as well as an indication that the SMTP connection was established over TLS. Do not check delivery alone: a message may reach the spam folder or pass SMTP delivery without passing domain authentication.
Test all WordPress scenarios: password resets, account creation, form submissions, comment notifications, orders, and messages generated by plugins. Some extensions may use their own mail mechanism or change the From address independently of the general configuration.
Also review WordPress, mail plugin, PHP, web server, and hosting logs. They should not contain SMTP passwords, tokens, complete headers with confidential data, or URLs containing secrets. Error logging should remain sufficient for troubleshooting without recording credentials.
- An authentication error often indicates an incorrect password, disabled SMTP access, or the need for an application password.
- A TLS error may be related to the wrong port, encryption mode, certificate, or server time.
- An SPF error is often caused by duplicate records or a missing source for a third-party service.
- A DMARC error may occur if a plugin changes From or the SMTP service signs the message with a different domain.
- After DNS changes, account for caching: different DNS servers may not see updates at the same time.
Frequently asked questions
Is connecting SMTP alone enough to secure WordPress email?
No. SMTP secures message transmission from the site to the email service and helps control sending, but it does not replace SPF, DKIM, and DMARC. All of these layers are needed to protect the domain.
Should the From address use the website’s domain?
Yes, this is the recommended approach. A From address on your own domain simplifies SPF/DKIM alignment and reduces the risk of spoofing. The form user’s address should be passed through Reply-To instead.
Which DMARC policy should be configured first?
If sending sources have not yet been verified, start with p=none and analyze the reports. After legitimate senders have been corrected, move to p=quarantine and then to p=reject.
Where is it safest to store the SMTP password?
Preferably in environment variables or a secrets manager. If this is not possible, store it in wp-config.php with proper access permissions, outside the repository and public files. If a leak is suspected, change the password.
Conclusion
Secure WordPress email is not a single switch but a coordinated configuration of the site, SMTP provider, and DNS. Use TLS, a separate mailbox with minimal permissions, protected SMTP secrets, correct SPF and DKIM records, and a gradual DMARC rollout.
After configuration, regularly check message headers, DMARC reports, logs, and the list of services authorized to send email for your domain. This reduces the risk of forged messages and helps ensure that important WordPress emails, including password reset and administrator activity notifications, are not lost.