我有一個存儲在一個數組中的電子郵件列表,我想遍歷該列表併發送一封電子郵件給每一個Mailgun。如何在PHP for循環中使用Mailgun?
這裏是我的腳本
$mgClient = new Mailgun('snipsnip');
$domain = "sandboxe08d52a4dcd247d7a31e3eb6e672ab03.mailgun.org";
$count = count($emails);
for($i = 0; $i < $count; $i++){
$to = $emails[$i];
$mgClient->sendMessage($domain, array(
'from' => 'Markus from StackOverflow <[email protected]>',
'to' => $to,
'subject' => 'Open This Email',
'text' => 'msg'
));
}
這是錯誤我得到
Fatal error: Uncaught exception 'Mailgun\Connection\Exceptions\MissingRequiredParameters' with message 'The parameters passed to the API were invalid. Check your inputs!' in /home/content/63/11130563/html/sites/paidfor/includes/mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:127 Stack trace: #0 /home/content/63/11130563/html/sites/paidfor/includes/mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(90): Mailgun\Connection\RestClient->responseHandler(Object(Guzzle\Http\Message\Response)) #1 /home/content/63/11130563/html/sites/paidfor/includes/mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(80): Mailgun\Connection\RestClient->post('sandboxe08d52a4...', Array, Array) #2 /home/content/63/11130563/html/sites/paidfor/includes/mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(36): Mailgun\Mailgun->post('sandboxe08d52a4...', Array, Array) #3 /home/content/63/11130563/html/sites/paidfor/bag/success/index.php(21): Mailgun\Mailgun->sendMessage('sandboxe08d52a4...', A in /home/content/63/11130563/html/sites/paidfor/includes/mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php on line 127
這對於Mailgun循環正確的道路?有小費嗎?數組$電子郵件
內容
Array
(
[0] => [email protected]
[1] => [email protected]
)
更新:我注意到,因爲是我的mailgun帳戶的腳本不與非Gmail的域
放置在這張貼片段的開始部分,您可以請發佈'print_r($ emails)' –
@JeffPuckettII的輸出我將它添加到我的帖子底部 –
只是爲了澄清,您是說這個腳本確實爲gmail域名工作? –