如何在 laravel PHP 中为入站邮件枪电子邮件编写 HTTP POST 处理程序?



http://documentation.mailgun.net/quickstart.html 包含 Django 中 http 处理程序的一些示例代码:

# Handler for HTTP POST to http://myhost.com/messages for the route defined above
def on_incoming_message(request):
if request.method == 'POST':
sender    = request.POST.get('sender')
recipient = request.POST.get('recipient')
subject   = request.POST.get('subject', '')
body_plain = request.POST.get('body-plain', '')
body_without_quotes = request.POST.get('stripped-text', '')
# note: other MIME headers are also posted here...
# attachments:
for key in request.FILES:
file = request.FILES[key]
# do something with the file
# Returned text is ignored but HTTP status code matters:
# Mailgun wants to see 2xx, otherwise it will make another attempt in 5 
minutes
return HttpResponse('OK')

PHP 中的等价物是什么?

我发现这个问题给我们留下了以下信息:

对于需要参考的其他任何人,只需调用 $_POST['value'] 和 确保返回 200 OK 标头。

在我的网络中.php我想它应该是这样的邮政路线:

Route::post('/messages', 'MessageController@store');

但是,当使用post时,我收到一个MethodNotAllowedHttpException错误。

我的第一个猜测是VerifyCsrfToken会导致问题的中间件 - 如果您在web组上运行它。将其移动到api组,查看异常是否消失。然后从控制器方法返回状态为 200 的响应:

return new IlluminateHttpResponse;

默认值将返回状态为 200 的空响应。 不要忘记在邮件枪控制面板中更新端点(带有api路由的组的前缀/api/messages(。

相关内容

最新更新