Home/Email API/PHPMailer via Composer

PHPMailer via Composer

composer require phpmailer/phpmailer takes ten seconds. It gives you a clean SMTP client, and precisely nothing that decides whether the email lands.

Verified By Kam Low, Co-founder · Updated

The install and the honest setup

PHPMailer is the right library if PHP must speak SMTP: actively maintained, handles encoding and attachments, escapes the injection traps mail() invites.

Terminal + PHPcomposer
composer require phpmailer/phpmailer

$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = "smtp.example.com";  $mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "user";  $mail->Password = "pass";
$mail->setFrom("[email protected]");  $mail->addAddress("[email protected]");
$mail->Subject = "Welcome";  $mail->msgHTML("<p>You're in.</p>");
$mail->send();

What the install doesn't buy you

Deliverability needs more than that: an authenticated domain with SPF, DKIM, and DMARC aligned, warmed sending infrastructure, bounce and complaint handling, and a suppression list. PHPMailer transports; it cannot do any of those.

The comparison worth making is not PHPMailer vs mail(). It's ten lines of SMTP config and credentials vs one cURL POST with a bearer token, where the platform owns the landing.

We know exactly how heavy the real setup feels, because we measured ours: verifying a technical sending domain used to mean adding five DNS records, with four more recommended. Asking a developer to do that during onboarding is a non-starter, so we flipped the default. A fresh account reserves a protected Nitrosend brand subdomain without consuming provider resources. Preparing it creates DNS and provider infrastructure on demand; the first live send waits for readiness and explicit selection, with Free allowing 500 or 5,000 recipients per rolling 24 hours by sender standing. Composer gives you the library in ten seconds. Your first send deserves the same respect for your time.

Same logic applies to the email itself. Installing a library doesn't design the message any more than it delivers it, which is why we keep a dedicated email design skill on GitHub that does better anti-slop design than any default template. The tooling should raise the craft, not just move the bytes.

Full parameters and responses live in the REST API docs and the API reference.

The trap
Gmail app password
abcd efgh ijkl mnop
✕ 500 emails/day cap
✕ breaks when 2FA settings change
✕ a full-inbox credential in your code
The fix
POST /v1/messages
Authorization: Bearer ns_live_…
✓ scoped API key, revoke anytime
✓ Free plan, unlimited contacts
✓ delivery events you can act on

Go deeper

Here is the deeper point, honestly. The fix for "how do I send email in PHP" is not a better library, it is not installing one at all. Describe the send to Claude, Cursor, or Codex and our MCP server drafts and sends it on the same account and key, no composer require and no PHPMailer object to configure.

The one-POST version: send email with PHP. Why the mail() starting point fails: PHP mail via SMTP. The port you pick matters less than the records behind it, so read SMTP ports alongside SPF, DKIM and DMARC authentication.

FAQ

How do I install PHPMailer with Composer?

composer require phpmailer/phpmailer, then configure an SMTP host, port, and credentials. It's the best SMTP client PHP has; it just doesn't touch deliverability, which lives in domain authentication and sender reputation.

PHPMailer or an email API?

PHPMailer when a legacy system requires SMTP. An email API otherwise: less config, no credentials in code, and delivery events built in.

First send in thirty seconds.

Unlimited contacts. Choose your sending volume.

Campaigns, flows and transactional email on every plan. See current prices, included allowances and prepaid services.

Compare plans → · Pricing for agents