Integrations & Code Verified for 2026 Expert Reviewed

Bulk Email in PHP with PHPMailer: High-Speed SMTP Guide

Direct Answer Quick Summary for Senders:

To send bulk emails in PHP using PHPMailer, configure SMTPKeepAlive = true to keep the TCP connection open across multiple messages, use Port 587 with SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS, connect to 171mails' relay (relay.171mails.com), and clear recipient arrays between iterations with clearAddresses() to prevent memory leaks.

Key Takeaways

Set SMTPKeepAlive = true in PHPMailer to reuse the same SMTP connection for multiple recipients.
Always call clearAddresses() and clearAttachments() inside loops to prevent recipient leakage.
Avoid using PHP's native mail() function, which lacks SMTP authentication and DKIM signing.
171mails provides 4 Dedicated IPs and automated suppression scrubbing for high-volume PHP senders.

1. Optimized PHPMailer Bulk Sending Code

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    // Server settings
    $mail->isSMTP();
    $mail->Host       = 'relay.171mails.com';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'your_171mails_username';
    $mail->Password   = 'your_171mails_password';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port       = 587;
    $mail->SMTPKeepAlive = true; // REUSE CONNECTION

    $mail->setFrom('newsletter@yourdomain.com', '171mails Updates');
    $mail->isHTML(true);
    $mail->Subject = 'Monthly Community Update';
    $mail->Body    = '<h1>Welcome!</h1><p>Your monthly content digest.</p>';

    // Loop through recipient database
    foreach ($subscribers as $sub) {
        $mail->addAddress($sub['email'], $sub['name']);
        $mail->send();
        $mail->clearAddresses(); // Reset for next subscriber
        usleep(100000); // 100ms pacing delay (10 emails/sec)
    }

    $mail->smtpClose(); // Gracefully close connection
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

2. The Importance of SMTPKeepAlive

Without SMTPKeepAlive = true, PHPMailer opens a new TCP connection, executes a TLS handshake, authenticates with username/password, and closes the connection for every single recipient. This generates enormous latency. Keeping the socket alive accelerates delivery speed by up to 500%.

3. Handling PHP Script Execution Timeouts

Long-running CLI scripts should execute via PHP CLI rather than web servers (Apache/Nginx). Use set_time_limit(0) and monitor memory consumption using memory_get_usage() to ensure stability across large dispatches.

Frequently Asked Questions

Yes! 171mails automatically handles IP rotation across your 4 Dedicated IPs on our servers, so your PHPMailer script simply connects to relay.171mails.com and benefits from multi-IP rotation.

171mails parses bounces automatically via custom Return-Path headers and provides webhooks to sync bounce status back to your local MySQL database.

With SMTPKeepAlive active, a single PHP CLI process can comfortably send 25 to 50 emails per second over high-speed networks.
Enterprise Bulk Email Relay

High-Throughput SMTP Relays for PHP & PHPMailer Developers

Accelerate your PHP bulk email scripts with connection keep-alive, 4 Dedicated IPs, and real-time suppression scrubbing.

  • 100% compatible with PHPMailer, Symfony Mailer, and SwiftMailer
  • 4 Dedicated IPs (2 IPv4 + 2 IPv6 dual-stack) up to 1M sends
  • 100M+ real-time suppression database scrubbing
  • Test your PHP script with our $5 (₹399) sandbox
100K Email Plan
$29 /mo
4 Dedicated IPs Included

Related Questions & Guides

Platform, CRM & Stack Integrations
How to Send Bulk Emails in Laravel with SMTP (Queues & Jobs)

Learn how to send bulk emails in Laravel using queues, jobs, and high-throughput SMTP relays. Includes .env...

Platform, CRM & Stack Integrations
Bulk Email API for Node.js (High-Throughput SMTP & REST)

Send high-throughput bulk email in Node.js using Nodemailer and REST APIs. Master connection pooling, concu...

Platform, CRM & Stack Integrations
How to Connect Bulk SMTP Relay to WordPress (Complete Guide)

Connect high-volume SMTP relay to WordPress with WP Mail SMTP, FluentSMTP, or Post SMTP. Step-by-step tutor...

Volume, Scaling & Rate Limits
SMTP Concurrency, Connections & Rate Limits: Complete Guide

Master SMTP concurrency limits, connection pools, and MX rate limits. Learn optimal settings for Postfix, P...