How do I send email via E-mail?

Asked

Viewed 81 times

1

I have the following routine implemented in Laravel

$prestadores = \App\Prestador::all();

Mail::send('emails.listaprestadores',['prestadores' => $prestadores],
   function($message) use ($prestadores){
       $message->to('[email protected]', 'Marcelo Gomes');
       $message->subject('[Teste] Lista de Prestadores');
});

To View is the code below. Does not generate exception, but the email is not sent. I changed the routine to send a simple email and it is sent normally. I believe you’re doing something wrong by passing the array, but I took the example in the documentation of Laravel.

<!DOCTYPE html><html>
<head>
    <title>Lista de Prestadores</title>
</head><body>
<table width="900" class="table table-responsive table-striped">
    <thead>
        <th>ID</th>
        <th>Razão Social</th>
        <th>CNPJ</th>
        <th>Cidade</th>
    </thead>
    <tbody>
        @foreach($prestadores as $prestador)
            <tr>
                <td>{{ $prestador->id ]}</td>
                <td>{{ $prestador->rezao_social ]}</td>
                <td>{{ $prestador->cnpj ]}</td>
                <td>{{ $prestador->cidade ]}</td>
            </tr>
        @endforeach
    </tbody>
</table><table class="table">
<tr>
    <td><span class="small">TrabalhoEmDia.com - Suas tarefas em Dia - </span>/td>    
</tr>
</table>
</body>
</html>
  • @Marcelogomers, $prestadores is a very large information list, maybe the email is being sent, but, blocked by the server, seen perhaps as spam, try sending an HTML email with 1 info if it is maybe this $prestadores

  • Also check the shipping configuration data, sometimes is using some service that requires encryption tls or ssl...even the smtp address may be wrong...

1 answer

2

The problem has been solved by including in the method Mail::send the from.

Correct shipment:

Mail::send('emails.listaprestadores',['prestadores' => $prestadores],function($message) use ($prestadores){
   $message->to('[email protected]', 'Marcelo Gomes');
   $message->subject('[Teste] Lista de Prestadores')
   $message->from('[email protected],'Marcelo');
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.