Mails are seemingly not sent

Permalink 1 user found helpful
I have inherited a project that is running v5.4.1.1 and has been so heavily customized that I'm afraid to upgrade.

There is a job that runs and then sends a notification email. Heres the code for sending the emails:
$emailNotificationRecipients = array(
      'John Doe'=>'johndoe@email.com'
      ,'Jane Doe'=>'janedoe@email.com'
     ,'Juan Doe'=>'juan@somewhere.com'
);
foreach ($emailNotificationRecipients as $name=>$email) {
    $mh = Loader::helper('mail');
    $mh->to($email,$name);
    $mh->from( 'no-reply@thesite.com' );
    $mh->addParameter('message_field', $this->logger);
    $mh->load('alert_account_report');
    $mh->setSubject('Daily Report' );
    $mh->sendMail();
    unset($mh);
}

This code only seems to send emails to the last person in the $emailNotificationRecipients array.

I've tried various things:
* Commenting out the last 2 names. The first person does indeed receive the email
* Comment out the last name. The 2nd person receives the email.
* Send out one email with all recipients instead of multiple emails. Does not work.

Is there a bug in the mail helper/Zend email or in my code somewhere?

I'm thinking about just using built-in PHP mail() to do this, but then have to recreate everything. blah.

Any help is appreciated.

SkyBlueSofa
 
mkly replied on at Permalink Reply
mkly
Hmmm... maybe try loading the helper then creating the object
$emailNotificationRecipients = array(
      'John Doe'=>'johndoe@email.com'
      ,'Jane Doe'=>'janedoe@email.com'
     ,'Juan Doe'=>'juan@somewhere.com'
);
Loader::helper('mail');
foreach ($emailNotificationRecipients as $name=>$email) {
    $mh = new MailHelper();
    $mh->to($email,$name);
    $mh->from( 'no-reply@thesite.com' );
    $mh->addParameter('message_field', $this->logger);
    $mh->load('alert_account_report');
    $mh->setSubject('Daily Report' );
    $mh->sendMail();
    unset($mh);

Actually you could probably just reset the mail and resend
$emailNotificationRecipients = array(
      'John Doe'=>'johndoe@email.com'
      ,'Jane Doe'=>'janedoe@email.com'
     ,'Juan Doe'=>'juan@somewhere.com'
);
$mh = Loader::helper('mh');
foreach ($emailNotificationRecipients as $name=>$email) {
    $mh->to($email,$name);
    $mh->from( 'no-reply@thesite.com' );
    $mh->addParameter('message_field', $this->logger);
    $mh->load('alert_account_report');
    $mh->setSubject('Daily Report' );
    $mh->sendMail();
    $mh->reset();
}