php - Add new suscriber with Mailster but no is added into data base - Stack Overflow

I've created a custom WordPress theme and I'm working with Mailster plugin.According to the

I've created a custom WordPress theme and I'm working with Mailster plugin. According to the documentation if you want to add a new subscriber then you can add to the Mailter list which you've created by code, code example

    function add_new_susbriber()
{
    $post_id = get_transient('post_id');
    if (!$post_id) {
        return;
    }

    $metadata = get_post_meta($post_id);
    $client_email = $metadata['email'][0] ?? null;
    $client_name = $metadata['name'][0] ?? 'Not provided';
    $client_lastname = $metadata['lastName'][0] ?? 'Not provided';

    if ($client_email) {
        $subscriber_data = [
            'firstname' => $client_name,
            'lastname'  => $client_lastname,
            'email'     => $client_email,
            'status'    => 1,
            'signup'    => time(),
            'confirm'   => time(),
        ];

        $subscriber_id = mailster('subscribers')->add($subscriber_data);

        if (!is_wp_error($subscriber_id)) {
            error_log("Successfully added subscriber to Mailster: $client_email with ID: $subscriber_id.");

            // Assign subscriber to list ID 2
            $list_id = 2;
            $success = mailster('subscribers')->assign_lists($subscriber_id, $list_id);

            if ($success) {
                error_log("Subscriber $subscriber_id successfully added to list ID $list_id.");
            } else {
                error_log("Failed to assign subscriber $subscriber_id to list ID $list_id.");
            }
        } else {
            error_log("Failed to add subscriber to Mailster: " . $subscriber_id->get_error_message());
        }
    } else {
        error_log("Client email not provided for Post ID $post_id.");
    }

    $admin_email = get_option('admin_email');
    $email_subject = "New Form Submission Received";
    $email_message = "Hello,\n\nYou have received a new form submission:\n\n";
    $email_message .= "Name: {$client_name}\nLast Name: {$client_lastname}\nEmail: {$client_email}\n\n";
    $headers = ['Content-Type: text/plain; charset=UTF-8'];

    if ($admin_email) {
        wp_mail($admin_email, $email_subject, $email_message, $headers);
    }

    if ($client_email) {
        $client_subject = "Thank you for your submission!";
        $client_message = "Hello {$client_name},\n\nThank you for reaching out to us. We will contact you shortly.";
        wp_mail($client_email, $client_subject, $client_message, $headers);
    }

    delete_transient('post_id');
}

all is ok but the problem is that even though we have linked the new subscriber to the campaign list the new subscriber doesn't appear ready to send emails using this list,

into the next image you can see the wordpress dashboar where mailster say us there are 2 suscriber but only one is abalibel in the list, please check out the photo

enter image description here

and into the data base i notice the susciber is tied to mailster_lists table but this has a column call added which has a value 0 and it is not until we enable the subscriber manually by dashboar that a number is added to this column enter image description here

in the next photo you can see which is the column I’m referring to, what I can do because so far I can not make when saving the subscriber and add to the list this column is enabled and I find nothing in the documentation of Mailster,

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742339814a4425394.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信