3

I have an issue with mailables. Here is the part of the code I'm using for sending mail

    try {
        Mail::to('xxx@xxx.com', 'Troubleshooting')->queue(new ErrorReport($data));
    } catch (\Exception $e) {
        $this->getErrors()->add('', $e->getMessage());
        return false;
    }

Mailable:

public function __construct($data)
{
    $this->data = $data;
}

public function build()
{
    return $this
        ->from(env('MAIL_FROM'), env('MAIL_NAME'))
        ->subject($this->data['subject'])
        ->view('emails.error_report', [
            'name'  => $this->data['name'],
            'email' => $this->data['email'],
            'msg'   => $this->data['msg'],
            'user'  => $this->data['user'],
        ]);
}

And finally, the view:

User name: {!! $name !!} <br/>
User email: {!! $email !!} <br/>
Message: {!! nl2br(e($msg)) !!} <br/>

User: <br/>
<pre>
{!! $user !!}
</pre><br/>

Session data: <br/>
<pre>
{!! var_dump(Session::all()) !!}
</pre><br/>

So the code doesn't error out, it returns me the message that everything went well but I never get the mail on my mail?

I also tried replacing queue() with send(). It doesn't do anything also, and it gives no error.

EDIT

If I set mail driver to 'log', mail gets in the Laravel log, but if it is on 'sendmnail' nothing happens.

This is left default:

'sendmail' => '/usr/sbin/sendmail -bs',
Norgul
  • 4,613
  • 13
  • 61
  • 144
  • You are queue-ing the mail, do you actually run/work this queue? – milo526 Jan 13 '18 at 09:06
  • Queuing was never done actually. But it worked before without queue setup. I tried running `artiusan queue:work` but that changed nothing – Norgul Jan 13 '18 at 09:07
  • It might have nothing to do with your code at all. Are you running a private server? Or do you have an official mailserver / smtp setup? If not, then most official mail servers out there will automaticly block your email due to the [SBL](https://www.spamhaus.org/sbl/) – icecub Jan 13 '18 at 09:11
  • It is setup in vagrant box. I didn't set up any mail credentials in `.env` but I don't see why it was working before – Norgul Jan 13 '18 at 09:18
  • It would be better to use a mail server or smtp server. It might be than sendmail mails are not passed outside of the virtual machines because of whatever (antivirus from you machine? ports ?). It might be that you could configure laravel to use PHP functions to send emails... Try some other solutions than the current one. – Cedric Jan 13 '18 at 13:47

0 Answers0