Installation

Install PHPMailer via Composer:

composer require phpmailer/phpmailer

Basic Configuration

<?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.lettermint.co';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'lettermint';
    $mail->Password   = 'your-api-token';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port       = 587;

    // Recipients
    $mail->setFrom('sender@yourdomain.com', 'Your Name');
    $mail->addAddress('recipient@example.com', 'Recipient Name');

    // Content
    $mail->isHTML(true);
    $mail->Subject = 'Test Email';
    $mail->Body    = '<h1>Hello!</h1><p>This is a test email.</p>';
    $mail->AltBody = 'Hello! This is a test email.';

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

Advanced Features

Multiple Recipients

$mail->addAddress('user1@example.com');
$mail->addAddress('user2@example.com');
$mail->addCC('manager@yourdomain.com');
$mail->addBCC('archive@yourdomain.com');

Attachments

$mail->addAttachment('/path/to/file.pdf');
$mail->addAttachment('/path/to/image.jpg', 'custom-name.jpg');

Custom Headers

$mail->addCustomHeader('X-Custom-Header', 'Custom Value');
$mail->addCustomHeader('X-Priority', '1');