从我的数据库中选择并发送邮件 [英] Select and send mail from my database

查看:205
本文介绍了从我的数据库中选择并发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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());
}

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

What is the correct way to select a column field from MySQL table and send emails to the recipients associated with that column?

推荐答案

尝试这样的一个例子:

<?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();
?>

这篇关于从我的数据库中选择并发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