A wrapper around PHPMailer to make it easier to use.

1.2.1 2023-08-08 08:08 UTC

This package is auto-updated.

Last update: 2024-07-08 10:01:18 UTC


PHPMailer Wrapper

This package makes it easier to send more advanced emails with PHPMailer.

If you just want to be able to send basic emails, using a variety of different possible drivers, you may be interested in the emailers package instead.


One can install the package with Composer by running:

composer require programster/phpmailer-wrapper

Example Usage

Below is an example of how one may use this tool to send an invoice as an attachment in an email to another person, being sure to provide both an HTML message, and the plaintext alternative, in case any of the recipients cannot view HTML emails. In this example, we also CC the accounts email address.


use Programster\Phpmailer\Attachment;
use Programster\Phpmailer\AttachmentCollection;
use Programster\Phpmailer\Contact;
use Programster\Phpmailer\ContactCollection;
use Programster\Phpmailer\PhpMailerEmailer;
use Programster\Phpmailer\SecurityProtocol;

require_once(__DIR__ . '/vendor/autoload.php');

# Create the emailer. We can use this to send() any number of emails.
$mailer = new PhpMailerEmailer(
    smtpHost: '', 
    smtpUser: '', 
    smtpPassword: 'myPasswordGoesHere', 
    securityProtocol: SecurityProtocol::TLS,
    from: new \Programster\Phpmailer\Contact('', 'My Name'),
    smtpPort: 587

# Send an email
    subject: 'Latest Invoice',
    plaintextMessage: "Please find attached my latest invoice.",
    htmlMessage: "<p>Please find attached my latest invoice.</p>",
    to: new ContactCollection(new Contact("", "Client Name")),
    cc: new ContactCollection(new Contact("accounts@company.domain", "Accounts")),
    attachments: new AttachmentCollection(new Attachment(__DIR__ . '/invoice.pdf', "my-invoice.pdf"));