CF8 - DB Read / Loop / E-Mail

send multiple database records in a formatted email using ChronoForms.

Overview

The issue occurs because the looped data cannot be directly passed to the email action.
Process the data array with a custom PHP function to format it as HTML, then pass the resulting HTML to the email action.

Answered
ChronoForms v8
rb rbock 27 Feb, 2024
Good day!

I would like to read several data records from a DB and send them formatted via email. I can display the data via loop, but I can't send it by email.
rb rbock 01 Mar, 2024
Answer
1 Likes
Ok... I solved it... I read the array with a PHP script and then pass the formatted table to the mail action.
rb rbock 01 Mar, 2024
Can be marked as solved!
rb rbock 09 Mar, 2024
function my_table($array){
$html = '<table>';
$html .= '<tr>';
foreach($array[0] as $k1=>$v1){
$html .= '<th>' . htmlspecialchars($k1) . '</th>';
}
$html .= '</tr>';

foreach( $array as $k1=>$v1){
$html .= '<tr>';
foreach($v1 as $k2=>$v2){
$html .= '<td>' . htmlspecialchars($v2) . '</td>';
}
$html .= '</tr>';
}

$html .= '</table>';
return $html;
}

$array = $this->get("data");

return my_table($array);
This topic is locked and no more replies can be posted.