hey finn i had similar issues. seems like u re using a trait that doesnt exist. check your Mailgun library import and ensure you instantiate the correct class name- Mailgun\Mailgun, not MailService\MailProvider. hope it helps!
Having worked with CodeIgniter and various email libraries, I can offer some insights on your issue. It appears the problem isn’t with Mailgun itself but with integrating it into CodeIgniter by trying to use traits, which CodeIgniter does not actually support. Instead of using a trait, you should load the Mailgun client within your controller and call its methods directly. Make sure that you have installed Mailgun properly via Composer and that you are including the autoloader. For example, your sendEmail method could look like this:
public function sendEmail()
{
$mg = Mailgun::create('your-api-key');
$result = $mg->messages()->send('your-domain.com', [
'from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Test Email',
'text' => 'This is a test!'
]);
if ($result) {
echo 'Email sent successfully';
} else {
echo 'Failed to send email';
}
}
This approach should resolve the error you’re encountering.
I’ve encountered this issue before. The problem lies in how you’re attempting to use the Mailgun library. CodeIgniter doesn’t natively support traits, which is what the error message is hinting at. Instead, you should instantiate the Mailgun client directly in your controller method. Try modifying your code like this:
public function sendMessage()
{
$mg = Mailgun::create('your-api-key');
$domain = 'your-domain.com';
try {
$mg->messages()->send($domain, [
'from' => 'Sender <[email protected]>',
'to' => 'Recipient <[email protected]>',
'subject' => 'Test Email',
'text' => 'This is a test email sent via Mailgun!'
]);
echo 'Email sent successfully';
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
Make sure you’ve properly installed the Mailgun SDK via Composer and included the autoloader in your CodeIgniter application. This approach should resolve your issue.