Php 用Mandrill发送电子邮件模板会给我带来错误

Php 用Mandrill发送电子邮件模板会给我带来错误,php,google-app-engine,mandrill,Php,Google App Engine,Mandrill,我正在尝试将我的站点切换到Mandrill,但是我在使用PHP API时遇到了一些问题 有两个问题: 首先,它会发送两次电子邮件。底部的代码是我所有的代码(除了PHP的开始和结束标记),我不明白为什么每次会发送两次电子邮件 其次,我从cURL得到一个错误,说URL没有设置。电子邮件正在发送,因此显然有一个URL集。错误如下 这是我的密码: require_once './libraries/Mandrill.php'; try { $mandrill = new Mandrill(

我正在尝试将我的站点切换到Mandrill,但是我在使用PHP API时遇到了一些问题

有两个问题:

  • 首先,它会发送两次电子邮件。底部的代码是我所有的代码(除了PHP的开始和结束标记),我不明白为什么每次会发送两次电子邮件
  • 其次,我从cURL得到一个错误,说URL没有设置。电子邮件正在发送,因此显然有一个URL集。错误如下
这是我的密码:

require_once './libraries/Mandrill.php';

try {
    $mandrill = new Mandrill('myapikey');
    $template_name = 'my-template-slug';
    $template_content = '';
    $message = array(
        'to' => array(
            array(
                'email' => 'a_test@emailaddress.com',
                'name' => 'RecipientsName',
                'type' => 'to'
            )
        ),
        'auto_text' => true,
        'merge_vars' => array(
            array(
                'rcpt' => 'a_test@emailaddress.com',
                'vars' => array(
                    array(
                        'name' => 'USERNAME',
                        'content' => 'user1234'
                    ),
                    array(
                        'name' => 'CONFIRM_CODE',
                        'content' => '19874lahg62378hwsi'
                    )
                )
            )
        )
    );
    $result = $mandrill->messages->sendTemplate($template_name, $template_content, $message);
} catch(Mandrill_Error $e) {
    echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
    throw $e;
}
下面是错误:

出现mandrill错误:mandrill\u HttpError-API调用 消息/发送模板失败:未设置URL!致命错误:未捕获 异常“Mandrill_HttpError”,消息为“API调用到” 邮件/发送模板失败:未设置URL!'在里面 /Users/Gavin/Desktop/Web/mandrill-test/libraries/mandrill.php:126 堆栈跟踪:#0 /Users/Gavin/Desktop/Web/mandrill test/libraries/mandrill/Messages.php(160): Mandrill->call('messages/send-t..,数组)#1 /Users/Gavin/Desktop/Web/mandrill test/index.php(70): Mandrill_Messages->sendTemplate('my-template-slug',Array,Array)#2 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/google/appengine/tools/devappserver2/php/setup.php(131): 要求('/Users/Gavin/De..)#3{main}被抛出 /Users/Gavin/Desktop/Web/mandrill test/libraries/mandrill.php在线 126


Mandrill劫持链接并注入自己的URL,以便通过其服务器重新路由链接。这会导致用户在进入正确页面之前在浏览器中看到mandrill URL


在您帐户的页面上有一个用于单击跟踪的选项(应该是一个下拉菜单,靠近顶部,就在跟踪打开的复选框下方)。除非为单击跟踪提供不同的每封邮件设置,否则您选择的内容将是应用于所有邮件的默认选项。使用SMTP,您可以使用自定义SMTP邮件头按邮件设置单击跟踪。有关使用SMTP头自定义此邮件的详细信息,请参见。

是否引发异常并同时发送两次电子邮件?或者是在多次调用之后发生的?我会尝试调试/打印,看看您的方法是否以某种方式被调用了两次。此外,这里:他们建议使用send而不是SendTemplate上面的代码是唯一使用的代码。是的,它抛出了异常并发送了两次电子邮件。我还应该补充一点,因为这个问题正在发生,我转而使用Mandrill的SMTP服务器而不是API(我自己的模板托管在我的web服务器上),它只发送了一次。在这种情况下,这似乎是他们API中的一个错误。我仍然会尝试中的建议,请检查此链接:-尝试新建当前源文件删除新位置。
<?php
require_once 'Mandrill.php';

$mandrill = new Mandrill('MY API KEY IS USUALLY HERE');
$message = array(
    'subject' => 'Test message',
    'from_email' => 'jwjody@yahoo.com',
    'from_name' => 'Sender person',
    'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>',
    'to' => array(array('email' => 'jwjody@yahoo.com', 'name' => 'Recipient 1')),
    'merge_vars' => array(array(
        'rcpt' => 'recipient1@domain.com',
        'vars' =>
        array(
            array(
                'name' => 'FIRSTNAME',
                'content' => 'Recipient 1 first name'),
            array(
                'name' => 'LASTNAME',
                'content' => 'Last name')
    ))));

//print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message));
echo ("hello");

?>
$mandrill->messages->send($message, $async=false, $ip_pool=null, $send_at=null);