2015-10-12 35 views
1

我不断收到InvalidArgumentException: Invalid resource type: boolean,这些邮件是通过邮戳发送的。有些正在工作,有些则不是。在工作的电子邮件和发生错误的电子邮件中,我看不到任何不同之处。他们使用相同的参数运行相同的代码。Postmark/Guzzle InvalidArgumentException:资源类型无效:布尔值

这里是我传递什么到邮戳:

$client = new PostmarkClient($config->postmark->token); 
$sendResult = $client->sendEmail(
    $config->postmark->sender, 
    $recipient, 
    $subject, 
    $html_body, 
    $text_body, 
    null, true, null, null, null, null, $attachments 
); 

这里的调用堆栈:

vendor/guzzlehttp/streams/src/Stream.php in factory at line 85 
throw new \InvalidArgumentException('Invalid resource type: ' . $type); 

vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php in applyOptions at line 345 
$request->setBody(Stream::factory(json_encode($value))); 

vendor/guzzlehttp/guzzle/src/Message/MessageFactory.php in createRequest at line 98 
$this->applyOptions($request, $options); 

vendor/guzzlehttp/guzzle/src/Client.php in createRequest at line 120 
return $this->messageFactory->createRequest($method, $url, $options); 

vendor/wildbit/postmark-php/src/Postmark/PostmarkClientBase.php in processRestRequest at line 101 
$request = $client->createRequest($method, $url, $options); 

vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php in sendEmail at line 61 
return new DynamicResponseModel($this->processRestRequest('POST', '/email', $body)); 

library/send_mail.php in send_mail at line 86 

我GOOGLE了一会儿,没有发现任何东西,以使这个意义上说。

我在这里看了: https://laracasts.com/discuss/channels/general-discussion/mandrill-trouble-invalid-resource-type-boolean 这里: https://laracasts.com/forum/?p=2325-problems-using-mandrill/0但是这两个都是具有Laravel +山魈的问题,但我使用的邮戳和无框架。然而,我们确实有Guzzle的共同点。这两个帖子都表示他们通过更新或重新安装Guzzle来处理它。

我似乎正在运行Guzzle的“工作”版本。 GitHub Issue #628 for Guzzle似乎正好是我所看到的,但这个问题说,它固定在4.0.2,我在狂饮5.3:

从我composer.lock在服务器上:

{ 
    "name": "guzzlehttp/guzzle", 
    "version": "5.3.0" 
}, 
... 
{ 
    "name": "guzzlehttp/streams", 
    "version": "3.0.0" 
}, 
... 
{ 
    "name": "wildbit/postmark-php", 
    "version": "dev-master", 
    "source": { 
     "type": "git", 
     "url": "https://github.com/wildbit/postmark-php", 
     "reference": "2eabc627c3f2a693b986e51d2f892cc2e2d065b3" 
    }, 
    "require": { 
    "guzzlehttp/guzzle": "~5.1", 
    "php": ">=5.4.0" 
    }, 
} 

有什么想法?

回答

1

当你的错误不是立即显而易见的时候,那么调用stak通常会揭示出错的原因。这也不例外,我应该早点注意到它。

调用堆栈中的倒数第二项是变坏的地方。

$request->setBody(Stream::factory(json_encode($value))); 

这里,json_encode($value)返回一个布尔值。使用json_last_error()我能够确定问题出在混合字符编码(JSON_ERROR_UTF8)。

在用户输入的某处,用户提供的数据是UTF-8和ISO-8895-1的混合。由于这是不一致的,一些电子邮件将工作得很好,而其他电子邮件则失败。

我最终强迫我的$html_body$text_body是UTF-8,并开始工作。

相关问题