---
title: "Sending emails via web-server"
canonical_url: "https://www.zone.lv/help/kb/sending-e-mail-trough-web-server-php-mail/"
post_type: "ht_kb"
published: "2020-07-09T10:00:54+00:00"
modified: "2026-02-13T09:31:33+00:00"
language: "en"
author: "Ardi Jürgens"
taxonomies:
  ht_kb_category:
    - name: "PHP"
      url: "https://www.zone.lv/help/kb-categories/php-en/"
    - name: "Technical"
      url: "https://www.zone.lv/help/kb-categories/technical-en/"
    - name: "Wordpress"
      url: "https://www.zone.lv/help/kb-categories/wordpress-en/"
  ht_kb_tag:
    - name: "e-mail"
      url: "https://www.zone.lv/help/kb-tags/e-mail/"
    - name: "laravel"
      url: "https://www.zone.lv/help/kb-tags/laravel-en/"
    - name: "mailer"
      url: "https://www.zone.lv/help/kb-tags/mailer/"
    - name: "Mailgun"
      url: "https://www.zone.lv/help/kb-tags/mailgun-en/"
    - name: "php mail()"
      url: "https://www.zone.lv/help/kb-tags/php-mail-en/"
    - name: "phpmail"
      url: "https://www.zone.lv/help/kb-tags/phpmail-en/"
    - name: "phpmailer"
      url: "https://www.zone.lv/help/kb-tags/phpmailer/"
    - name: "port 2525"
      url: "https://www.zone.lv/help/kb-tags/port-2525-en/"
    - name: "Sendgrid"
      url: "https://www.zone.lv/help/kb-tags/sendgrid-en/"
---

# Sending emails via web-server

## General

If you are hosting your website on Zone virtual server and you would like to send emails out from your website, please note, that **ports 25, 1025, 1026, 465 and 587 are closed**. Hence you can not use smtp.zone.lv server or any other server that is using the mentioned ports.

In order to send emails from your website, `localhost` has to be assigned as SMTP host name and port `25` should be used. Authentication or secure connection (SSL/TLS) is not required. Those values should be assigned as *false* or *none*.

### PHP

Here’s an example of PHP script’s settings:

```
$mail->Mailer = "smtp";
$mail->Host = "localhost";
$mail->Port = "25";
$mail->SMTPSecure = 'none';
$mail->SMTPAutoTLS = false;
$mail->SMTPAuth = false;
```

 Useful tip! Many external mail service providers like Sendgrid and Mailgun support **port 2525** to send email out. This port is not closed and can be used freely.

### Laravel

The Laravel setup looks like this:

```
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="info@yourdomain.com"
MAIL_FROM_NAME="Senders name"
```

The configuration in the `./config/mail.php` file looks like this:

```
'mailers' => [
    'smtp' => [
    'transport' => 'smtp',
    'url' => env('MAIL_URL'),
    'host' => env('MAIL_HOST', '127.0.0.1'),
    'port' => env('MAIL_PORT', 2525),
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'timeout' => null,
    'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url(env('APP_URL', 'http://localhost'), PHP_URL_HOST)),
    'verify_peer' => false,
    ],
    ...
]
```

### WordPress – WP Mail SMTP plugin

Setting up the WP Mail SMTP plugin to send emails via `localhost` and port `25`:

