gpt4 book ai didi

php - 从我的数据库中选择并发送邮件

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

我正在尝试从 MySQL 数据库表中获取电子邮件列,然后向他们发送电子邮件。下面是我的 PHP 代码:

private function sendEmailTech() {
$select = $this->pdo->prepare("SELECT email FROM tbl_tech_email");
try {
$select->execute();
$data = $select->fetch();
foreach($data as $datum=>$email){
if ($email == '') {
$rows.=$email.',';
} else {
return false;
}
$rows = str_replace(',--','',$rows);
$to = explode(',', $rows); // to change to array
mail($$rows, "My Info", "Hello, I just sent a mail to You");
}
}
catch (PDOException $e) {
die($e->getMessage());
}

从 MySQL 表中选择列字段并向与该列关联的收件人发送电子邮件的正确方法是什么?

最佳答案

尝试这样的事情:

<?php
function sendEmailTech() {
$select = $this->pdo->query("SELECT email FROM tbl_tech_email");
$select = $select->fetchAll();
if(count($select) > 0) {
foreach($select AS $recipient) {
mail($recipient["email"], "My Info", "Hello, I just sent a mail to You");
}
} else {
echo "No user to send email";
die();
}
}
// sendEmailTech();
?>

关于php - 从我的数据库中选择并发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33671694/

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