Skip to main content
Resend Docs

Search documentation

Type to search this documentation.

On this pageOverview

Send emails using PHPMailer with SMTP

Before you start, you'll need:

  1. Install

    Get the PHPMailer package.

    php
    composer require phpmailer/phpmailer
  2. 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
    <?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.';
    }

PHPMailer SMTP Example

See the full source code.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu