All 17 Email Delivery sections
Setting the connection in wp-config.php
The main connection and who it comes from can be set in wp-config.php instead of on the Settings screen. That keeps the password out of the database altogether, and lets an agency set many sites up from one file. Define any of these, above the line that says to stop editing:
define( 'TRML_HOST', 'smtp.sendgrid.net' );
define( 'TRML_PORT', 587 );
define( 'TRML_ENCRYPTION', 'tls' );
define( 'TRML_USERNAME', 'apikey' );
define( 'TRML_PASSWORD', 'your API key' );
define( 'TRML_FROM_EMAIL', 'shop@example.com' );
define( 'TRML_FROM_NAME', 'Example Shop' );| Constant | Sets | Takes |
|---|---|---|
TRML_PROVIDER | Which service | gmail, outlook, sendgrid, mailgun, postmark, brevo, mailjet, smtp2go, ses, zoho, fastmail or custom |
TRML_HOST | Mail server | a server name, such as smtp.gmail.com |
TRML_PORT | Port | a number from 1 to 65535 |
TRML_ENCRYPTION | Encryption | tls, ssl or none |
TRML_USERNAME | Username | anything |
TRML_PASSWORD | Password | anything, used exactly as written |
TRML_FROM_EMAIL | From address | an email address |
TRML_FROM_NAME | From name | anything |
Each one you define is used for the site, whatever the Settings screen says. Those you leave out come from the screen as before. A few follow from others:
- a mail server (or a service, which has one) means email leaves through it, so How email leaves is A mail service;
- a service on its own brings its own mail server, port and encryption, as choosing it on the screen does, unless you set those too;
- a mail server without a service is read as the service whose server it is (
smtp.gmail.comis Gmail), or as Another service, which decides which ports Send a test tries and what the From domain check expects; - a username or a password means signing in to the mail server.
On the Settings screen, each field set this way is greyed and says Set in wp-config.php, with the constant's name. The password box stays empty: the password is never shown, sealed or stored. Saving the screen does not change those fields. What the screen had saved for them stays saved underneath, so taking a constant out of wp-config.php brings back the screen's own value. A note above the settings, and another on the Dashboard and on Send a test, lists what wp-config.php sets.
A constant whose value its setting does not take, such as a port of 99999 or an encryption of starttls, is not used. The screen's own value is, and the screen and the Dashboard name the constant. A constant defined as an empty string sets nothing.
Send a test, Check the sign-in now, the daily sign-in check and the wp email-delivery commands all use the constants. When Send a test finds that another port answers and wp-config.php sets the port or the encryption, it says which values to set there rather than offering Use port. A typo in a constant stops email on every site that uses the file, and the test and the daily check report it as they report any other refusal.
An exported settings file holds the screen's own values, never what wp-config.php sets, and importing a file leaves the settings wp-config.php sets as they are. The backup connection is set on the screen only.
On a network the constants apply to every site. To give one site values of its own, a must-use plugin can change them through the trml_constant_values filter, which is given the defined values by constant name:
add_filter( 'trml_constant_values', function ( $values ) {
if ( 3 === get_current_blog_id() ) {
$values['TRML_FROM_EMAIL'] = 'orders@another-shop.example';
}
return $values;
} );Still stuck? Ask the developers who wrote it. We aim to reply within one business day.