Email configuration is crucial for your eCommerce store to ensure reliable delivery of order confirmations, subscription reminder, and other important notifications. This guide explains how to configure SMTP in DigiCommerce without using additional plugins.
To configure SMTP, add the following code to your theme’s functions.php file or in a site-specific plugin:
function digicommerce_smtp_mailer($phpmailer) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.host.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 465;
$phpmailer->Username = SMTP_USERNAME;
$phpmailer->Password = SMTP_PASSWORD;
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->From = SMTP_USERNAME;
$phpmailer->FromName = 'DigiCommerce';
}
add_action('phpmailer_init', 'digicommerce_smtp_mailer');
In this code, replace smtp.host.com
with your SMTP host URL, and modify the FromName
value from ‘DigiCommerce’ to your preferred sender name that customers will see in their email client.
Securing Your SMTP Credentials
For enhanced security, store your SMTP credentials in the wp-config.php file instead of including them directly in your functions file. Add these lines to your wp-config.php:
define('SMTP_USERNAME', '[email protected]');
define('SMTP_PASSWORD', 'PASSWORD');
Replace [email protected]
and PASSWORD
with your actual SMTP credentials. This approach keeps sensitive information separate from your theme or plugin files and simplifies credential updates when needed.
Once you’ve implemented these configurations, WordPress will automatically use your specified SMTP server for all outgoing emails, ensuring reliable delivery of order notifications, customer communications, and other important messages.