I’m working on a zend framework based email project and I’m following some code samples online.. I can’t understand this line of code which apparently loops through different ‘parts’ of an email message. I have no idea how it works btw and suspect that theres some error taking place which my parser isn’t showing right.
foreach (new RecursiveIteratorIterator($mail->getMessage($i)) as $ii=>$part)
what does the above foreach loop mean?
It creates a new recursive iterator based on the contents of the message with id $i and loops through the parts of the e-mail. E-mails generally consist of multi-part messages, so the getmessage method probably has a call to retrieve the first part of the message after retrieving headers. The method to get the part likely calls itself (recursively) with an incrementing id to return the part, hence the $ii=>$part.
It is difficult to expand without knowing the full contents of the method call.
Example for Directory recursion
EDIT 2: Using the example on the linked site:
This retrieves all the parts and looks for a plaintext part. It is a way of looping through something recursively allowing manipulation on it.