Controller:
$sent = Mail::to('[email protected]')->send(new Welcome($name, $email, $phone, $msg));
.send:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.dominio.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
View:
<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 doesn't change anything. I don't know what else to try, I have created a new mailable and the same thing.
Version: Laravel 5.4
What server are you using? I hope these data are just a sample, otherwise this is the problem
There are also email companies like sendgrid that put a monthly limit on you and if you exceed it, they leave the emails on "waiting" to be sent as soon as the month ends and the next begins.
After doing a lot of tests, I came to the conclusion that I only needed one thing to check.... Let's see if the server's IP was blocked due to SPAM or something.... and indeed they had blocked me and the reason was MAIL SPOOFING, therefore the Mailable class would be like this.
Since what I did was take the email that they wrote me in the form and put it in the from as if that account had sent the email directly.