Configuring an SMTP server for sending mail with Drupal
Sending mails from Drupal is a feature we take for granted. Sometimes however you can't rely on the default SMTP settings available from your hosting provider. This week I was unable to send mails from my Drupal site, because the default sendmail installation was no longer functioning. Fortunately I quickly found a solution with the SMTP Authentication Support module.Typically the default SMTP settings are buried in a file named "php.ini". PHP usually comes with a wrapper to the sendmail application. Sometimes the SMTP settings for PHP are crippled or deactivated on purpose, e.g. on shared hosting plans. If you're not in control of your server, then you can't edit this file.
No sending mails for you from Drupal then? Not necessarily.
The SMTP Authentication Support module builds on top of the SMTP library from PHP Mailer. When installed, it will substitute itself to the default mail send API. The basic features of this module are:
- Configuration of a primary and optionally a secondary SMTP server
- Support for SMTP authentication (optional)
- Support for SSL encryption (optional)
- Configuration of sender's email address and name (defaulting to the site name)
- Debug messages and test email (with configurable recipient's address) for checking whether the SMTP configuration is functional
Installation is a 5 step procedure:
- Download and unpack the the SMTP Authentication Support module: it will unpack in an "smtp" directory.
- Download and unpack the PHP Mailer module that corresponds to your needs (I downloaded the PHP 5/6 version).
- Rename the PHP Mailer directory (mine was "PHPMailer_v5.1") to "phpmailer" and drop it into the "smtp" directory (see step 1).
- Upload the "smtp" directory to your host's "sites/all/modules" directory.
- Enable the SMTP Authentication Support module (browse as Drupal admin to admin/build/modules)
Now all that remains, is to configure the SMTP Authentication Support module:
- Browse as Drupal admin to admin/settings/smtp
- Turn the module on
- Specify the SMTP server you want to use. Optionally, specify a backup SMTP server. Check with your hosting provider (or ISP) for the settings that apply to you.
- Configure the SMTP connection settings: specify an alternate SMTP port, authentication (optional), whether an SSL connection should be initiated.
- Configure the sender's identity: email address and sender's name (the latter defaults to the name of your Drupal site).
- Fill in a valid email address in the "Send test email" field to test your configuration. Please do so, in order to test your setup!
- Click "Save configuration" and you are done!
If you see PHP errors on a white background, you probably either forgot to upload the PHP Mailer library, or you did not rename its directory to "phpmailer" (all lowercase!), or this directory is in the wrong location. These errors won't break your Drupal site - they only appear when you try sending a mail.