Getting parameter validation error when sending emails through Mailgun API

I’m trying to send an email using the Mailgun PHP library but I keep getting a fatal error about invalid parameters. The error message says something about sandbox domains being for testing only and needing to add authorized recipients.

Here’s my code:

$mailer->dispatchMessage(MY_DOMAIN, [
    'from' => '[email protected]',
    'to' => MY_EMAIL_LIST,
    'subject' => $emailSubject,
    'html' => $content + '<br><br><a href="%unsubscribe_url%">Click to unsubscribe</a>'
]);

The error I’m getting mentions MissingRequiredParameters exception and talks about sandbox subdomains. I’m not sure what I’m doing wrong here. Has anyone encountered this issue before? What am I missing in my configuration?

you’re in sandbox mode, which limits who can receive emails. check your mailgun dashboard and whitelist the recipients. also, that + should be a . for concatenation in php - that’s likely causing your parameter error.

I encountered a similar issue when I started using Mailgun. It appears you are trying to send emails from a sandbox domain, which can only send to authorized recipients. You need to add the recipient emails under ‘Authorized Recipients’ in the Mailgun dashboard. Additionally, in your PHP code, be careful with string concatenation; PHP requires the use of . (period) instead of +. The MissingRequiredParameters error could be related to your domain constant not being configured correctly or an issue with your API key.

The issue you’re facing is likely due to using a sandbox domain for sending emails, which only allows communication with verified recipients listed in your Mailgun dashboard. To resolve this, either upgrade your account to use a custom domain or ensure that all recipient emails are added to your authorized recipients list. Additionally, it looks like there’s a syntax mistake in your PHP code; PHP uses the dot operator (.) for string concatenation, not the plus sign (+). This could also be contributing to the parameter validation error.