【问题标题】:Laravel and Mailgun: Incoming Email SubjectLaravel 和 Mailgun:传入的电子邮件主题
【发布时间】:2016-12-07 13:45:33
【问题描述】:

我目前正在使用 Mailgun 在我的应用程序中检查收到的电子邮件。到目前为止,我可以获得电子邮件的收件人、发件人和正文;但不是主题。

$recipient = $request->input('recipient'); <-- Working
$sender = $request->input('sender'); <-- Working
$body = $request->input('body-html'); <-- Working
$subject = $request->input('subject'); <-- Not Working

我可以在邮件标题中看到主题:

$headers = $request->input('message-headers');

返回以下内容:

[["Received", "by luna.mailgun.net with SMTP mgrt 8734663311733; Fri, 03 May 2013 18:26:27 +0000"], ["Content-Type", ["multipart/alternative", {"boundary": "eb663d73ae0a4d6c9153cc0aec8b7520"}]], ["Mime-Version", "1.0"], ["Subject", "Test deliver webhook"], ["From", "Bob <bob@thewardensaga.com>"], ["To", "Alice <alice@example.com>"], ["Message-Id", "<20130503182626.18666.16540@thewardensaga.com>"], ["X-Mailgun-Variables", "{\"my_var_1\": \"Mailgun Variable #1\", \"my-var-2\": \"awesome\"}"], ["Date", "Fri, 03 May 2013 18:26:27 +0000"], ["Sender", "bob@thewardensaga.com"]]

这看起来是一个数组,但通过 is_array 运行它,返回 false。

我尝试过的代码:

foreach($headers as $header) {
    if($header[0] == 'Subject') {
        $subject = $header[1];
    }
}
return $subject;

返回:ErrorException 为 foreach() 提供的参数无效

【问题讨论】:

  • 也许 message-headers 是一个 json 字符串。在 foreach 中使用之前,请尝试在其上使用 json_decode

标签: php laravel email mailgun subject


【解决方案1】:
$subject = null;
foreach ($data as $header) {
    if ($header[0] == 'Subject') {
        $subject = $header[1];
        break;
    }
}

【讨论】:

    猜你喜欢
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 2016-11-22
    • 2019-07-18
    • 2017-10-12
    • 2021-01-01
    • 2018-06-17
    相关资源
    最近更新 更多