Is that possible to schedule a message using wpMandrill plugin?
I saw in this post that we can use mandrill_payload filter to change anything in the structure (following Mandrill's API , /messages/send).
How can I change the send_at parameter so that I can schedule e-mails to be sent.
Would it be something like this:
function customFilterSendAt($send_at)
{
$send_at = "2016-01-23 14:00:00";
return $send_at;
}
add_filter('mandrill_payload', 'customFilterSendAt');
Then
wp_mail($email_adress, $subj, $body );
?
I found that it is possible to schedule emails using wpMandrill. This link (check aaroneight comments) helped me.
To schedule your email using wpMandrill:
$message = array(
'subject' => $subj,
'from_name' => 'From Name',
'from_email' => 'from_email@example.com',
'to' => 'to_email@example.com',
'html' => $body,
'async' => false,
'ip_pool' => null,
'send_at' => '2016-02-24 19:45:00'
);
$sendmessage = wpMandrill::sendEmail($message);
Debugging:
echo '<pre>'.print_r($sendmessage,true).'</pre>';
Output example:
Array
(
[0] => Array
(
[email] => to_email@example.com
[status] => scheduled
[_id] => db835dfe43cd5d67b3743a30e184f84d
[reject_reason] =>
)
)
At this time, scheduled emails may only be managed via Mandrill's API, so you won't find them within Mandrill's Dashboard.
to list your scheduled emails you can use:
$url = 'https://mandrillapp.com/api/1.0/messages/list-scheduled.json';
$key = 'Your API key';
//$to = ''; // optional
$args = array(
'body' => array(
'key' => $key
)
);
$results = wp_remote_post( $url, $args );
$results = json_decode($results['body']);
Output example:
Array
(
[0] => stdClass Object
(
[_id] => 1d0xe54f3b759a1153b7a53g3321f4b6
[created_at] => 2016-02-24 19:30:13
[send_at] => 2016-02-24 19:42:00
[from_email] => from_email@example.com
[to] => to_email@example.com
[subject] => Email Subject
)
[1] => stdClass Object
(
[_id] => 1272e526f6924ba096d23146e2dxad4c
[created_at] => 2016-02-24 19:31:12
[send_at] => 2016-02-24 19:45:00
[from_email] => from_email@example.com
[to] => to_email@example.com
[subject] => Email Subject
)
)