PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Fetching messages and simple methods

Messages can be fetched after you've opened the storage . You need the message number, which is a counter starting with 1 for the first message. To fetch the message, you use the method getMessage():

<?php
$message 
$mail->getMessage($messageNum);

Array access is also supported, but this access method won't supported any additional parameters that could be added to getMessage(). As long as you don't mind, and can live with the default values, you may use:

<?php
$message 
$mail[$messageNum];

For iterating over all messages the Iterator interface is implemented:

<?php
foreach ($mail as $messageNum => $message) {
    
// do stuff ...
}

To count the messages in the storage, you can either use the method countMessages() or use array access:

<?php
// method
$maxMessage $mail->countMessages();

// array access
$maxMessage count($mail);

To remove a mail, you use the method removeMessage() or again array access:

<?php
// method
$mail->removeMessage($messageNum);

// array access
unset($mail[$messageNum]);

Zend Framework