使用wpMandrill安排电子邮件到Wordpress

时间:2016-02-23 15:25:43

标签: wordpress email plugins mandrill schedule

是否可以使用wpMandrill插件安排消息?

我在这个post中看到我们可以使用mandrill_payload过滤器来更改结构中的任何内容(遵循Mandrill的API,/messages/send)。

如何更改send_at参数,以便我可以安排发送电子邮件。

会是这样的:

socket

然后

function customFilterSendAt($send_at)
{
  $send_at = "2016-01-23 14:00:00";
  return $send_at;
}

add_filter('mandrill_payload', 'customFilterSendAt');

1 个答案:

答案 0 :(得分:1)

我发现可以使用wpMandrill安排电子邮件。这link(查看一些评论)帮助了我。

使用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);

调试:

echo '<pre>'.print_r($sendmessage,true).'</pre>';

输出示例:

Array
(
    [0] => Array
        (
            [email] => to_email@example.com
            [status] => scheduled
            [_id] => db835dfe43cd5d67b3743a30e184f84d
            [reject_reason] => 
        )
)

目前,预定的电子邮件只能通过Mandrill的API进行管理,因此您无法在Mandrill的信息中心内找到它们。

列出您可以使用的预定电子邮件:

$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']);

输出示例:

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
        )
)