我使用此代码生成表格:
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>{$row['rollNo']}</td>";
echo "<td>{$row['bgroup']}</td>";
echo "<td>{$row['first_name']}</td>";
echo "<td>{$row['last_name']}</td>";
echo "<td>{$row['phone']}</td>";
echo "<td>{$row['e_mail']}</td>";
echo "<td><input type='button' value='Send Email'></td>";
echo "</tr>";
输出:
当我点击Send Email
时,我想触发与该按钮对应的电子邮件的电子邮件。如何将按钮旁边的电子邮件地址作为mail()
功能的输入发送?
提前致谢!
答案 0 :(得分:1)
为了清楚起见,我会做同样的事情:
// Top of page:
if(isset($_POST['submit'])) {
// check the $_POST['id'] against your db
// if you have it in the db (you should!)
// send using the mail()
}
while($row = mysql_fetch_array($result)) { ?>
<tr>
<form method="post" action="">
<td><?php echo $row['rollNo']; ?></td>
<td><?php echo $row['bgroup']; ?></td>
<td><?php echo {$row['first_name']; ?></td>
<td><?php echo $row['last_name']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['e_mail']; ?></td>
<td>
<!-- hidden input here with the id (or whatever your auto incremented/unique value is in your table) -->
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<input type="submit" name="submit" value="Send Email"></td>
</form>
</tr><?php
} ?>
作为旁注,您不应该使用 mysql _ 库/函数。它是不安全的,并计划在将来的PHP版本中弃用。有一天你会醒来,发现你的数据库代码都不再有用了!