So the issue i am having is that no matter what button i click from the table it just inputs the first email in the database. i want it to grab the email of the corresponding record of the button that was clicked this is the table:-
<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>
above is the button that toggles the modal. below is the modal itself
<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">
below is the input i am having problems with. and the last bit is the remaing part of the modal remaining modal
Recipient: "><?php
}
?>
this closes the while loop
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
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!";
}
?>
this is the php mailer code
<?php use PHPMailer\\PHPMailer\\PHPMailer; use PHPMailer\\PHPMailer\\Exception; 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,其他方式您可以在循环外定义模态并添加模态显示事件来定义电子邮件地址。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.