gpt4 book ai didi

php - 将电子邮件发送到从数据库中检索到的电子邮件地址由 PHP 中的 session 发起数组到字符串转换?

转载 作者:行者123 更新时间:2023-11-30 22:10:21 25 4
gpt4 key购买 nike

我正在尝试创建一个系统,当您启动 session 时,一封电子邮件将发送到用户创建帐户时使用的电子邮件。我有一个错误,我试图解决,但我无法解决。这是错误:

Notice: Array to string conversion in C:\xampp\htdocs\LoginSystem\index.php on line 37

我一直在使用片段,但显然没有正确应用它们:

<?php
require 'assests/database.php';
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to your web app</title>
<link rel="stylesheet" stype="text/css" href="assests/style.css">
<link href="https://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet">
</head>
</head>
<body>
<div class="header">
<a href="index.php"> Your App Name</a>
</div>
<?php if( isset($_SESSION['user_id']) ): ?>
<?php
$sql = 'select email from noodles_gamification where ID = "'.$_SESSION['user_id'].'"';
$result = $conn->query($sql);
$email = "";
// output data of each row
$row = $result->fetch(PDO::FETCH_ASSOC);
$email = $row["email"];
/*
$recipients = array();
while($row = mysql_fetch_array($stmt)) {
$recipients = $row[0]['email'];
} */
$to = $email;
$subject = "E-mail subject";
$body = "E-mail body";
$headers = "From: noreply@prakashsoft.esy.es" ;
mail($to, $subject, $body, $headers);
?>
<br /> Welcome you are succesfully loggin in!
<a href="assests/logout.php">Logout?</a>
<?php else : ?>
<h1>Please login or register</h1>
<a href="assests/login.php">login</a> or
<a href="assests/register.php">Register</a>
<?php endif; ?>
</body>
</html>

最佳答案

尝试改变

`$row = $result->fetch(PDO::FETCH_ASSOC);` 

`$email = $result->fetchAll(PDO::FETCH_COLUMN);`

你的查询看起来像这样

$sql = 'select email from noodles_gamification where ID = "'.$_SESSION['user_id'].'"';
$result = $conn->query($sql);
$email = "";
// output data of each row
$email = $result->fetchAll(PDO::FETCH_COLUMN);

希望这对您(y)有所帮助。

关于php - 将电子邮件发送到从数据库中检索到的电子邮件地址由 PHP 中的 session 发起数组到字符串转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40275307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com