Olá, gostaria de saber como enviar e-mail pelo laravel tentei da seguinte forma e não resolveu, segue codigo:
ERRO QUE ESTA APRESENTANDO:
(1/1) Swift_TransportException
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
"
\config\mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'meuhost.com.br'),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'site@meudominio.com.br'),
'name' => env('MAIL_FROM_NAME', 'Contato do Site'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('site@meudominio.com.br'),
'password' => env('SENHA DEFINIDA'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
.env
MAIL_DRIVER=smtp
MAIL_HOST=meuhost.com.br
MAIL_PORT=465
MAIL_USERNAME=site@meudominio.com.br
MAIL_PASSWORD=SENHA DEFINIDA
MAIL_ENCRYPTION=tls
controller
namespace App\Http\Controllers;
use App\Http\Requests\ContatoRequest;
use Illuminate\Http\Request;
use Mail;
class HomeController extends Controller {
public function enviar(Request $request){
$data = $request->all();
Mail::send('enviar', $data, function ($message) {
$message->from("site@meudominio.com.br")
->to('suporte@meudominio.com.br')
->subject('Contato');
});
}
}
request
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ContatoEnviarRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'nome' => 'required|min:3|alpha',
'lastname_contact' => 'required|min:3|alpha',
'email' => 'required|email',
'phone_contact' => 'required'
'mensagem' => 'required|min:30',
];
}
}
View ENVIA <!DOCTYPE html>
Dados do contato
Nome: {{ $nome }}
E-mail: {{ $email }}
Telefone: {{ $phone_contact }}
Mensagem: {{ $mensagem }}
VIEW CONTATO
<form action="/envia" method="post">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label>Nome</label>
<input input type="text" name="nome" class="form-control">
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label>Sobrenome</label>
<input type="text" class="form-control" name="lastname_contact">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control" >
</div>
</div>
<div class="col-md-6 col-sm-6">
<div class="form-group">
<label>Telefone de Contato</label>
<input type="text" id="phone_contact" name="phone_contact" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Sua Mensagem</label>
<textarea rows="5" class="form-control" name="mensagem" style="height:100px;"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<button class="btn btn-primary">Enviar</button>
</div>
</div>
</form>
</div>