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:

$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";
        <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%;"> 
            <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>
            <button class="amendbutton" type="submit" style="padding: 10px;">Send Message</button>

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->Subject = 'Subject header';
$mail->Body    = 'Subject: ' . $_POST["subject"] . 'Message: ' . $_POST["contentfield"];

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


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: