(Laravel 5.6.)
I have 2 enviroments, qa
and prod
.
In qa everything works ok, but in prod Emails are sending wrong.
The idea is to send emails to a list of emails that are an input of a user when something is triggered. In other words, the "edit" view of a user looks like:
name:
password:
emails_list: // a string
In my app, I have a button that calls and ajax
url and that url execute a function that have this code:
// $emails is an array of emails made from the $user model with
// $user->emails_list (using 'explode' to convert the comma separated string into an array)
foreach($emails as $email){
$email = str_replace('"', '', str_replace(' ', '', $email));
Mail::to($email)
->send(new IntentosAgotados($user));
}
// and IntentosAgotados($user, $reporte) is:
class IntentosAgotados extends Mailable
{
use Queueable, SerializesModels;
protected $user;
public function __construct($user)
{
$this->user = $user;
}
public function build()
{
return $this->subject("[My App] - Some text")
->view('emails.someview',[
'user' => $this->user,
]);
}
}
If a user has 2 emails in the emails_list
the wrong behaviour is like this:
So the 3rd time, is sending the new email, BUT also one email of each others two emails:
1th, 1th-2nd, 1th-2nd-3rd, etc
White should be "just send one email to each users"
I'm not using queues for this, the emails are sending in the moment.
But everything goes ok in qa
enviroment as I said. So my question is:
How could I track why is sending wrong the emails? a log? or should I put some dd()
around my code to see what's is happening and why is trigger in more than expected the mail
function.