我正在使用来自 https://github.com/SparkPost/php-sparkpost#send-an-email-using-the-transmissions-endpoint的示例
这里有异步承诺: https ://github.com/SparkPost/php-sparkpost#then-asynchronous
一切都使用 Composer 正确安装。如果我使用 $response = $promise->wait(); 电子邮件已发送但未发送 $promise->then(function(){}, function(){})
我正在从命令行运行 php 脚本,异步选项设置为 true
/// this works:
try {
$response = $promise->wait();
echo $response->getStatusCode()."\n";
print_r($response->getBody())."\n";
} catch (\Exception $e) {
echo $e->getCode()."\n";
echo $e->getMessage()."\n";
}
// but this doesn't
$promise->then(
// Success callback
function ($response) {
echo $response->getStatusCode()."\n";
print_r($response->getBody())."\n";
},
// Failure callback
function (Exception $e) {
echo $e->getCode()."\n";
echo $e->getMessage()."\n";
}
);