Reputation: 255
I'm currently using Mailgun to check received emails in my application. So far I can get the recipient, the sender, and the body of the email; but not the subject.
$recipient = $request->input('recipient'); <-- Working
$sender = $request->input('sender'); <-- Working
$body = $request->input('body-html'); <-- Working
$subject = $request->input('subject'); <-- Not Working
I can see the subject in the message header:
$headers = $request->input('message-headers');
Which returns the following:
[["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 <[email protected]>"], ["To", "Alice <[email protected]>"], ["Message-Id", "<[email protected]>"], ["X-Mailgun-Variables", "{\"my_var_1\": \"Mailgun Variable #1\", \"my-var-2\": \"awesome\"}"], ["Date", "Fri, 03 May 2013 18:26:27 +0000"], ["Sender", "[email protected]"]]
This looks to be an array but running it through is_array, returns false.
Code that I have tried:
foreach($headers as $header) {
if($header[0] == 'Subject') {
$subject = $header[1];
}
}
return $subject;
RETURNS: ErrorException Invalid argument supplied for foreach()
Upvotes: 2
Views: 392
Reputation: 2881
$subject = null;
foreach ($data as $header) {
if ($header[0] == 'Subject') {
$subject = $header[1];
break;
}
}
Upvotes: 0