Keeping credentials in wp-config.php

By default your SMTP password and API keys are stored in the database, encrypted with AES-256 using your site’s own security keys. For extra security, or to set up many sites the same way, you can put the SMTP details in wp-config.php instead. They then never touch the database.

Available constants

Add any of these to wp-config.php, above the line /* That's all, stop editing! */:

define( 'BW_SMTP_HOST', 'smtp.example.com' );
define( 'BW_SMTP_PORT', 587 );
define( 'BW_SMTP_ENCRYPTION', 'starttls' ); // none | ssl | tls | starttls
define( 'BW_SMTP_AUTH', true );
define( 'BW_SMTP_USER', '[email protected]' );
define( 'BW_SMTP_PASS', 'your-smtp-password' );
define( 'BW_SMTP_FROM', '[email protected]' );
define( 'BW_SMTP_FROM_NAME', 'Example Site' );

You can define only some of them, for example just BW_SMTP_PASS, and set the rest on the settings screen.

What you see in the dashboard

Fields set by a constant are locked on the SMTP Settings screen. A Locked by wp-config.php card lists which ones. To change a locked value, edit wp-config.php.

Constants apply to the SMTP mailer settings. API keys for SendGrid, Mailgun, Postmark and Brevo are entered on the settings screen and stored encrypted.

Good to know

  • Constants always win over values saved in the dashboard.
  • Exports from Import / Export never include passwords or API keys, whether they come from constants or the database.
  • Encrypted passwords depend on your WordPress security keys (the AUTH_KEY en AUTH_SALT lines in wp-config.php). If you change those keys, or move the database to a site with different keys, enter the password again. Passwords set with BW_SMTP_PASS are not affected.

Was this article helpful to you?

Nieuwsbrief

Blijf op de hoogte

Ontvang meldingen over nieuwe plugins, updates en exclusieve tutorials.

Geen spam ooit. U kunt zich op elk moment uitschrijven.