We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Sending Multiple Emails with Same Attachment

Development and Programming

Ryan Irelan's avatar
Ryan Irelan
444 posts
16 years ago
Ryan Irelan's avatar Ryan Irelan

I have an extension that sends out emails to certain members (based on member group and custom profile fields). For some members, this includes a file attachment. All of the members receiving attachments receive the same exact attachment.

The problem I’m having is that the emails are getting a duplicate attachment and it increases +1 for each email. So, if there are 20 members eligible to receive the attachment, the 20th email sent will have the attachment 20 times.

I’m using straight-foward EEmail class code for this, just like is specified in the docs under Sending Multiple Email.

So, can attachments not be used when sending emails in a loop?

(As an aside, I’ve noticed that initialize() function does not clean up attachments.)

Any thoughts/help/advice would be great. Thanks!

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Are you calling attach() inside the loop? Sounds like that might be the case, as that would add it to the $attach_name class array again and again.

       
Ryan Irelan's avatar
Ryan Irelan
444 posts
16 years ago
Ryan Irelan's avatar Ryan Irelan

I am calling attach() in the loop. Yeah, exactly, it just keeps adding to the array. Am I implementing it incorrectly and that’s the expected behavior?

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Well, in 1.x, where attach() is undocumented and incomplete, yes. In CI/2.0 you’ll notice that clear() resets file attachments unless it’s told not to specifically. In either case, if your goal is for every person to get the same attachment, then setting it once outside of the loop is the way you’d want to go to minimize overhead from redundant method calls.

       
Ryan Irelan's avatar
Ryan Irelan
444 posts
16 years ago
Ryan Irelan's avatar Ryan Irelan
Well, in 1.x, where attach() is undocumented and incomplete, yes. In CI/2.0 you’ll notice that clear() resets file attachments unless it’s told not to specifically. In either case, if your goal is for every person to get the same attachment, then setting it once outside of the loop is the way you’d want to go to minimize overhead from redundant method calls.

Yeah, I acknowledge I’m using an incomplete and undocumented feature. 😊 Of course the obvious fix you pointed out wasn’t so obvious to me. Gah! I’m all set now by taking it out of the loop.

Thanks for the assistance and for the details on 2.0, Derek.

Your nemesis,

Ryan

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Glad to help, Ryan.

Your nemesis, Ryan

::glares and shakes fist::

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.