0

Been trying this for MONTHS. Time to ask for help. I want to take sql table data and turn it into a mailing list for wp_mail using PHP. This code turns up blank, but I can't find anything online aside from that.

$results = $wpdb->get_results("SELECT * FROM $table_name WHERE accepting_emails='Yes'");
        foreach($results as $emaillist) {
            echo $emaillist->email.",";
        }

I have attempt several changes and getting nothing in return. Mostly says parse error. I've tried creating an array with the foreach function but I'm not sure I'm doing it right, I've tried references, and more still not getting the result. Any suggestions?

  • then you have no rows for that croteria, have you run it in phpmyadmin? – nbk Aug 23 '21 at 18:24
  • Yes and the row is established. The connection works fine I've created a separate function to check that and no problems. I'm just not sure why the data being output is not able to be called in the wp_mail function ... it's display as email1@email.com, email2@email.com when I display it via shortcode (there is only 2 test emails currently), but when I test it via the wp_mail itself, it is coming through blank (I have a separate email send to my web admin with the listed emails to see if they are parsing correctly... that is where they are coming back blank). Any thoughts? – Nicholas Gambacini Aug 23 '21 at 22:33
  • Why are you using `SELECT *`, when all you want is the email address? `SELECT *` is an [anti-pattern](https://stackoverflow.com/questions/3639861/why-is-select-considered-harmful). – Tangentially Perpendicular Aug 23 '21 at 23:48
  • I'm using SELECT so it selects all data that pertains to the where statement. Is there a better choice I'm not aware if so! I've tried get->col with even less success – Nicholas Gambacini Aug 24 '21 at 00:29

0 Answers0