Mail Laravel 5.4 (Mailables) Does not work and does not give an error

0

Controller:

$sent = Mail::to('[email protected]')->send(new Welcome($name, $email, $phone, $msg));

.env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.dominio.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

Vista:

<h3>Contacto Web</h3>
<br>
<br>
<b>Nombre:</b> {{$name}}
<br>
<b>Email:</b> {{$email}}
<br>
<b>Teléfono:</b> {{$phone}}
<br>
<b>Mensaje:</b> {{$msg}}

Mailable:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue;

class Welcome extends Mailable {

    use Queueable, SerializesModels;

    /**
     * @var
     */
    public $name;
    public $email;
    public $phone;
    public $msg;

    /**
     * Create a new message instance.
     *
     * @param $name
     * @param $email
     * @param $phone
     * @param $msg
     */
    public function __construct($name, $email, $phone, $msg)
    {
        $this->name = $name;
        $this->email = $email;
        $this->phone = $phone;
        $this->msg = $msg;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {

        $address = '[email protected]';
        $dest_name = 'Web';
        $subject = 'Contacto Web';

        return $this->view('emails.welcome')
            ->to($address, $dest_name)
            ->from($this->email, $this->name)
            ->subject($subject);

    } }

In theory this code worked for me until now and suddenly it has stopped sending emails, it does not show any error. I've tried changing the send to queue and it does not change anything. I do not know what else to try, I created a new mailable and the same.

Version: Laravel 5.4

    
asked by RuralGalaxy 06.09.2017 в 10:11
source

2 answers

0

After doing a lot of tests, I came to the conclusion that I only needed one thing to check ... Aver if the IP of the server was blocked by SPAM or something ... and I was effectively blocked and the reason it was by MAIL SPOOFING, therefore the Mailable class would be like this.

Since what I did was take the email they wrote to me in the form and put it in the from as if that account had sent the mail directly.

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue;

class Welcome extends Mailable {

    use Queueable, SerializesModels;

    /**
     * @var
     */
    public $name;
    public $email;
    public $phone;
    public $msg;

    /**
     * Create a new message instance.
     *
     * @param $name
     * @param $email
     * @param $phone
     * @param $msg
     */
    public function __construct($name, $email, $phone, $msg)
    {
        $this->name = $name;
        $this->email = $email;
        $this->phone = $phone;
        $this->msg = $msg;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {

        $address = '[email protected]';
        $dest_name = 'Web';
        $subject = 'Contacto Web';

        return $this->view('emails.welcome')
            ->to($address, $dest_name)
            ->from('[email protected]', $this->name)
            ->subject($subject);

    } }
    
answered by 09.09.2017 / 19:52
source
0

What server are you using? These data I hope they are just sample, but this is the problem

MAIL_DRIVER=smtp
MAIL_HOST=smtp.dominio.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

There are also postal companies like sendgrid that put you monthly limit and if you exceed it, they leave the emails in "waiting" to be sent as soon as the month ends and the next one begins

    
answered by 06.09.2017 в 10:20