我有一个 php 页面,它显示 mysql 数据库中每个用户的课程表数据,如下所示:
$result = mysql_query($sql);
echo "<table border='0'>
<thead>
<tr>
<th>Class Link</th>
<th>Student Skype ID</th>
<th>Student Name</th>
<th>Faculty Name</th>
<th>Class Name</th>
<th>USA Date (DD/MM/YY)</th>
<th>USA Start Time</th>
<th>USA End Time</th>
<th>India Date (DD/MM/YY)</th>
<th>India Start Time</th>
<th>India End Time</th>
<th>Status</th>
</tr>
</thead>";
while($row = mysql_fetch_array($result))
{
echo "<tbody>";
echo "<tr>";
echo "<td><a href=\"".$row['class_link']."\" target='blank'>Start Class</a></td>";
echo "<td>" . $row['skype_id'] . "</td>";
echo "<td>" . $row['student_name'] . "</td>";
echo "<td>" . $row['faculty_name'] . "</td>";
echo "<td>" . $row['subject_name'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['starttime'] . "</td>";
echo "<td>" . $row['endtime'] . "</td>";
echo "<td>" . $row['facdate'] . "</td>";
echo "<td>" . $row['facstarttime'] . "</td>";
echo "<td>" . $row['facendtime'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
echo "</tbody>";
}
echo "</table>";
现在我有以下 php 电子邮件脚本
$to = '[email protected] /cdn-cgi/l/email-protection';
$subject = "Your Class Schedule";
$message = **'HOW CAN I PUT THE DATA FROM MYSQL HERE?'**;
$headers = 'From: [email protected] /cdn-cgi/l/email-protection' . "\r\n" .
$headers = "MIME-Version: 1.0" . "\r\n" .
$headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n" .
'Reply-To: [email protected] /cdn-cgi/l/email-protection' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
正如上面代码的 $message 中提到的,我想将检索到的数据放入 $message 部分,以便它进入邮件。
有人可以帮忙吗?
根据您的 mysql 数据的来源及其存储方式,您不能检索它并将其添加到 $message 变量中吗?
<?PHP
$query = "SELECT * FROM yourtable WHERE youridentifier = 'unique'"
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$content = $row['field with email content']
// or if there is more than one field
$content2 = $row['field with more email content']
}
// then you can create the "message" as you wish
$message = "Greetings ".$content.",
you are receiving this email because of blah. ".$content2."
Thank you,
code guy"
// Then you can still use $message as your variable
}
?>
按照您的要求格式化(HTML 或非 HTML 等).. 并邮寄出去。
对于多行,稍微改变 while ..
<?PHP
// give your message the starting string
$message = 'Greetings,
you are receiving this email as an invoice as follows:
<table style="width: 80%;">
<tr>
<td>Description</td>
<td>Cost</td>
<td>Weight</td>
<td>Color</td>
</tr>
'
$query = "SELECT * FROM yourtable WHERE youridentifier = 'unique'"
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$message .= " <tr>";
$message .= " <td>".$row['itemdescription']."</td>";
$message .= " <td>".$row['cost']."</td>";
$message .= " <td>".$row['shippingweight']."</td>";
$message .= " <td>".$row['color']."</td>";
$message .= " </tr>";
}
// then update the message with the ending
$message .= "
</table>
Thank you,
code guy"
// Then you can still use $message as your variable
}
?>
该假设是如果您使用的是 HTML 格式的电子邮件,否则它只是格式化的文本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)