Most people probably do not use Mailgun here but I do. Thus I struggled getting emails hooked up correctly for a few days. With a bunch of trial and error I DO have emails sending with variables like user names in the body of the email.
With that I realized I needed to figure out how to verify users. So here's what I've landed on because the available snippets are specifically for Sengrid.
This flow works for my signup function:
Generate verification token - Use the Generate Random Number function to create a verification code or token (before you create the user)
Store token - Save this token in your user table with an expiration timestamp
Build verification link - Construct your verification URL like:
https://yourapp.com/verify?token=YOUR_TOKEN&email=USER_EMAIL
Send via Mailgun - Include this link in your Mailgun email template using the variables you've already set up such as 'verification_token'
Handle verification - When users click the link, parse the token from the URL using the url_parse filter and verify it against your stored token
In this case you need a /verify page that calls to your endpoint to check the token.