Swift_transportexception error when sending e-amil using SMTP + Laravel 5.4

Asked

Viewed 1,095 times

0

Speak Person, one more trouble, it’s as follows:

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

My file . env is as follows:

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

Include the password is the same, so you can test and see that I am not passing the wrong information

I have a model called Contact, in it I have Function email() the following form:

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 Contactocontroller, who makes the call in 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 mistake, which happens when trying to send the email: Erro que é apresentado no momento do envio

I don’t think it’s relevant to post something related to the view, but if necessary I can post.

1 answer

0


Sometimes the laziness of not reading the documentation gets in the way:

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 that the problem was solved, I was trying to send the email without having the prerequisites.

Source: Laravel 5.4

Browser other questions tagged

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