Hi I have an array of data, that I'd like to send as the body part of an email. The code I have so far is: $items = array(); foreach($xmlData->Item as $item) { //do some stuff here } $to = "test@example.com"; $subject = "Import Successful"; foreach($items as $record) { $body .= $record; } if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } Code (markup): But I get that $body is undefined. Any ideas what I'm doing wrong?
You need to have $body = ''; before you start adding to it. Apart from that your script is just fine. To make it a bit more readable change foreach($items as $record){ $body .= $record; } PHP: to foreach($items as $record){ $body .= $record . "\n"; } PHP: \n puts a line break after every record and has to be in double quotes.
Ok, so I added the bits of code you mentioned, but the $body part of the email is still blank. Any ideas why? Thanks UPDATED The problem was I need to access the array data like $body .= $record->Name Code (markup): All is working fine now Thanks