Swift_TransportException error while sending e-amil using SMTP + Laravel 5.4

0

Speak Person, one more trouble, is as follows:

I'm trying to send an email through my application (api), where I develop with Laravel 5.4. The thing seems very easy, just not!

My .env file looks like this:

MAIL_DRIVER=smtp
MAIL_HOST=mail.estilosoft.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=meAjuda123
MAIL_ENCRYPTION=null

Include the same password, for you to test and see that I am not passing the wrong information

I have a model called Contact, in it I have the function email () as follows:

public function email($dados){

    Mail::send('contatoEmail',$dados, function ($message){
        $message->subject('E-Mail Example');
        $message->from('[email protected]','Contato');
        $message->to('[email protected]');
    });
    if(Mail::failures())
        return Mail::failures();
    else
    return true;
}

I also have a ContactController, which makes the call in the function:

namespace App\Http\Controllers;
use App\Contato;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class ContatoController extends Controller{

public function store(Request $request){
    $validator = Validator::make($request->all(), [
        'nome' => 'required',
        'sobrenome' => 'required',
        'email' => 'required',
        'telefone' => 'required',
        'assunto' => 'required',
        'departamento_id'=> 'required',
        'mensagem' => 'required',
    ]);
    if ($validator->fails()) {
        return response()->json(['erro'=> true, 'mensagem'=>'Formato de dados inválidos!','data'=>$request->all()], 401);
    }

    $contato = new Contato();
    $contato->fill($request->all());
    if($contato->save()){
        if($contato->email($request->all())){
            return response()->json(['erro'=> false, 'mensagem'=>'Mensagem salva, email enviado!','data'=>$contato], 201);
        }else{
            return response()->json(['erro'=> false, 'mensagem'=>'Mensagem salva!','data'=>$contato], 201);
        }
    }else{
        return response()->json(['erro'=> true, 'mensagem'=>'Não conseguimos salvar sua solicitação','data'=>$contato], 201);
    }
}

} // class

And to end the problem, or rather, to start the problem, the damn error, which happens when trying to send the email:

I think it's not relevant to post something about the view, but if I need to, I can post it.

    
asked by anonymous 14.09.2017 / 04:54

1 answer

0

Sometimes the laziness of not reading the documentation is a mess:

  

Driver Prerequisites / - /   The API based drivers such as Mailgun and SparkPost are often simpler and faster than SMTP servers. If possible, you should use one of these drivers. All of the API drivers require the Guzzle HTTP library, which may be installed via the Composer package manager:

composer require guzzlehttp/guzzle

With this the problem was solved, I was trying to send the email without having the prerequisites.

Source: Laravel 5.4

    
16.10.2017 / 17:06