I think you need to install the Mailgun library in you project via composer as in the instructions here.
most importantly this bit above the example code in the kirby docs:
require 'vendor/autoload.php';
use Mailgun\Mailgun;
I think its saying class not found because the example in the kirby documentation has lines like
$mg = Mailgun\Mailgun::create('key-example');
which means its trying to use the class in the mailgun library from mailgun but your code currently doesnt have that library loaded into it (this is what the use statement does).
It will be a smiliar story for Sendgrid.
The kirby docs could probably be made a bit clearer as i think they assume you already have the respective libraries installed.
yes you need composer installed and use the the official pluginkit from my previous post as a basis of the plugin. you need install the mailgun library in your plugin folder, not the main Kirby folder. this will put the mailgun library in a Vendor folder INSIDE your plugin.
From there you can load the mailgun library into the file with the class in it, and go from there.
To be honest i have never put the class in the pluigns main index.php, i use a serperate file for that but i guess it should work. its just tidier to put the class in a seperate file.
Wait a minute, what do you want to do? If you want to use Mailgun as your SMTP email provider, you don’t need the SDK. But include your credentials in the /site/config/config.php as described in the docs you linked above.
OK but lets step back a second. What are you using mailgun / sendgrid for? These are designed for high volume email sending, beyond what most web hosting companies will allow from a standard SMTP mail account on your hosting.
If this is low traffic site and your just using this for like a contact form or something you can probably do away with mailgun / sendgrid. Check the terms of your hosting account. Most will say something like “up to 500 emails a day per email account” in the small print.
More than that, regularly, will likely get you flagged as a spammer. If your volumes are higher than that then yes, you do need service like mailgun/sendgrid, but other other wise you can just use a normal SMTP account on your webhosting to send mail from kirby.
I only use it for transactional email (I don’t exceed 50 emails / month I think).
The problem is that the sites are on shared hosting with thousands of customers.
Theoretically these companies have reliable ip addresses which limit the arrival in spam because their ip are known to mail servers (gmail, yahoo, hotmail …)?
It is for this use. But maybe you are right. Any good advice is worth taking.
I tested again with the documentation and it seems to work again (I see the mailgun signature and the encryption again) Emails | Kirby CMS
But the shared hosting and thousands of customers doesnt matter. What does matter is what they have contractually aggreed to provide you with. From experience, ~50 emails a month is million miles from any limit ive seen imposed but a hosting company, shared or not.