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