Search code examples
phpemailphpmailermailing-list

Bulk Mailing Performance Sending Method


I wrote a mailing script phpmailer/swiftmail supported. Actually small campaigns works fine, all mails arrive to receivers without spam or server resouce problems.

I have question about per connection sending performance. Which way better for sending action? (Subscriber specific different mail body)

First scenario;

  • Open Newsletter Data
  • Catch 100 Subscriber on task list
  • Replace Newsletter Data/Header For Each Subscriber and Save to New Array
  • Call PhpMailer - Common SMTP Connection settings
$mail->SMTPKeepAlive = true;
foreach($newArray as $k=>$v){
  $mail->AddAddress($k, $v['name']);
  $mail->Subject  =  $v['subject'];
  $mail->Body = $v['content'];
  $mail->Send();
}
  $mail->smtpClose();

Second scenario (Current method on my script, I've call phpmailer class into record loop);

  • Open Newsletter Data
  • Open Task List 100 record
while($rs = $sql->fetch_assoc()){
  Replace Newsletter Data/Header
  Call PhpMailer - Common SMTP Connection settings
  $mail->SMTPKeepAlive = true;
  $mail->AddAddress($rs['mail'], $rs['name']);
  $mail->Subject  =  $campRs['subject'];
  $mail->Body = $campRs['content'];
  $mail->Send();
}
  $mail->smtpClose();

I'm confused about that, if I go for large amount mailing list, any server or script problems may occur?

Best regards!


Solution

  • The vast majority of time spent sending an email is the SMTP communication between your web server and the SMTP server it is talking with.

    Both scenarios are likely to be equivalently fast.

    If you need to increase performance, look into having multiple threads sending to different email addresses concurrently.