0

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 MAIL_USERNAME=vidalmanriquecab@gmail.com MAIL_PASSWORD=1234 MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=vidalmanriquecab@gmail.com

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

Vidal M.
  • 133
  • 1
  • 11
  • 2
    did you check for logs in laravel.log – mightyteja Apr 18 '21 at 16:45
  • 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. Apr 18 '21 at 17:29
  • it says undefined variable 'name' but it is – Vidal M. Apr 18 '21 at 17:30
  • local.ERROR: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed {"exception":"[object] (ErrorException(code: 0): stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed at C:\\laragon\\www\\ayudas-ocm\\vendor\\swiftmailer\\swiftmailer\\lib\\classes\\Swift\\Transport\\StreamBuffer.php:94) – Vidal M. Apr 18 '21 at 17:45
  • 1
    I searched for google for term local.ERROR: stream_socket_enable_crypto(): . Its listing few SO articles. Can you please go through those – mightyteja Apr 18 '21 at 17:52
  • Also,please try sending plain text in the blade removing all the variables to cross check – mightyteja Apr 18 '21 at 17:53
  • i came to this. sorry no SO. https://discourse.laminas.dev/t/stream-socket-enable-crypto-ssl-operation-failed-with-code-in-zend-mail/1130 . then another error and came to this, where i´m stuck https://stackoverflow.com/questions/14176965/swift-transportexception-connection-could-not-be-established-with-host-smtp-gmai – Vidal M. Apr 18 '21 at 17:57
  • user credintials are correct. tried to flush cache and all that stuff. Also got my antiv down for a try, but nothing else matters... – Vidal M. Apr 18 '21 at 17:58
  • 1
    I came to this after various trials, and now it´s working to me https://stackoverflow.com/questions/32693528/expected-response-code-220-but-got-code-with-message-in-laravel. Thanks @mightyteja – Vidal M. Apr 18 '21 at 18:29

1 Answers1

2

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
Vidal M.
  • 133
  • 1
  • 11