我想出瞭解決方案,其實很簡單。
隨着Laravel(使用Bogardo Mailgun Package):
$to_name = "Jim Bob";
$to_email = "[email protected]";
$subject = "Howdy everyone!";
// Send the email and capture the response from the Mailgun server
$response = Mailgun::send('emails.transactional', array('body' => $body), function($message) use($to_email, $to_name, $subject)
{
$message->to($to_email, $to_name)->subject($subject);
});
// HTTP Response Code 200 means everything worked as expected
if ($response->http_response_code === 200) {
echo "Woohoo! The message sent!";
}
在純醇」 PHP(使用官方Mailgun PHP SDK):
// Config Information
$mailgun = new Mailgun("key-v876876dfsv876csd8768d876cfsd4");
$domain = "mg.mydomain.com";
// Prepare the necessary information to send the email
$send_data = array(
'from' => $from_name . ' <' . $from_email . '>',
'to' => $to_name . ' <' . $to_email . '>',
'subject' => $subject,
'html' => $html
);
// Send the email and capture the response from the Mailgun server
$response = $mailgun->sendMessage($domain, $send_data);
// HTTP Response Code 200 means everything worked as expected
if ($response->http_response_code === 200) {
echo "Woohoo! The message sent!";
}
檢查出所有的列表Mailgun HTTP響應碼:(https://documentation.mailgun.com/api-intro.html?highlight=401#errors)
感謝您的回答,但幸運的是,這並不是那麼困難。 Webhooks對於其他更高級的事情來說非常棒,但對於從Mailgun獲得成功的迴應並非必要。請參考我發佈的答案。 – zeckdude
200響應是否表明Mailgun已經成功接收到您的請求,然後Mailgun繼續處理電子郵件,給每封郵件發送,失敗,退回等狀態。我不能100%確定它使用你的方法是成功的。也許你可以嘗試給它發送一個不存在的電子郵件地址,如果它給出了一個200響應檢查mailgun日誌,這將顯示發送失敗。 –