Forums

Problem using wp_schedule_single_event inside a class (2 posts)

  1. Jeff
    Member
    Posted 3 years ago #

    I've been making a modification to Subscribe2 plugin so that batches of emails can be sent out with a delay between them (because my hosting only allow 300 emails to be sent per hour).

    The bare bones of my modification are as follows:

    <?php
    
    class s2class {
    
    	function send_emails($email = array()) {
    	$recipient = $email[0];
    	$subject = $email[1];
    	$mailtext = $email[2];
    	$headers = $email[3];
    	$status = @wp_mail($recipient, $subject, $mailtext, $headers);
    	return $status;
    	}	
    
    	function mail() {
    	$delays = 3600;
    	$email = array ($recipient, $subject, $mailtext, $headers);
    	$status = $this->send_emails($email);
    	wp_schedule_single_event(time()+$delays, 'send_batch_emails', $email);
    	}
    
    	function subscribe2() {
    	add_action('send_batch_emails', array(&$this, 'send_emails'), 10, 1); 
    
    	} 
    
    }
    ?>

    I can send out the emails without a delay using
    $status = $this->send_emails($email);
    and
    wp_schedule_single_event(time()+$delays, 'send_batch_emails', $email);
    puts all the correct data into the Cron queue but doesn't send the $email array to the send_emails() function.

    I'm not at all familiar with using classes and suspect that using wp_schedule_single_event inside a class is causing the problem passing the data with add_action.

    I've searched high and low on Google and haven't found anything that seems to correspond with this problem.

  2. mattyrob
    Member
    Posted 3 years ago #

    upekshapriya,

    Your mail() function seems to be trying to send the emails by calling send_mails before scheduling a future event. You may need to consider storing the data in a table prior to sending as there are long delays.

    The better way is to approach your host provider and ask them to install a server side email choking application rather than relying on PHP / / WordPress.

Topic Closed

This topic has been closed to new replies.

About this Topic