I'm trying to get the emails column from MySQL database table and then sending emails to them. Below is my PHP code:
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());
}
What is the correct way to select a column field from MySQL table and send emails to the recipients associated with that column?
Try something like this: