Answer the question
In order to leave comments, you need to log in
How to parse and send an array as a table via mail()?
Good afternoon!
There was a need to pull information from the database and send it in the form of a table to e-mail.
I can send mail, operate with data from the database too, but I don’t understand how I can display the table in message so that the table with all the selected rows is sent. Tried to make a loop, but nothing comes out.
$subject = "Тема";
require_once('db.php');
function get_s()
{
global $link;
$link->set_charset("utf8");
$p1 = 'xxx';
$sql = "SELECT * FROM current WHERE par= '$p1' ORDER BY id";
$result = mysqli_query($link, $sql);
$ps = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $ps;
}
$message = '<table>
<thead>
<tr>
<th scope="col">col1</th>
<th scope="col">col2</th>
<th scope="col">col3</th>
<th scope="col">col4</th>
</tr>
</thead>
<tbody>
<tr>
<th></th>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>';
$headers= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
mail($to, $subject, $message, $headers);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question