![](https://www.zone.lv/static/sites/5/localhost.png)

## Email limitations

You are allowed to send out one email every five seconds. If you exceed this limit, an automatic restriction will be applied on sending emails via webserver. To remove this restriction, please contact our customer support at <info@zone.lv>

 Additional information For information on email restrictions to prevent or neutralise cyber attacks, click [here](https://www.zone.lv/help/en/kb/restrictions-and-limitations-on-sending-email-to-prevent-or-neutralise-cyber-attacks/)

## SPF

When sending out emails from your webserver, please make sure that your domain’s SPF record allows it. Otherwise the emails will be marked as spam or won’t be delivered at all.

In case your domain is using only Zone email services, the SPF record should look like this:

```
v=spf1 a mx include:_spf.zone.lv -all
```

If your website is hosted with us, but you are using email services elsewhere, the SPF record should be modified accordingly. Adding `include:_spf.zone.lv` to your domain’s SPF record is sufficient. Here’s an example:

```
v=spf1 ip4:123.4.5.6 include:_spf.zone.lv -all
```

 Useful tip! You can find instructions on how to add and manage an SPF record [here](https://www.zone.lv/help/en/kb/spf-record/).

## DKIM

In order to add authenticity to email that are sent from your webserver, you can use **DKIM signature**. DKIM will add a cryptographic signature to the email, so that the receiving end can be sure that the email was sent out properly and it has not been forged.

To activate DKIM, log in to “My Zone” and choose `Web hosting`-&gt;`Email`. [Further guidelines can be found here.](https://www.zone.lv/help/en/kb/spf-dkim-and-dmarc-how-to-prevent-your-emails-from-getting-into-spam/)

## Changing PHP sendmail\_from

By default, the email form your web server are sent out from noreply address – for example `noreply@example.com`. This can be changed with PHP [mail()](http://ee1.php.net/manual/en/function.mail.php) function’s fifth parameter -f.

To change the default noreply address, log in to My Zone and choose `Web hosting`-&gt;`Webserver`-&gt;`Main domain settings`-&gt;`Modify`–&gt;`PHP settings`.

![](https://www.zone.lv/static/sites/5/phpsettings_en_1.png)

On the next page the sendmail\_from value must be changed . You **only** need to enter the e-mail address in the form of `address@example.com`.

![](https://www.zone.lv/static/sites/5/phpsettings_en_2.png)

## Log of e-mails sent from web server

The log of emails from the web server can be seen in the My Zone via Web-hosting management under `Logs` -&gt; `Webserver e-mail`.

Detailed instructions on the logs can be found [here](https://www.zone.lv/help/en/kb/log-of-e-mails-sent-from-web-server/).

## Using an external SMTP server

 Attention! The given guide is only an example and Zone customer support does not provide help for setting up an external SMTP server for customer’s web application.

Prerequisites for using an external SMTP server:

- Web-hosting package Pro
- Dedicated IP address (comes with web-hosting Pro package, ask customer support to activate it)
- external SMTP server that supports TLS/SSL connection over port 587

In order to send a mail from the web server through an external server, the application must send the mail to the IP address allocated to the virtual server. Typical plugins for WordPress and other applications do not allow you to do this in the user interface, so you have to do the configuration directly on a per-file basis.

 Important information! Port 25 cannot be used on shared web-hosting, even if your virtual server has its own dedicated IP address. This restriction is in place to prevent the risk of uncontrolled spam, which Zone would be unable to monitor or block effectively. However, with a dedicated IP, you can use alternative SMTP ports or consider upgrading to a [managed cloudserver](https://www.zone.lv/en/cloud-server/managed-cloudserver/).

It must be taken into account that the webserver e-mail log visible in the My Zone control panel does not display the mails sent via an external server.

### Example 1: [WP Mail SMTP by WPForms](https://et.wordpress.org/plugins/wp-mail-smtp/)

To send emails from the specific IP address, the following filter must be added into the functions.php file:

```
add_filter('wp_mail_smtp_custom_options',function($phpmailer){
  $phpmailer->SMTPOptions=[
    'socket'=>[
      'bindto' => '1.2.3.4:0'
    ]
  ];
  return $phpmailer;
});
```

Where on the row of `'bindto' => '1.2.3.4:0'` replace `'1.2.3.4:0'` with a allocated dedicated IP address.

NB! The IP address is followed by `:0`.

Example of a plugin configuration:

[![](https://www.zone.lv/static/sites/5/WP-dedicated-IP-SMTP.png)](https://www.zone.lv/help/en/kb/sending-e-mail-trough-web-server-php-mail/wp-dedicated-ip-smtp/)

### Example 2: [Nodemailer](https://nodemailer.com/)

In Nodemailer, you can set up dedicated IP address with the `localAddress` value. Gmaili SMTP as an example:

```
nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
        user: 'username@gmail.com',
        pass: 'password'
    },
    localAddress: '1.2.3.4'
});
```

where on the row of `localAddress: '1.2.3.4'` replace `'1.2.3.4'` with a allocated dedicated IP address.

### Example 3: [Laravel](https://laravel.com/)

Laravel `.env` file example:

```
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="username@gmail.com"
MAIL_FROM_NAME="Sender name"
```

An example of `./config/mail.php` configuration file:

```
'mailers' => [
    'smtp' => [
    'transport' => 'smtp',
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'timeout' => null,
    'local_domain' => env('MAIL_EHLO_DOMAIN'),
    'source_ip' => '1.2.3.4',
    ],
    ...
],
```

Where on the row of `'source_ip' => '1.2.3.4',` replace `'1.2.3.4'` with a allocated dedicated IP address.
