# PHPMailer

Send email from PHP with an authenticated SMTP transport.

Before you begin, verify a sending domain and create an [API key](https://usesendy.com/docs/authentication). Keep the key in your application server’s secret configuration.

## Configure PHPMailer

Install PHPMailer with Composer, then save this script in your project.

Install the package:

Install · terminal

```
composer require phpmailer/phpmailer
```

Use this configuration:

send-email.php

```
<?php

use PHPMailer\PHPMailer\PHPMailer;

require __DIR__ . '/vendor/autoload.php';

$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.usesendy.com';
$mail->Port = 2525;
$mail->SMTPAuth = true;
$mail->Username = 'apikey';
$mail->Password = 'API_KEY';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->CharSet = 'UTF-8';

$mail->setFrom('noreply@example.com', 'My App');
$mail->addAddress('recipient@example.com');
$mail->Subject = 'Welcome';
$mail->isHTML(true);
$mail->Body = '<h1>Welcome</h1><p>Your account is ready.</p>';
$mail->AltBody = 'Your account is ready.';

$mail->send();
echo "Email queued.\n";
```

Replace `API_KEY` with your full Sendy API key and the sender with an address on your verified domain. Use STARTTLS on port 2525 with the literal username `apikey`. See [PHPMailer email documentation](https://github.com/PHPMailer/PHPMailer).

## Send a test email

Run · terminal

```
php send-email.php
```

Run php send-email.php. The script prints Email queued. after SMTP accepts the message; failures throw an exception.

## Check the result

Open [Emails](https://usesendy.com/emails) to confirm the message was queued and follow its status. Successful SMTP submission confirms queuing, not inbox delivery. See [Errors](https://usesendy.com/docs/errors) for failure guidance.
