我正在尝试为网络表单设置电子邮件通知:
$query = "UPDATE email_tbl SET notified='".mysqli_real_escape_string($conn,$notified)."', reasoning='".mysqli_real_escape_string($conn,$reasoning)."' WHERE id='$id'";
$result=mysqli_query($conn, $query);
$query2 = "SELECT `or_user` FROM `usf_tbl` WHERE `id` = $id";
$result = mysqli_query($conn,$query2);
while ($row= mysqli_fetch_assoc($result))
$to = "example@email.com, $row[or_user]";
$subject = "Email Notification";
$message = "
<html>
<p>Email Notification for $row[or_user]</p>
</html>";
我正在接收所需的电子邮件,但该电子邮件不包含“or_user”。但是,电子邮件会根据需要发送到“or_user”。 为什么不在实际的电子邮件中打印“or_user”? 提前谢谢。
答案 0 :(得分:4)
$query = "UPDATE email_tbl SET notified='".mysqli_real_escape_string($conn,$notified)."', reasoning='".mysqli_real_escape_string($conn,$reasoning)."' WHERE id='$id'";
$result=mysqli_query($conn, $query);
$query2 = "SELECT `or_user` FROM `usf_tbl` WHERE `id` = $id";
$result = mysqli_query($conn,$query2);
while ($row= mysqli_fetch_array($result))
{
$to = "example@email.com, $row['or_user']";
$subject = "Email Notification";
$message = "
<html>
<p>Email Notification for". $row['or_user']."</p>
</html>";
}
答案 1 :(得分:2)
使用mysqli_num_rows
检查天气查询返回结果
$query2 = "SELECT `or_user` FROM `usf_tbl` WHERE `id` = $id";
$result = mysqli_query($conn, $query2);
$email = "";
$row_cnt = mysqli_num_rows($result);
if ($row_cnt > 0) {
$row = mysqli_fetch_assoc($result);
//在不使用while循环的情况下获取数据
$email = $row['or_user'];
$to = "example@email.com, $email";// pass $email here
$subject = "Email Notification";
//使用sprintf
将电子邮件作为
$message = sprintf("<html>
<p>Email Notification for %s</p>
</html>", $email);
}//end if condition here