CityHost.UA
Help and support

Email delivery best practices

Starting in 2022, Gmail (Google) and other popular mail services such as Outlook, Yahoo, Zoho have strengthened security methods to protect their users from spam and unauthorized emails. In order to successfully deliver letters, you need to comply with a certain set of requirements that are set by these postal services for senders.

If the sender does not fully meet the requirements of the specific postal service to which the letter is sent, such a letter may be marked as spam. Otherwise, the letter will not be delivered at all, and you will receive an error message from the mail server in response, which will indicate the reason for non-delivery.

Let's look at examples of best practices for sending emails in Gmail. Our source of information will be the official Google documentation available at support.google.com/mail/answer/81126


1. Always use SMTP instead of PHP MAIL

Most often, when creating a site, the developer uses the PHP MAIL method (a built-in PHP function) to send letters, because it is simpler, does not require additional settings and allows you to save time on development, however, this method does not provide the level of security, delivery success and control level that offers SMTP (domain mail).

The SMTP sending method should always be used to send emails to customers (order status, payment receipts, restoring access to accounts).

The PHP MAIL method should be used only for sending system/test emails from the site for the purpose of debugging its work, but not for full-fledged correspondence. Before the changes in email delivery policies, the PHP MAIL method could provide email delivery, although with a high chance of getting into spam, but for now, we strongly advise you to switch the site to sending emails using the SMTP method.

To use the SMTP sending method, create a mailbox on the hosting , and in the settings of the sending module on the site, write the host, ports and security protocols, which can be found in the block "Settings for the mail client" of the "Mail" section on the hosting. In general, it is worth entrusting the issue of switching to SMTP to the specialist who was involved in the development of the site, since this is his profile of responsibility.


2. For the domain from which letters are sent, it is necessary to have mandatory DNS records — DKIM and SPF, and the records must correspond to the mail server from which the mail is sent.

If you are sending emails through a shared hosting server, you can set up the correct DKIM/SPF records according to this guide .

Make sure that only one SPF record exists for your domain. If you have two or more such records, delete the redundant ones or merge them into one. The presence of more than one SPF record for a domain will lead to the potential entry of emails into spam.

If you are using a VDS/DS server for sending, the correct DKIM/SPF records must be created directly on the server. For example, the Hestia control panel automatically generates these entries . Otherwise, you will need to configure them in your own server settings depending on the software you are using.

In addition, it is important for VDS/DS servers to have a PTR of a DNS record that refers to the domain from which letters are sent. This guide describes how to install a PTR record.


3. In the letter, it is important that the "From" (FROM) header corresponds to the domain or site from which it is sent.

If you use the PHP MAIL method to send emails through a shared hosting server, the FROM header must be defined in your send script or in your site settings. If there is no such setting, you can specify the FROM header using the sendmail_path parameter in the PHP settings for the site in question.


4. Use the mail-tester.com service

mail-tester.com is a service for identifying possible problems with sending letters and fixing them. This service provides an opportunity to identify problematic aspects that need to be resolved.

To use the email tester, go to their website and copy the email address provided. Then send an email from your website to this address and click the "check" button. For example, if you do not receive a message about ordering a product from your site, you can order a product using the same e-mail address of the mail tester, so that the service analyzes the letter from the point of view of your customer.

If the email is successfully sent to the mail tester, you will be prompted to view a detailed report along with the email's delivery rating. The report will indicate aspects that are necessary for the successful delivery of the email to the inbox, such as DKIM settings, SPF, PTR, domain rating, lack of a correct FROM header, and other factors.


5. Carry out independent testing of the very fact of sending letters

If you suspect that emails are not being sent from the server, it is recommended to check by using test php scripts that use the sending method you need, such as PHP MAIL or SMTP, as described in the instructions .

If the test php script successfully sends the letter and delivers it to the test box, then it is worth continuing to work with the sending settings at the level of DNS records of the domain and site settings.

In the conditions of virtual hosting, there may be restrictions on sending emails in some cases, for example, during the use of a test period of hosting or due to the blocking of external connections due to the presence of malicious code on the site .


6. Pay attention to additional sources of information

Spam: why emails end up there and how to avoid it

What to do so that emails to Gmail users are not blocked and marked as spam

Solving problems with the delivery of emails on Outlook (Microsoft)


Similar articles