I am trying to pull together all my users to send an email out to them from a contact form. I am using WordPress to house all my users.

I have a script which loops through all my users but need to be able it to send them all at once:

<?php
$wp_user_search = $wpdb->get_results("SELECT ID, user_email FROM $wpdb->users ORDER BY ID");
foreach ( $wp_user_search as $userid ) {
    $user_id       = (int) $userid->ID;
    $user_login    = stripslashes($userid->user_login);
    $email  = stripslashes($userid->user_email);
    $return  = '';
    $return .= "t" . '<p>'. $email .'</p>' . "n";
    print($return);
}
?>
        <form action="../mailadmin.php" method="post">
            <input type="hidden" name="email" value="<?php echo $email; ?>">
            <input type="text" name="subject" value="" placeholder="Subject..." style="padding: 10px; border: 1px solid #EEEEEE; width:100%;"> 
            <br><br>
            <textarea onkeyup="textAreaAdjust(this)" name="contentfield" style="max-width: 100%; min-width: 100%; min-height: 200px; padding: 10px; border: 1px solid #EEEEEE;  height:auto; overflow:visible;" placeholder="Please begin typing your message..."></textarea>
            <br><br>
            <button class="amendbutton" type="submit" style="padding: 10px;">Send Message</button>
        </form>
    </div>    
</div>

My second file which handles the mail function is causing me some difficulty as it does not appear to be recognising my named fields so I am wanting to send it to all users, send through a subject and message but I keep getting errors stating undefined variables?

This is the part of the script that is causing me bother too:

$mail->addAddress(stripslashes($_POST["email"]));
$mail->Subject = 'Subject header';
$mail->Body    = 'Subject: ' . $_POST["subject"] . 'Message: ' . $_POST["contentfield"];

Read more here: Sending an email to all users via contact form


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: