Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 185799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:32:05+00:00 2026-05-11T15:32:05+00:00

I think I must be doing something wrong here because my code only sent

  • 0

I think I must be doing something wrong here because my code only sent an email to the last subscriber in the table. When I log the array of subscribers, its obvious that there are more than one that it is trying to send to. I think the problem has to do with trying to batch them together…What is the best way for me to do this? I’m trying to create one message, with an attachment, then send address each one individually, and send them all out as one batched process. Here’s my code:

    $subscribersManager = new DD_Subscribers_Manager();     $subscribers = $subscribersManager->getAllSubscribers();       $subject = $form->getElement('subject')->getValue();     $body = $form->getElement('body')->getValue();     $filename = $form->getElement('bulletin')->getValue();     $filepath = Zend_Registry::get('rootDir') . '/public/downloads/archive/' . $filename;      $config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'fake@email.com', 'password' => 'password');     $smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);      foreach ($subscribers as $subscriber) {         $message = new Zend_Mail('utf-8');         $message->setFrom('fake@email.com', 'My Fake Mailing List')                 ->addTo($subscriber->email)                 ->setSubject($subject)                 ->setBodyText($body);         $attachment = $message->createAttachment(file_get_contents($filepath));         $attachment->type = 'application/pdf';         $attachment->filename = $filename;     }     $message->send($smtpConnection); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:32:05+00:00Added an answer on May 11, 2026 at 3:32 pm

    This looks like a scope issue: You create $message inside the foreach loop and only send the last one (since $message->send() is called after the foreach.

    Basically, you overwrite the value of $message each time the foreach loop iterates. Move $message->send into the foreach loop to send one email per iteration. There may be another way to create an array of messages and send them all at once, but I’m not familiar with ZendMail.

    EDIT: Actually, if you read the documentation on Zend_Mail you can call $message->addTo() to add additiional recipients (more than 1) to a single message. Your code could change to something like:

    $message = new Zend_Mail(); $message->setFrom('fake@email.com', 'My Fake Mailing List')                                 ->setSubject($subject)                                 ->setBodyText($body);  foreach($subscribers as $subscriber){      $message->addTo($subscriber->email); } $message->send(); 

    Zend_Mail – adding recipients

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 222k
  • Answers 222k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should be able to adapt the example code here… May 13, 2026 at 12:28 am
  • Editorial Team
    Editorial Team added an answer Strictly speaking, Application.cfm doesn't define an application; cfapplication does. If… May 13, 2026 at 12:28 am
  • Editorial Team
    Editorial Team added an answer The only way currently is to hit /admin/invite_user/ as a… May 13, 2026 at 12:28 am

Related Questions

I'm new to jQueryUI and I think I am overlooking something very basic... Quick
I would like to keep model binding when doing ajax calls from my view.
I am new to Python and Numpy, and I am facing a problem, that
I might be doing something completely wrong here but for some reason the values

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.