Question

Array
(
    [id] => 
    [name] => hjkjh
    [email] => hjkhjk@gail.zfcc
    [address] => fsdf
    [gender] => female
    [city] => MUMBAI
    [hobbies] => Array
        (
            [0] => dance
            [1] => reading
        )

    [myimage] => 
)

I want to passs this values in body of email msg how to pass the VALUES this array is in $data I want as this

name = value
email= value

Can someone please help

Was it helpful?

Solution 2

You can use as

$name = $your_array["name"];
$email = $your_array["email"];
$address = $your_array["address"];
$gender = $your_array["gender"];
$city = $your_array["city"];
$hobbies = '';

foreach($your_array["hobbies"] as $key=>$val){
  $hobbies .= $val.' ';
}

And finally you can use the above variables in the email code.

Update from your last comment, you can do the way you are doing as

    foreach($data as $key=>$value) { 
    $body .=$key."="; 
    if($key== 'hobbies'){
        foreach($value as $k=>$v){
            $body .= $v.' ';
        }
        $body .= "\n";
    }else{
            $body .=$value."\n"; 
    }

} 
$body .= "\n"; 

OTHER TIPS

Check this :

$data=array(
    "id" =>1, 
    "name" => "hjkjh",
    "email" => "hjkhjk@gail.zfcc",
    "address" => "fsdf",
    "gender" =>  "female",
    "city" => "MUMBAI",
    "hobbies" => Array
        (
         0 => "dance",
         1 => "reading"
         ),
    "myimage" => ""
);

$body="";
$body.="Name :".$data['name']."<br/>";
$body.="Email :".$data['email']."<br/>";
$body.="Address :".$data['address']."<br/>";
$body.="Gender :".$data['gender']."<br/>";
$body.="City :".$data['city']."<br/>";
$body.="Hobbies :".$data['hobbies'][0].", ".$data['hobbies'][1]."<br/>";
echo $body;

And Its O/P is as given:-

Name :hjkjh
Email :hjkhjk@gail.zfcc
Address :fsdf
Gender :female
City :MUMBAI
Hobbies :dance, reading

I Hope this is what you are needed!

$string = implode( ", ",$array);  

will work.... visit the link http://www.dreamincode.net/forums/topic/233154-printing-out-a-php-array-in-an-email-body/ for details ........thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top