如何基于数据库查询结果生成邮件内嵌HTML表格用于开发者错误通知
没问题!我根据你提供的查询结果(包含ID、姓名、邮箱、角色、创建时间这几列数据),帮你写了一份适合作为错误通知邮件的HTML表格代码,专门针对邮件客户端做了兼容优化,方便开发者查看:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>数据库查询结果错误通知</title> <style> /* 适配邮件客户端的基础样式,配合内联样式使用 */ body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f4f4f4; } .email-container { max-width: 600px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } table { width: 100%; border-collapse: collapse; margin-top: 15px; } th { background-color: #f0f0f0; padding: 10px; text-align: left; border-bottom: 2px solid #ddd; } td { padding: 10px; border-bottom: 1px solid #ddd; } .alert-title { color: #dc3545; font-size: 1.2em; margin-bottom: 10px; } </style> </head> <body> <div class="email-container"> <h2 class="alert-title">⚠️ 数据库查询结果错误通知</h2> <p>以下是触发错误的数据库查询结果,请开发者排查问题:</p> <table> <thead> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Role</th> <th>Created At</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Alice Smith</td> <td>alice@example.com</td> <td>admin</td> <td>2024-01-15 09:30:00</td> </tr> <tr> <td>2</td> <td>Bob Johnson</td> <td>bob@example.com</td> <td>editor</td> <td>2024-01-16 14:15:00</td> </tr> <tr> <td>3</td> <td>Charlie Brown</td> <td>charlie@example.com</td> <td>viewer</td> <td>2024-01-17 10:00:00</td> </tr> </tbody> </table> <p style="margin-top: 20px; color: #666;">如果需要更多信息,请查看系统日志或联系运维人员。</p> </div> </body> </html>
代码说明:
- 采用内联+内嵌样式组合,避免主流邮件客户端过滤外部样式,保证显示效果一致
- 加入醒目的错误标题,让开发者第一时间注意到通知性质
- 表格做了清晰的样式区分,表头灰色背景、数据行底部边框,提升可读性
- 底部补充了引导信息,方便后续排查动作
如果你的查询结果数据有变动,只需要修改<tbody>里的<tr>行内容即可。
内容的提问来源于stack exchange,提问作者phalondon
相关产品推荐
相关产品推荐

