sending simplexml values in an email
Posted: Mon Feb 07, 2011 7:48 am
I am trying to send the titles in an xml file to mysefl in an email, but only seem to be able to get the email to print 0 or 1,
I can echo the titles in the xml using the following code :
This will print on screen
Title One
Title Two
TitleThree etc...
So I can extract the titles in this way, but am not sure how to send those results in an email.
If I use mail() within the foreach statement and put in the message the variable $lc_title like this
I get an email for each title, but I want just one email with all the titles. Putting it outside just returns one value, not all of them.
I am not sure how to pass all the values in that foreach statement, out of it as a string to be used in my email.
I can echo the titles in the xml using the following code :
Code: Select all
if( ! $xml = simplexml_load_file('/path/to/my/file.xml') )
{
echo 'unable to load XML file';
}
else
{
foreach( $xml as $item )
{
//returns all the <title> from the xml file
$lc_title = $item->title;
echo $lc_title.'<br />';
}
}
Title One
Title Two
TitleThree etc...
So I can extract the titles in this way, but am not sure how to send those results in an email.
If I use mail() within the foreach statement and put in the message the variable $lc_title like this
Code: Select all
$to = "me@mymail.com";
$subject = "book titles";
$message = "The titles of the books are <br />".$lc_title."<br />";
$from = "server@mysite.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
I am not sure how to pass all the values in that foreach statement, out of it as a string to be used in my email.