0

此问题与此Check email template after meta tag replacement and before sent in Mandrill 有关

我想知道是否有一种方法可以将 Mandrill 配置为仅在替换电子邮件模板中的所有合并标签时才发送电子邮件。这可能吗?

4

1 回答 1

0

AFAIK 无法使用 Mandrill 进行配置。

但是,您可以(也许应该)使用 API 执行此操作 - 利用该render方法预呈现外发电子邮件,然后查找任何未替换的字段。

function has_merge_tags($string)
{
    return ( strpos("|*", $string) === false AND strpos("*|", $string) === false);
}

function send_email($template_code, $merge_fields)
{
    $mandrill = new Mandrill(APIKEY);

    // pre-render the template with the merged fields
    $result = $mandrill->templates->render($name, array(), $merge_fields);

    if (has_merge_tags($result['html']))
    {
        // throw exception, log it, whatever
    }

    really_send_email($result['html']);   
}

https://mandrillapp.com/api/docs/templates.php.html#method=render

于 2014-08-20T18:15:49.293 回答