Some help please!

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
Osirion
Forum Newbie
Posts: 2
Joined: Sat Feb 09, 2008 7:22 am

Some help please!

Post by Osirion »

Ok, first off - great script - so easy to use and damn powerful - does everything I need (so far!) :)

Now to explain my scenario:
I am using this script to e-Mail all my clients invoices every month. So I have a cron that generates the PDF's and then e-Mails the invoices through with the attachments. While I have this all in one loop, I would think it would be faster/less resource intensive to do this in a batchSend instead of using one send per run of the PDF generation loop?

My limits:
I have a 500 e-Mail limit per hour from my ISP with 60 pop checks per hour.


My script:

Code: Select all

 
require_once("includes/swift_mailer/lib/Swift.php");
require_once("includes/swift_mailer/lib/Swift/Connection/SMTP.php");
 
$swift =& new Swift(new Swift_Connection_SMTP("mail.osirion.co.za"))
 
while ($invoices_data = mysql_fetch_array($invoices_query))
{
   /*Invoice generated into a pdf here*/
 
   $message =& new Swift_Message("Invoice ". $invoices_data['invoice']);
   $message->setContentType("text/html");
   $message->attach(new Swift_Message_Part(new Swift_File("includes/invoice_template.html"), "text/html"));
 
   $message->attach(new Swift_Message_Attachment(new Swift_File("invgendir/". $invoices_data['id'] .".pdf"), $invoices_data['id'] .".pdf", "application/pdf"));
   $message->attach(new Swift_Message_Attachment(new Swift_File("images/logo.gif", "image/gif")););
   $message->attach(new Swift_Message_Attachment(new Swift_File("images/header_top_splitter.gif", "image/gif")););
 
 
   $swift->send($message, "client@clientsdomain.poo", "accounts@mydomain.wee");     
}
$swift->disconnect();
Is there a way to optimise this or is this as good as it gets ?
Thanks in advance :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Some help please!

Post by Chris Corbyn »

Ah, I was about to say you can move all your attach() calls outside the loop, but since they all appear to be dynamic content you probably already have it set up the way you need. Unfortunately, sending masssive amounts of emails with multiple attachments is never going to be that fast because it takes time to:

a) encode the data in the attachments
b) transport the mail over a network

I have found that using a Disk cache is faster than storing everything in memory (which is the opposite to what you'd expect!).

There are some notes in the documentation about this:

http://www.swiftmailer.org/wikidocs/v3/misc/caching
Osirion
Forum Newbie
Posts: 2
Joined: Sat Feb 09, 2008 7:22 am

Re: Some help please!

Post by Osirion »

Thanks :)

I just really want the least server resource intensive method of doing this because I dont want my hosting provider suspending my account for over usage of the server resources and so forth :P
Post Reply