> ## Documentation Index
> Fetch the complete documentation index at: https://help.onetsolutions.net/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP Email (SMTP)

> Send emails from PHP using SMTP authentication

To ensure email deliverability and security, we recommend using SMTP authentication instead of the PHP `mail()` function.

<Warning>
  The PHP `mail()` function is disabled on our servers due to security concerns. It lacks authentication and is commonly exploited by malicious scripts.
</Warning>

## Using PHPMailer with SMTP

<Info>
  **Prerequisites**

  * A Web Hosting service with OnetSolutions
  * An email account created in cPanel
  * PHPMailer library installed in your project
</Info>

### Installation

Download PHPMailer from the [official GitHub repository](https://github.com/PHPMailer/PHPMailer) or install via Composer:

```bash theme={null}
composer require phpmailer/phpmailer
```

### SMTP Configuration

```php theme={null}
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    // SMTP settings
    $mail->isSMTP();
    $mail->Host = 'mail.yourdomain.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'your-email@yourdomain.com';
    $mail->Password = 'your-email-password';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port = 587;

    // Email content
    $mail->setFrom('your-email@yourdomain.com', 'Your Name');
    $mail->addAddress('recipient@example.com', 'Recipient Name');
    $mail->Subject = 'Subject of your email';
    $mail->Body = 'Content of your email';

    $mail->send();
    echo 'Email sent successfully!';
} catch (Exception $e) {
    echo "Error: {$mail->ErrorInfo}";
}
```

## SMTP Settings

<Info>
  Use these settings to configure your PHP application for sending emails.
</Info>

| Setting    | Value                   |
| ---------- | ----------------------- |
| Host       | `mail.yourdomain.com`   |
| Port       | 587 (TLS) or 465 (SSL)  |
| Encryption | STARTTLS or SSL         |
| Username   | Your full email address |
| Password   | Your email password     |

<Warning>
  **Security Best Practice**: Never hardcode your email credentials directly in your code. Use environment variables or a configuration file outside your web root to store sensitive information.
</Warning>

<Tip>
  Test your email configuration by sending a test message to yourself before deploying to production.
</Tip>
