0

Hello world,

I have a DB in mysql, and want to create a code that will select all this DB data ( there are 10 records) and send it via email (created send email in php).

Anyone have a such example please ?Could you help me =?

Thanks in advance.

2
Contributors
2
Replies
7
Views
8 Years
Discussion Span
Last Post by Arsench
0

After connecting to your database all you'd need to do is do a SELECT and do a while loop to add each entries data to an email message.

Here is an example, with syntax for MySQL:

$to      = 'youremail@example.com';
$subject = 'Your Subject';
		
$message = <<<EOT
<html>
<head>
  <title>Your Subject</title>
</head>
<body>
<p>Here is the data from the Example table:</p>
<table>
<tbody>
<tr>
<th>Field 1</th>
<th>Field 2</th>
<th>Field 3</th>
</tr>
EOT;

$sql = "SELECT * FROM `your_table`";
$result = mysql_query($sql);
while($data = mysql_fetch_array($result))
{
$message .= '
<tr>
<td>.'$data['field_1'].'</td>
<td>.'$data['field_2'].'</td>
<td>.'$data['field_3'].'</td>
</tr>
';
}

$message .= <<<EOT
</tbody>
</table>
</body>
</html>
EOT;

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Example <youremail@example.com>' . "\r\n";

mail($to, $subject, $message, $headers);
0

After connecting to your database all you'd need to do is do a SELECT and do a while loop to add each entries data to an email message.

Here is an example, with syntax for MySQL:

$to      = 'youremail@example.com';
$subject = 'Your Subject';
		
$message = <<<EOT
<html>
<head>
  <title>Your Subject</title>
</head>
<body>
<p>Here is the data from the Example table:</p>
<table>
<tbody>
<tr>
<th>Field 1</th>
<th>Field 2</th>
<th>Field 3</th>
</tr>
EOT;

$sql = "SELECT * FROM `your_table`";
$result = mysql_query($sql);
while($data = mysql_fetch_array($result))
{
$message .= '
<tr>
<td>.'$data['field_1'].'</td>
<td>.'$data['field_2'].'</td>
<td>.'$data['field_3'].'</td>
</tr>
';
}

$message .= <<<EOT
</tbody>
</table>
</body>
</html>
EOT;

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Example <youremail@example.com>' . "\r\n";

mail($to, $subject, $message, $headers);

Greate, God bless you, its work very good. Thank you very much

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.