如何使引导模态表单从表格的电子邮件输入时,相应的按钮的表格行被单击



所以我遇到的问题是,无论我从表中单击什么按钮,它只是输入数据库中的第一封电子邮件。我想让它抓取被点击按钮的相应记录的电子邮件,这是表格:-

<table class="table table-striped table-responsive">
<thead> 
<tr>
<th scope="col">#</th> 
<th scope="col">Name</th>
<th scope="col">EMAIL</th>
<th scope="col">SUBJECT</th>
<th scope="col">MESSAGE</th>
<th scope="col">TIME</th>
<th scope="col">Action</th>
<!-- <th scope="col">status</th> -->
</tr>
</thead>
<?php
$sql = "SELECT  id, name, email, subject, message, time FROM contact";
$records = mysqli_query($conn, $sql);
// $products = mysqli_fetch_array($records);
while($data = mysqli_fetch_array($records))
{
?>

<form method="post">
<tbody>
<tr>
<td><?php echo $data['id']; ?></td>
<td><?php echo $data['name']; ?></td>
<td><?php echo $data['email']; ?></td>
<td><?php echo $data['subject']; ?></td>
<td><?php echo $data['message'];?></td>
<td><?php echo $data['time']; ?></td> 
<td><a href="reply.php">reply</a></td>
<td><button type="button" name="submit" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal"data-bs-whatever="<?php echo $data['email'];?>">Reply</button></td></form>
</tr>   

上面的是切换模式的按钮。下面是模态本身

<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New message</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="POST" role="form" enctype="multipart/form-data" action="">
<div class="row">

下面的是我遇到问题的输入。最后一点是模态的剩余部分剩余模态

收件人:">
<div class=" col-md-6 mb-3">
<label for="Email-Subject" class="col-form-label">Email-Subject:</label>
<input type="text" class="form-control" name="subject" id="subject">
</div>

<div class="mb-3">
<label for="message-text" class="col-form-label">Message:</label>
<textarea class="form-control" rows="8" name="message" id="message"></textarea>
</div>

<div class=" col-md-6 mb-3">
<label for="attachment" class="col-form-label">Attachment</label>
<input type="file" class="form-control" name="file[]" multiple= "multiple" id="file">
</div>
</div>
<button name="submit" type="submit" class="btn btn-primary">Send mail</button>

</form>
</div>

</div>
</div>
</div>

this关闭while循环

<?php 
}
?>

这是PHP邮件发送器代码

<?php
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

if(isset($_POST['submit'])) {
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = "foxyfox069@gmail.com";
$mail->Password = "musa3310";
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom("foxyfox069@gmail.com");
$mail->addAddress($_POST['email']);
// $mail->addReplyTo($_POST['email'], $_POST['name']);
$mail->isHTML(true);    
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['message'];
for ($i=0; $i <count($_FILES['file']['tmp_name']) ; $i++) { 

$mail->addAttachment($_FILES['file']['tmp_name'][$i],$_FILES['file']['name'][$i]);
}
try {
$mail->send();
echo 'Your message was sent successfully!';
} catch (Exception $e) {
echo "Your message could not be sent! PHPMailer Error: {$mail->ErrorInfo}";
}
} 
else {
echo "There is a problem with the contact.html document!";
}
?>

你已经为while循环中的每一行定义了模态,所以你需要为所有模态保持唯一的id,否则你可以定义模态跳出循环并添加模态显示事件来定义电子邮件地址

最新更新