如何发送电子邮件接受或拒绝预订请求
How to send an email accepting or rejecting a request for a reservation
我的目标是能够通过电子邮件接受或拒绝客户的请求。我所拥有的是我网站的后台,似乎每个人都提交了我的预订表格,提交后的客户收到一封电子邮件,说他们的确认正在等待中,此时管理员可以选择接受或拒绝预订,在该操作完成后,客户将收到一封包含回复的电子邮件。
现在,我尝试使用 "accept" 按钮,看看它是否有效。现在,我收到一条错误消息,提示地址无效 $mail->addAddress($_POST['EmailReser']);
//File listreser.php
<body style="background-color:white;">
<?php
$sql="select * from Reservas";
$res=$lig->query($sql);
?>
<div class="container">
<h1 align="center">List Reservations</h1> <br><br>
<table id ="tableUser" class="table table-striped display">
<thead>
<tr>
<th>Code of the reservation</th>
<th>Name </th>
<th>Last Name</th>
<th>Email</th>
<th>Telephone</th>
<th>Date </th>
<th>Time</th>
<th>Number of people</th>
<th>Message </th>
<th>State</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($lin=$res->fetch_array()){ ?>
<tr>
<td><?php echo$lin[Cod_Reserva]; ?></td>
<td><?php echo$lin[NomeReser]; ?></td>
<td><?php echo$lin[ApelidoReser]; ?></td>
<td><?php echo$lin[EmailReser]; ?></td>
<td><?php echo$lin[TelefoneR]; ?></td>
<td><?php echo$lin[DataR]; ?></td>
<td><?php echo$lin[Hora]; ?></td>
<td><?php echo$lin[NumPessoas]; ?></td>
<td><?php echo$lin[MensagemR]; ?></td>
<td><a style="padding-right:12px;" href=index.php?cmd=aceitar&Cod_Reserva=<?php echo $lin["Cod_Reserva"]; ?>><img src='images/check.png' width="20" height = "20" ></a><a href=index.php?cmd=rejeitar&Cod_Reserva=<?php echo $lin["Cod_Reserva"]; ?>><img src='images/close.png' width="15" height = "15" ></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
var_dump($_GET);
exit();
// $Cod_Reserva=$_REQUEST['Cod_Reserva'];
$Cod_Reserva=$_REQUEST['Cod_Reserva'];
//$EmailReser = $_GET['EmailReser'];
// $sql="select * from Reservas ";
$sql="select EmailReser from reservas where cod_reserva = $Cod_Reserva";
$res=$lig->query($sql);
//$lin=$res->fetch_array();
while ($lin=$res->fetch_array()){
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->CharSet = "utf-8";
$mail->Host='smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure='tls';
$mail->Username='email@gmail.com';
$mail->Password='****';
$mail->setFrom('email@gmail.com');
$mail->addAddress($lin['EmailReser']);
$mail->addReplyTo('email@gmail.com');
$mail->isHTML(true);
$mail->Subject='Your request has been confirmed';
$mail->Body = "message";
if(!$mail->send()){
echo "<script>
alert('There's been a mistake');
</script>";
}
else{
echo "<script>
alert('Email was sent with success');
</script>";
}
}
?>
您可以将带有 link 的按钮替换为发送接受电子邮件的单独 PHP 脚本。您需要包含足够的信息以了解您正在接受哪个预订(以及将其发送到哪里),并且您需要添加一些验证以确保只有 suitable 用户才能实际处理接受.
所以就像你的代码的结尾一样
<a href='acceptance.php?ref=<?php echo $lin["Cod Reserva"]; ?>'>Accept</a>
调用该脚本并将该值作为 $_GET['ref'] 传递给 table 中的每一行。抱歉,我不知道该字段是否正确,但它必须是预订的唯一 ID。然后,您的 acceptance.php 脚本会从数据库中检索其余信息以获取要使用的电子邮件地址。
或者您可以在每一行绘制一个 html 表单,将引用粘贴到隐藏变量中,绘制一个按钮,然后调用单独的脚本。
使用单独的脚本而不是相同的脚本发送电子邮件便于稍后为启用 JS 的用户添加 Ajax。
我的目标是能够通过电子邮件接受或拒绝客户的请求。我所拥有的是我网站的后台,似乎每个人都提交了我的预订表格,提交后的客户收到一封电子邮件,说他们的确认正在等待中,此时管理员可以选择接受或拒绝预订,在该操作完成后,客户将收到一封包含回复的电子邮件。
现在,我尝试使用 "accept" 按钮,看看它是否有效。现在,我收到一条错误消息,提示地址无效 $mail->addAddress($_POST['EmailReser']);
//File listreser.php
<body style="background-color:white;">
<?php
$sql="select * from Reservas";
$res=$lig->query($sql);
?>
<div class="container">
<h1 align="center">List Reservations</h1> <br><br>
<table id ="tableUser" class="table table-striped display">
<thead>
<tr>
<th>Code of the reservation</th>
<th>Name </th>
<th>Last Name</th>
<th>Email</th>
<th>Telephone</th>
<th>Date </th>
<th>Time</th>
<th>Number of people</th>
<th>Message </th>
<th>State</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($lin=$res->fetch_array()){ ?>
<tr>
<td><?php echo$lin[Cod_Reserva]; ?></td>
<td><?php echo$lin[NomeReser]; ?></td>
<td><?php echo$lin[ApelidoReser]; ?></td>
<td><?php echo$lin[EmailReser]; ?></td>
<td><?php echo$lin[TelefoneR]; ?></td>
<td><?php echo$lin[DataR]; ?></td>
<td><?php echo$lin[Hora]; ?></td>
<td><?php echo$lin[NumPessoas]; ?></td>
<td><?php echo$lin[MensagemR]; ?></td>
<td><a style="padding-right:12px;" href=index.php?cmd=aceitar&Cod_Reserva=<?php echo $lin["Cod_Reserva"]; ?>><img src='images/check.png' width="20" height = "20" ></a><a href=index.php?cmd=rejeitar&Cod_Reserva=<?php echo $lin["Cod_Reserva"]; ?>><img src='images/close.png' width="15" height = "15" ></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
var_dump($_GET);
exit();
// $Cod_Reserva=$_REQUEST['Cod_Reserva'];
$Cod_Reserva=$_REQUEST['Cod_Reserva'];
//$EmailReser = $_GET['EmailReser'];
// $sql="select * from Reservas ";
$sql="select EmailReser from reservas where cod_reserva = $Cod_Reserva";
$res=$lig->query($sql);
//$lin=$res->fetch_array();
while ($lin=$res->fetch_array()){
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->CharSet = "utf-8";
$mail->Host='smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure='tls';
$mail->Username='email@gmail.com';
$mail->Password='****';
$mail->setFrom('email@gmail.com');
$mail->addAddress($lin['EmailReser']);
$mail->addReplyTo('email@gmail.com');
$mail->isHTML(true);
$mail->Subject='Your request has been confirmed';
$mail->Body = "message";
if(!$mail->send()){
echo "<script>
alert('There's been a mistake');
</script>";
}
else{
echo "<script>
alert('Email was sent with success');
</script>";
}
}
?>
您可以将带有 link 的按钮替换为发送接受电子邮件的单独 PHP 脚本。您需要包含足够的信息以了解您正在接受哪个预订(以及将其发送到哪里),并且您需要添加一些验证以确保只有 suitable 用户才能实际处理接受.
所以就像你的代码的结尾一样
<a href='acceptance.php?ref=<?php echo $lin["Cod Reserva"]; ?>'>Accept</a>
调用该脚本并将该值作为 $_GET['ref'] 传递给 table 中的每一行。抱歉,我不知道该字段是否正确,但它必须是预订的唯一 ID。然后,您的 acceptance.php 脚本会从数据库中检索其余信息以获取要使用的电子邮件地址。
或者您可以在每一行绘制一个 html 表单,将引用粘贴到隐藏变量中,绘制一个按钮,然后调用单独的脚本。
使用单独的脚本而不是相同的脚本发送电子邮件便于稍后为启用 JS 的用户添加 Ajax。