# Send emails using PHPMailer with SMTP

## Prerequisites

Before you start, you'll need:

- A Resend [API key](/guides/get-started-create-an-api-key)
- A [verified domain](/guides/get-started-add-a-domain)

## Guide

:::::steps
::::step{title="Install"}
Get the [PHPMailer](https://github.com/PHPMailer/PHPMailer) package.

:::code-group
```bash php theme={"theme":{"light":"github-light","dark":"vesper"}}
composer require phpmailer/phpmailer
```
:::
::::

:::step{title="Send email using SMTP"}
When configuring your SMTP integration, you'll need to use the following credentials:

- **Host**: `smtp.resend.com`
- **Port**: `587`
- **Username**: `resend`
- **Password**: `YOUR_API_KEY`

Then use these credentials to send with PHPMailer:

```php theme={"theme":{"light":"github-light","dark":"vesper"}}
<?php

// Include Composer autoload file to load PHPMailer classes
require __DIR__ . '/vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

$mail = new PHPMailer(true);

try {
    $mail->isSMTP();
    $mail->Host = 'smtp.resend.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'resend';
    $mail->Password = 're_xxxxxxxxx';
    $mail->SMTPSecure = 'tls';
    $mail->Port = 587;

    // Set email format to HTML
    $mail->isHTML(true);

    $mail->setFrom('onboarding@resend.dev');
    $mail->addAddress('delivered@resend.dev');
    $mail->Subject = 'Hello World';
    $mail->Body = '<strong>It works!</strong>';

    $mail->send();

    // Log the successfully sent message
    echo 'Email successfully sent';
} catch (Exception $e) {
    // Log the detailed error for debugging
    error_log('Mailer Error: ' . $mail->ErrorInfo);
    // Show a generic error message to the user
    echo 'There was an error sending the email.';
}
```
:::
:::::

## Examples

:::card{title="PHPMailer SMTP Example" href="https://github.com/resend/resend-phpmailer-smtp-example" icon="arrow-up-right-from-square"}
See the full source code.
:::

## Related pages

- [Send emails with SMTP](./get-started-send-with-smtp.md)
- [Send Auth0 transactional emails with Resend](./get-started-send-with-auth0.md)
- [Send emails using Customer.io with SMTP](./get-started-send-with-customer-io-smtp.md)
- [Send emails using Django with SMTP](./get-started-send-with-django-smtp.md)
- [Send emails using Laravel with SMTP](./get-started-send-with-laravel-smtp.md)
- [Send emails using Liferay with SMTP](./get-started-send-with-liferay-smtp.md)
- [Send emails using Nodemailer with SMTP](./get-started-send-with-nodemailer-smtp.md)
- [Send emails using Rails with SMTP](./get-started-send-with-rails-smtp.md)
- [Send emails using Retool with SMTP](./get-started-send-with-retool-smtp.md)
- [Send emails using Supabase with SMTP](./get-started-send-with-supabase-smtp.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
