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

# Phpmailer

# Sending with PHPMailer

Integrate Mailofly into standard PHP projects using PHPMailer.

***

## Installation

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

***

## Example

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

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    // Server settings
    $mail->isSMTP();
    $mail->Host       = 'smtp.mailofly.com';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'mailofly';
    $mail->Password   = 'mfly_live_your_api_key';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port       = 587;

    // Recipients
    $mail->setFrom('support@yourcompany.com', 'Acme Support');
    $mail->addAddress('customer@example.com');

    // Content
    $mail->isHTML(true);
    $mail->Subject = 'Your Order Confirmation';
    $mail->Body    = '<h1>Thank you for your order!</h1>';
    $mail->AltBody = 'Thank you for your order!';

    $mail->send();
    echo 'Message has been sent successfully';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
```


## Related topics

- [Introduction](/smtp/introduction.md)
- [Integrations](/integrations/index.md)
- [Supabase](/smtp/supabase.md)
- [Laravel](/smtp/laravel.md)
