gpt4 book ai didi

PHP MYSQL 添加多个电子邮件地址到 AddAddress while 循环

转载 作者:行者123 更新时间:2023-11-29 23:47:02 25 4
gpt4 key购买 nike

有人请给我指出正确的方向吗?我在这里看过很多关于这个主题的帖子,我似乎找到了许多不同的拼图,但没有一个能够组合在一起。我想在广告插入数据库后向用户发送电子邮件。我没有收到任何错误,但也没有收到电子邮件。如果我在 AddAddress 行中硬编码和电子邮件地址,我会收到电子邮件,但数组没有组合在一起。如有任何帮助,我们将不胜感激。

public function create($category_id, $title, $description, $city, $price)
{
// clean the input to prevent for example javascript within the notes.
$category_id = \strip_tags($category_id);
$title = \strip_tags($title);
$description = \strip_tags($description);
$city = \strip_tags($city);
$price = \strip_tags($price);


$sql = "INSERT INTO ads (category_id, user_id, title, description, city, price) VALUES (:category_id, :user_id, :title, :description, :city, :price)";
$query = $this->db->prepare($sql);
$query->execute(array(':category_id' => $category_id, ':user_id' => $_SESSION['user_id'], ':title' => $title, ':description' => $description, ':city' => $city, ':price' => $price));

$count = $query->rowCount();
if ($count == 1) {
$user_email = '';
$sql = "SELECT user_email FROM users";
$query = $this->db->prepare($sql);
$query->execute(array(':user_email' => $user_email));
return $query->fetchAll();

while ($row = mysql_fetch_array($query)){
$to = $row['user_email'];

// create PHPMailer object here. This is easily possible as we auto-load the according class(es) via composer
$mail = new PHPMailer;

// please look into the config/config.php for much more info on how to use this!
if (EMAIL_USE_SMTP) {
// Set mailer to use SMTP
$mail->IsSMTP();
//useful for debugging, shows full SMTP errors, config this in config/config.php
$mail->SMTPDebug = PHPMAILER_DEBUG_MODE;
// Enable SMTP authentication
$mail->SMTPAuth = EMAIL_SMTP_AUTH;
// Enable encryption, usually SSL/TLS
if (defined('EMAIL_SMTP_ENCRYPTION')) {
$mail->SMTPSecure = EMAIL_SMTP_ENCRYPTION;
}
// Specify host server
$mail->Host = EMAIL_SMTP_HOST;
$mail->Username = EMAIL_SMTP_USERNAME;
$mail->Password = EMAIL_SMTP_PASSWORD;
$mail->Port = EMAIL_SMTP_PORT;
} else {
$mail->IsMail();
}

// build the email
$mail->From = EMAIL_AD_NOTIFICATION_FROM_EMAIL;
$mail->FromName = EMAIL_AD_NOTIFICATION_FROM_NAME;
$mail->AddAddress($to);
$mail->Subject = EMAIL_AD_NOTIFICATION_SUBJECT;
$mail->Body = EMAIL_AD_NOTIFICATION_CONTENT;

// send the mail
if($mail->Send()) {
$_SESSION["feedback_positive"][] = FEEDBACK_PASSWORD_RESET_MAIL_SENDING_SUCCESSFUL;
return true;
} else {
$_SESSION["feedback_negative"][] = FEEDBACK_PASSWORD_RESET_MAIL_SENDING_ERROR . $mail->ErrorInfo;
return false;
}
}

} else {
$_SESSION["feedback_negative"][] = FEEDBACK_NOTE_CREATION_FAILED;
}
// default return
return false;

}

最佳答案

  $sql = "SELECT user_email FROM users";
$query = $this->db->prepare($sql);
$query->execute(array(':user_email' => $user_email));
return $query->fetchAll();

这有点错误,我认为你想要更多的东西......

$sql = $this->db->prepare("SELECT user_email FROM users WHERE user_email=?");
$sql->execute(array($user_email));


while($row = $sql->fetch(PDO::FETCH_ASSOC)) {

关于PHP MYSQL 添加多个电子邮件地址到 AddAddress while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25857584/

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