Adding recipients
For the sake of simplicity in this case our application is storing the role of users as a single field in the
Users table so to retrieve all admin users we make the following query:
$users = new Users;
$where = array(
'role = ?' => Zend_Auth::getInstance()->getIdentity()->id,
'user_id != ?' => 'admin'
);
$rows = $users->fetchAll($where);
You??™ll notice the additional term in the argument to fetchAll() to filter out cases where if, as is quite likely,
the submitter is also an admin user. This prevents them receiving an additional and unnecessary admin email
on top of the CC (carbon copy) version they??™d receive as a submitter. In some cases you may actually prefer to
send a different version to the submitter from the one sent to the support team so this is largely an
implementation preference.
Having retrieved all admin users we can now loop over them and add them to the mail with a ???To??? header
like so:
Licensed to Menshu You
Zend Framework in Action (Ch010) Manning Publications Co. 10
foreach ($rows as $adminUser) {
$mail->addTo($adminUser->email, $adminUser->name);
}
Next we??™ll retrieve the email details for the submitter using their id from Zend_Auth and add them to the
mail with a CC header:
$users->find(Zend_Auth::getInstance()->getIdentity()->id);
$submitter = $users->current();
$mail->addCC($submitter->email, $submitter->name);
We also have the option of adding users with a BCC (blind carbon copy) header using
Zend_Mail::addBcc() but don??™t need it in this case.
Pages:
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260