Yeah, that trailing comma’s your problem, but honestly? I got tired of fighting PHP syntax quirks like this and found a better way.
Skip wrestling with Mailgun’s PHP SDK. Just automate the whole email workflow instead - no more debugging syntax errors.
I moved away from direct API calls because maintaining all that PHP code sucks. Now I trigger a workflow with my data and it handles the Mailgun stuff automatically.
You can still send your HTML content and recipient info through a simple HTTP request, but the messy array formatting and API calls happen behind the scenes.
Bonus: adding retry logic, logging, or switching providers later doesn’t mean touching your main code.
Latenode works great for this - connects straight to Mailgun and handles the API mess: https://latenode.com
check the line with ), ); - that’s your problem. you’ve got a comma hanging there after the array closes but before the function ends. php doesn’t like extra commas in function calls.
hey, i think u got an extra comma after the closing parenthesis in your sendMessage function. just remove that comma before the ); and it should work fine!
Yes, the issue arises from the trailing comma after the last array element in your sendMessage call. In PHP, trailing commas are not permitted in function parameters, so you should change the closing part from ), ); to ));. I’ve experienced similar errors while working with Mailgun; it’s a common mistake with nested arrays. The PHP parser misinterprets the extra comma, anticipating another parameter, leading to the syntax error when it encounters the closing parenthesis.
That trailing comma is your problem. I hit this exact same issue when I started using the Mailgun SDK about a year ago. The ), ); at the end of your sendMessage call is invalid - PHP expects either another parameter or the closing parenthesis, not a comma AND closing parenthesis. Just change it to )); and you’re good to go. These syntax errors are so frustrating because they’re hard to spot when everything else looks right. Mailgun’s docs show trailing commas in arrays but not function calls, which trips people up.