Mail() not working despite "PHP mail" as selected "Mail method" (ocms 2)

I have set up MailHog (with docker) and cannot get mails to send using mail(), please see comments below in code for it to make more sense…

Extra info: in my docker container, this is needed to make mail() point to mhsendmail (mailhog’s
sendmail):

sendmail_path = "/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025"

I have tried using the above option under “Sendmail” mail method (in backend) but it doesn’t work (some options errors returned when trying to send mail …)

So if I can somehow just get a mail sending option to use “mail()” then it should work …

Any help much appreciated!

class MailTest extends Command
{
    /**
     * @var string The console command name
     */
    protected $name = 'trader47:mailtest';

    /**
     * @var string The console command description.
     */
    protected $description = 'Send a test mail.';

    /**
     * Execute the console command.
     * @return void
     */
    public function handle()
    {
        $this->info(__METHOD__);

        // This does not work, even with "PHP mail" selected as "Mail method" in backend Mail Config
//        Mail::send('trader47.user::mail.test', ['name' => 'JohnSnow'], function (Message $message) {
//            $message->to('myemail@gmail.com');
//            $message->subject('TEST');
//        });

        // This works, mail is being sent to mailhog
        $to = "support@t47.test";
        $subject = "TESTING LOCAL SEND!";
        $body = "Hello, world!";
        $headers = "From: jon@snow.com" . "\r\n";
        mail($to,$subject,$body,$headers);
    }
}

Possibly related: Default mail driver called `mail` no longer works · Issue #3256 · octobercms/october · GitHub

Hey @gvanto

Laravel removed the mail type since it is the same as sendmail so it is best to focus on configuration with this driver type.

When using the following config:
(under admin/system/settings/update/october/system/mail_settings > “Sendmail path”):
/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025

And I run the mail test command (using Mail::send(…) method), I get:

mhsendmail is required for this to work, I’ve tried getting just “sendmail” to work using docker but it simply does not…

It looks like you’re using smtp, shouldn’t it be set to use the smtp driver?

Has anyone got this working by any chance? Mailhog with october?

Mailhog supports SMTP, so select this as the driver.