0
votes

Im trying to send mail from my local laravel project but get err0r 500.Can´t get anything on console but POST error 500.

.ENV

MAIL_MAILER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 [email protected] MAIL_PASSWORD=1234 MAIL_ENCRYPTION=tls [email protected]

ROUTES

use App\Mail\ContactoMailable;
use Illuminate\Support\Facades\Mail;
Route::post('correo',function(){
    $data=request()->all();
    $correo= new ContactoMailable;
    Mail::to($data['email'])->send($correo);
    return view('contacto');
})->name('correo');

BLADE CONTACT FORM

@extends('layouts.main-layout')
@section('styles')
<link rel="stylesheet" href="{{ asset('css/header.css') }}">
@endsection
@section('content')
    <p>Contacta con nosotros utilizando este formulario para que nos pongamos en contacto contigo. Cuanta más información nos des, más ágiles seremos para ofrecerte una solución a la medida de tus necesidades.

        Si prefieres, puedes contactar con nosotros en horario de 9:00 a 14:00 en el teléfono 983 154 444</p>
    <div id="contacto">
        <form id="contact_form" method="POST" action="{{ route('correo') }}">
            @csrf
            @method('post')

MAILABLE

class ContactoMailable extends Mailable
{
    use Queueable, SerializesModels;

    public $subject="Info de contacto";
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('msg.mensaje');
    }
}

Again, any help welcome. Thanks in advance

1
did you check for logs in laravel.logmightyteja
exception":"[object] (Facade\\Ignition\\Exceptions\\ViewException(code: 0): Undefined variable: name (View: C:\\laragon\\www\\ayudas-ocm\ esources\\views\\msg\\mensaje.blade.php) at C:\\laragon\\www\\ayudas-ocm\ esources\\views/msg/mensaje.blade.php:7) [stacktrace][previous exception] [object] (ErrorException(code: 0): Undefined variable: name at C:\\laragon\\www\\ayudas-ocm\\storage\\framework\\views\\6af63c215d4f2225356326d6c5ee8ff7b6c3ad16.php:7) [stacktrace]Vidal M.
it says undefined variable 'name' but it isVidal M.
I searched for google for term local.ERROR: stream_socket_enable_crypto(): . Its listing few SO articles. Can you please go through thosemightyteja
I came to this after various trials, and now it´s working to me stackoverflow.com/questions/32693528/…. Thanks @mightytejaVidal M.

1 Answers

2
votes

To me, solution was in this post

Expected response code 220 but got code "", with message "" in Laravel

Basically you have to enable double check security (Gmail) and then generate an app password, which is used in .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<<your email address>>
MAIL_PASSWORD=<<app password>>
MAIL_ENCRYPTION=tls