8 months ago

Programatically check if Mailgun mail was sent correctly with PHP SDK

Posted 8 months ago by Gabotronix

Hi everybody, I 'm tinkering with Mailgun's PHP SDK in my laravel app, the emails are sent correctly after checking Mailgun's dashboard but I'm wondering if there's a way to get a confirmation programatically, currently I'm getting back an empty variable from my sendMail trait:

namespace App\Traits;

trait SendMail

    public function sendMail($view, $mailData, $subject, $to)
        $html = view($view, compact('mailData'))->render();

        $result = app(Mailgun::class)->messages()->send(config('mail.mailgun.domain'), [
            'from' => config('').' <'.config('mail.from.address').'>',
            'to' => $to,
            'subject' => $subject,
            'html' => $html,
        return $result;


Here, result returns an empty array, always... how can I know if mail was sent with my code without checking Mailgun's dashboard or my mail inbox. Thanks in advance.

Please sign in or create an account to participate in this conversation.