2016-03-03 34 views

回答

1

我想出瞭解決方案,其實很簡單。

隨着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

0

要知道電子郵件的狀態,您可以使用Mailgun webhooks。從Mailgun管理區域,您可以指定Mailgun在處理完電子郵件後發送的webhook網址。

確保您的應用程序中存在任何用作webhook的url,並且在您使用的任何控制器中都有一個路由和方法。一旦您的應用程序收到發佈的數據,您可以解析發送的數據並確定電子郵件的狀態。然後,您可以更新數據庫或您需要執行的任何操作。

要確定哪些電子郵件您需要在電子郵件中添加一些自定義標題,以便稍後可以識別它。

看到這個答案如何做到這一點的詳細信息:Using Laravel's Mailgun driver, how do you (gracefully) send custom data and tags with your email?

URL必須是活的,它的工作,因此,如果您是在本地與laravell測試宅基地可以在ngrok看看網絡掛接,它允許您將本地環境傳輸到可用於測試目的的url。

+0

感謝您的回答,但幸運的是,這並不是那麼困難。 Webhooks對於其他更高級的事情來說非常棒,但對於從Mailgun獲得成功的迴應並非必要。請參考我發佈的答案。 – zeckdude

+0

200響應是否表明Mailgun已經成功接收到您的請求,然後Mailgun繼續處理電子郵件,給每封郵件發送,失敗,退回等狀態。我不能100%確定它使用你的方法是成功的。也許你可以嘗試給它發送一個不存在的電子郵件地址,如果它給出了一個200響應檢查mailgun日誌,這將顯示發送失敗。 –

相關問題