View Full Version : How do i include array data in php mail?

09-03-2009, 01:23 AM
Ok ive baffled my self for some reason, as in the title How do i include array data in php mail?

The Code i have:

I have stored post ids in a variable $ids array:

$ids[]= $row['ID'];

i have then created a foreach ( i dont actually want to out put this data as it is meant to be included in the mail message)

foreach ($ids as $expired){
echo '<a href="http://www.domain.com?s='.$expired.'">Link Text</a><br />';

and the mail code:

mail("info@domain.com","email subject","email body","Content-Type: text/html; charset=iso-8859-1\n");

So how do i list the contents of the array $ids[] in the mail message / email body i might be over thinking something!? any help is apreciated.

09-03-2009, 02:31 AM
foreach ( $ids as $i => $expired )
$ids[$i] = '<a href="http://www.domain.com?s=' . $expired . '">Link Text</a>';

$ids = implode( "\n", $ids );

"email subject",
nl2br( "email body\n\nExpired IDs:\n{$ids}" ),
"Content-Type: text/html; charset=iso-8859-1\n"

09-03-2009, 02:33 AM
Can't you just assign the data to a variable then include it in the message like:

foreach ($ids as $expired){
$message .= '<a href="http://www.domain.com?s='.$expired.'">Link Text</a><br />';

then send $message in replace of "email body"?

09-03-2009, 03:09 AM
Wow awesome just tested your code and it works just as it should.

i thought there had to be a way to extract the info from the array! and ive learnt something new too , not bad haha, thanks @kbluhm (http://www.codingforums.com/showpost.php?p=860947&postcount=2)