Sending emails via SMTP server reduces the chance of flagging them as spam.
Also, using it in Drupal websites enhances the success rate of email reaching the destination server.
However, improper Drupal 8 SMTP settings like wrong port or typo in SMTP server name may lead to the email sending failures.
That’s why, at Bobcares, we often get requests from our customers to fix Drupal SMTP errors as part of our Server Management Services.
Today, we’ll see how our Support Engineers fix Drupal SMTP errors.
How we configure SMTP in Drupal 8
Fortunately, Drupal 8 allows to use different back-ends for formatting and sending e-mails by default. Also any theme can be configured and setup for sending mails. Unlike Drupal 7, there is no need to configure each theme template for email sending.
Let’s take a look on how we configure SMTP settings in Drupal 8. This SMTP Authentication Support module becomes a popular choice as it can bypass PHP’s default mail function and can send mails via SSL too.
1. Firstly, we download the SMTP Authentication Support module from https://www.drupal.org/project/smtp to Drupal installation’s modules directory and unzip it.
2. Then, we login to the Drupal 8 administration panel.
3. Now, we access the Manage -> Extend section. We find the SMTP Authentication Support module under the MAIL section and click on the Configure option to enable it.
4. Next, click the On radio button to turn the module on and enter the SMTP configuration options there.
For instance, to configure mail server settings, we fill the field with the following entry.
- SMTP server – The address for your outgoing SMTP server
- SMTP backup server – leave as blank.
- Use encrypted protocol – Set to YES if want to use SSL encryption.
- SMTP port – The port on which the SMTP service will connect to. For encrypted connection, use 465 otherwise 25.
5. After that, we fill the SMTP Authentication fields as following,
- Username – Username@domain.com
- Password – PASSWORD
- Email from address – Usernane@domain.com
- E-mail from name – The name from which you want messages to appear.
When using a Gmail account, we make sure to replace Username and Password with the Gmail account username and password respectively. And, in such cases, we set the SMTP server to Gmail server too.
6. At last, we click “Save configuration” to save the changes.
How we fixed the related errors
Although, the SMTP setup looks pretty straight forward, it may not always work.
Let’s take a closer look on the reasons for SMTP not working and how our Support Engineers fixed it.
1. Wrong port settings
Recently, one of our customers contacted us with a problem related to PHPMailer in Drupal 8. He used the SMTP method to send emails. But, when he tried to send emails got an error as
SMTP Error: Could not connect to SMTP host.
So, it was clear that PHPMailer was unable to contact the SMTP server defined in the mail server settings.
Here, the possible reasons for this error would be bad port settings either in mail server or due to firewall restrictions in the client’s computer. In this case, only a particular user reported the problem. Thus, we isolated the problem with his network/computer.
Therefore, our Support Engineers solved the problem by making necessary changes in the customer’s computer firewall. Again, when multiple users complain about connection problems, we review the firewall at the server side and make necessary changes.
2. Incorrect SMTP server settings
Often, customers may get errors while sending emails due to improper working of the SMTP server. Also, the SMTP server fails to send emails with incorrect SMTP server settings.
Similarly, another customer reported that his mails did not work after configuring the SMTP module in Drupal.
Therefore, our Support Engineers checked the SMTP server settings in Drupal. Then, they found that the wrong SMTP server name setting caused the problem with emails.
So, we solved the issue by providing a correct SMTP server name in Drupal SMTP server settings.
For example, when customers prefer to use a Google account, then we set up the SMTP server name as smtp.gmail.com.
[Having trouble while configuring Drupal 8 SMTP settings? We’ll fix it for you.]
In short, improper Drupal 8 SMTP settings such as wrong SMTP server name, wrong port settings, etc. may cause errors when sending emails. Today, we saw how our Support Engineers fixed related errors.