Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts

    Question How do i include array data in php mail?

    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:

    PHP Code:
    $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)

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


    and the mail code:
    PHP 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.
    "I have not failed, I've found 10,000 ways that don't work" Thomas Edison

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    PHP Code:
    foreach ( $ids as $i => $expired )
    {
        
    $ids[$i] = '<a href="http://www.domain.com?s=' $expired '">Link Text</a>';
    }

    $ids implode"\n"$ids );

    mail(
        
    "info@domain.com",
        
    "email subject",
        
    nl2br"email body\n\nExpired IDs:\n{$ids}" ),
        
    "Content-Type: text/html; charset=iso-8859-1\n"
    ); 
    Last edited by kbluhm; 09-03-2009 at 02:35 AM.

  • Users who have thanked kbluhm for this post:

    maxvee8 (09-03-2009)

  • #3
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    Can't you just assign the data to a variable then include it in the message like:

    PHP Code:
    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"?

  • #4
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts
    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
    Last edited by maxvee8; 09-03-2009 at 03:17 AM.
    "I have not failed, I've found 10,000 ways that don't work" Thomas Edison


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •