---
title: Sending Email via Scripts
description: Learn how to set up email sending from your website using PHP, Exim, or an SMTP server, including the necessary parameters and PHP libraries.
---

[Skip to content](https://help.ishosting.com/en/sending-email-via-scripts#main-content)

- [English](https://help.ishosting.com/en/sending-email-via-scripts)
- [Русский](https://help.ishosting.com/ru/sending-email-via-scripts)

English

Show submenu for translations

[![is\*hosting](https://help.ishosting.com/hubfs/Logo_Ishosting_mono-1.svg)](https://help.ishosting.com/en)

- [Blog](https://blog.ishosting.com/en)
- [Support](https://my.ishosting.com/en/tickets)

Open main navigation

Close main navigation

- [Blog](https://blog.ishosting.com/en)
- [Support](https://my.ishosting.com/en/tickets)
- - [English](https://help.ishosting.com/en/sending-email-via-scripts)
    - [Русский](https://help.ishosting.com/ru/sending-email-via-scripts)

  English
  
  Show submenu for translations
- [Go to ishosting.com](https://ishosting.com/)

[Go to ishosting.com](https://ishosting.com/)

 Hello. How can we help you?

- There are no suggestions because the search field is empty.

1. [Help Center](https://help.ishosting.com/en)
2. [Mail](https://help.ishosting.com/en/mail)
3. [Getting Started](https://help.ishosting.com/en/mail#getting-started)

# Sending Email via Scripts

## This article describes methods for sending email from your website using the PHP mail() function, the Exim mail server, and the SMTP protocol.

To automatically send emails from your website (such as notifications, contact form submissions, registration confirmations, or other messages), you can use a local Exim mail server or an SMTP server that requires authentication.

### Sending Email via PHP mail()

The **mail()** function allows you to send emails directly from PHP scripts using a mail service configured on the server, such as Exim.

By default, the sender's address may appear in the format **login@server.com**, where:

- **login** is the username
- **server.com** is the domain name used by the mail server

To specify a particular sender address, include a **From** header and the additional **-f** parameter when calling the **mail()** function.

Example of sending an email:

```
<?php$to = "recipient@example.com";$subject = "Test message";$message = "This is a test email.";$headers = "From: sender@example.com";mail($to, $subject, $message, $headers, "-fsender@example.com");?>
```

Replace the sender and recipient addresses with your own.

**NOTE!** The **-f** parameter sets the SMTP envelope sender address. Its availability depends on your mail server's configuration.

For more information on configuring and using the **mail()** function, please refer to the [official PHP documentation](https://www.php.net/function.mail?utm_source=chatgpt.com).

### Sending Email via SMTP

To send emails via SMTP, you must have a valid mailbox and the necessary connection credentials for the mail server.

**SMTP Server Connection Parameters**

| **Parameter** | **Description** |
| --- | --- |
| **SMTP Server** | Address of the server used for sending email |
| **Login** | Full email address |
| **Password** | Password for the email account |
| **Port** | 25 or 2525, depending on the server configuration |
| **Encryption** | As required by the SMTP server settings |
| **Authorization** | Via login and password |

**Note!** Available ports and encryption methods depend on the mail server settings. When using a third-party SMTP service, ports 465 or 587 may be required.

**Libraries for Sending Email via SMTP**

To send emails via SMTP, you can use specialized libraries available for various programming languages:

- [PHPMailer](https://github.com/PHPMailer/PHPMailer?utm_source=chatgpt.com) is a library for sending email from PHP scripts, supporting SMTP authorization and encryption.
- [Symfony Mailer](https://symfony.com/doc/current/mailer.html?utm_source=chatgpt.com) is a PHP component for creating and sending emails.
- [smtplib](https://docs.python.org/3/library/smtplib.html?utm_source=chatgpt.com) is a standard Python library for sending emails via SMTP.

Refer to the documentation for your chosen library to configure the connection.

### Comparison of Email Sending Methods

| **Criterion** | **PHP mail() / Exim** | **SMTP with Authorization** |
| --- | --- | --- |
| Local mail server | Required | Optional |
| Mailbox authorization | Generally not required | Required |
| Additional libraries | Not required | Recommended |
| Use of an external mail service | Depends on configuration | Supported |
| Error diagnostics | Mail server logs | SMTP server responses and library logs |

### What to Do if Emails Are not Being Sent?

If errors occur while sending email, check the following parameters:

- Correctness of the sender and recipient addresses. Correctness of the email account login and password.
- Availability of the SMTP server and the port being used.
- Alignment of encryption settings with the mail server's configuration.
- Proper functioning of the local Exim mail service when using **the mail()** function.
- Presence and accuracy of SPF, DKIM, and DMARC DNS records.
- Presence of any errors in the mail server logs.

If emails are being sent but not reaching the recipient, please check the "**Spam**" folder.

If you have any questions, you can ask them in the online chat in the lower-right corner of the site or create a request to the support service through the[ticket system](https://my.ishosting.com/en/tickets).

- [Virtual Private Servers](https://help.ishosting.com/en/virtual-private-servers#main-content)

    - [Getting Started](https://help.ishosting.com/en/virtual-private-servers#getting-started)
    - [Working with VPS](https://help.ishosting.com/en/virtual-private-servers#working-with-vps)
    - [Software](https://help.ishosting.com/en/virtual-private-servers#software)
    - [Backup and Data Storage](https://help.ishosting.com/en/virtual-private-servers#backup-and-data-storage)
    - [Additional Services](https://help.ishosting.com/en/virtual-private-servers#additional-services)
    - [VPS Load](https://help.ishosting.com/en/virtual-private-servers#vps-load)
    - [Other Issues](https://help.ishosting.com/en/virtual-private-servers#other-issues)
- [Dedicated Servers](https://help.ishosting.com/en/dedicated-servers#main-content)

    - [Getting Started](https://help.ishosting.com/en/dedicated-servers#getting-started)
    - [Working with Dedicated Server](https://help.ishosting.com/en/dedicated-servers#working-with-dedicated-server)
    - [Additional Services](https://help.ishosting.com/en/dedicated-servers#additional-services)
    - [Other Issues](https://help.ishosting.com/en/dedicated-servers#other-issues)
- [Server Administration](https://help.ishosting.com/en/server-administration#main-content)

    - [API](https://help.ishosting.com/en/server-administration#api)
    - [Windows Instructions](https://help.ishosting.com/en/server-administration#windows-instructions)
    - [UNIX Instructions](https://help.ishosting.com/en/server-administration#unix-instructions)
    - [ispmanager](https://help.ishosting.com/en/server-administration#ispmanager)
    - [VestaCP](https://help.ishosting.com/en/server-administration#vestacp)
    - [DirectAdmin](https://help.ishosting.com/en/server-administration#directadmin)
    - [BitrixVM](https://help.ishosting.com/en/server-administration#bitrixvm)
    - [Security](https://help.ishosting.com/en/server-administration#security)
    - [DDoS Protection](https://help.ishosting.com/en/server-administration#ddos-protection)
    - [Working with Files](https://help.ishosting.com/en/server-administration#working-with-files)
    - [Databases](https://help.ishosting.com/en/server-administration#databases)
    - [PHP](https://help.ishosting.com/en/server-administration#php)
    - [Logs and Statistics](https://help.ishosting.com/en/server-administration#logs-and-statistics)
    - [Diagnostics and Troubleshooting](https://help.ishosting.com/en/server-administration#diagnostics-and-troubleshooting)
    - [HestiaCP](https://help.ishosting.com/en/server-administration#hestiacp)
    - [cPanel](https://help.ishosting.com/en/server-administration#cpanel)
    - [aaPanel](https://help.ishosting.com/en/server-administration#aapanel)
    - [FastPanel](https://help.ishosting.com/en/server-administration#fastpanel)
    - [Other](https://help.ishosting.com/en/server-administration#other)
- [Mail](https://help.ishosting.com/en/mail#main-content)

    - [Getting Started](https://help.ishosting.com/en/mail#getting-started)
    - [ispmanager](https://help.ishosting.com/en/mail#ispmanager)
    - [DirectAdmin](https://help.ishosting.com/en/mail#directadmin)
    - [VestaCP](https://help.ishosting.com/en/mail#vestacp)
    - [Other Issues](https://help.ishosting.com/en/mail#other-issues)
- [VPN](https://help.ishosting.com/en/vpn#main-content)

    - [Getting Started](https://help.ishosting.com/en/vpn#getting-started)
    - [Android](https://help.ishosting.com/en/vpn#android)
    - [iOS](https://help.ishosting.com/en/vpn#ios)
    - [macOS](https://help.ishosting.com/en/vpn#macos)
    - [Mikrotik](https://help.ishosting.com/en/vpn#mikrotik)
    - [Linux](https://help.ishosting.com/en/vpn#linux)
    - [Windows](https://help.ishosting.com/en/vpn#windows)
    - [Amnezia VPN](https://help.ishosting.com/en/vpn#amnezia-vpn)
    - [Hysteria](https://help.ishosting.com/en/vpn#hysteria)
- [Data Storage](https://help.ishosting.com/en/data-storage#main-content)

    - [Getting Started](https://help.ishosting.com/en/data-storage#getting-started)
    - [Backups](https://help.ishosting.com/en/data-storage#backups)
    - [Other](https://help.ishosting.com/en/data-storage#other)
- [SSL Certificates](https://help.ishosting.com/en/ssl-certificates#main-content)

    - [Getting Started](https://help.ishosting.com/en/ssl-certificates#getting-started)
    - [Install](https://help.ishosting.com/en/ssl-certificates#install)
- [Affiliate Program](https://help.ishosting.com/en/affiliate-program)
- [Additional Services](https://help.ishosting.com/en/additional-services#main-content)

    - [Additional IP](https://help.ishosting.com/en/additional-services#additional-ip)
    - [Control Panels](https://help.ishosting.com/en/additional-services#control-panels)
    - [Antivirus](https://help.ishosting.com/en/additional-services#antivirus)
- [Client Area](https://help.ishosting.com/en/client-area#main-content)

    - [Balance History](https://help.ishosting.com/en/client-area#balance-history)
- [Payment for Services](https://help.ishosting.com/en/payment-for-services#main-content)

    - [Getting Started](https://help.ishosting.com/en/payment-for-services#getting-started)
    - [My Account](https://help.ishosting.com/en/payment-for-services#my-account)
    - [Payments](https://help.ishosting.com/en/payment-for-services#payments)
    - [Other Issues](https://help.ishosting.com/en/payment-for-services#other-issues)
- [Documents and Policies](https://help.ishosting.com/en/documents-and-policies#main-content)

    - [General](https://help.ishosting.com/en/documents-and-policies#general)
    - [Company](https://help.ishosting.com/en/documents-and-policies#company)
- [Questions and Answers](https://help.ishosting.com/en/questions-and-answers#main-content)

    - [Control Panels](https://help.ishosting.com/en/questions-and-answers#control-panels)
    - [ispmanager](https://help.ishosting.com/en/questions-and-answers#ispmanager)
    - [Windows](https://help.ishosting.com/en/questions-and-answers#windows)
    - [Linux](https://help.ishosting.com/en/questions-and-answers#linux)
    - [Mail](https://help.ishosting.com/en/questions-and-answers#mail)
    - [Other](https://help.ishosting.com/en/questions-and-answers#other)
- [Special Offers](https://help.ishosting.com/en/special-offers)
- [is\*smart](https://help.ishosting.com/en/issmart#main-content)

    - [General Info](https://help.ishosting.com/en/issmart#general-info)
    - [Getting Started](https://help.ishosting.com/en/issmart#getting-started)
    - [API](https://help.ishosting.com/en/issmart#api)
    - [AI Models](https://help.ishosting.com/en/issmart#ai-models)
- [List of Apps](https://help.ishosting.com/en/list-of-apps)

[![is\*hosting](https://help.ishosting.com/hubfs/ishosting-logo-black.svg "is*hosting")](https://ishosting.com)

<https://www.facebook.com/ishostingcom> <https://twitter.com/ishostingcom> <https://www.instagram.com/is.hosting> <https://www.youtube.com/@ishosting> <https://www.linkedin.com/company/is-hosting>

Copyright © 2025, © Webrain OÜ