I have a PHP array, and I need to test the content of that array via an email. I'm aware that we can see the entire array using var_dump()
, but how can I send that output in an email?
You can use print_r( $array, true )
to get the output as a string. You can then pass this into your message body. The second paramter instructs the method to return the value rather than output it directly, permitting you to handle the results.
$message = "Results: " . print_r( $array, true );
First Convert your array string using foreach() or implode function. I am using foreach to convert array to string..
Where string will be key and value pairs.
$data = '';
foreach ($array as $key=>$value){
$data .= $key.'-------'.$value;
$data.= "\n";
}
or use following code to convert array to string.
$data = implode("\n", $array);
Now send that using php mail function.
mail($recipient, $subject, $data, $headers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With