Not able to send email using mailtrap in laravel

146 views Asked by At

I am using mailtrap for send email after submit inquiry message. firstly i created account and configure credentials in .env file mail section. and after i used \mail::To function to send email. but it is not working. please help me to resolve my mistake.

.env


    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=503848ba931ece
    MAIL_PASSWORD=5a62476eecc5f5
    MAIL_ENCRYPTION=null
    [email protected]
    MAIL_FROM_NAME=Example

FrontEndController.php


public function SubmitMessage(Request $request){
        $inquiry = new Inquiries;
        $inquiry->full_name = $request->fullname; 
        $inquiry->email = $request->email;
        $inquiry->phone = $request->contactno;
        $inquiry->message = $request->message;
        $inquiry->save();
        return response()->json(['status' => 200, 'message' => 'Your message saved successfully']);
        \Mail::to('[email protected]')->send(new Inquirymail($inquiry->message));
    }

Inquirymail.php

<?php

namespace App\Mail;
namespace App\Models;

use App\Models\Inquiries;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class Inquiries extends Mailable
{
    use Queueable, SerializesModels;
    public $inquiry;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($inquiry)
    {
        $this->inquiry = $inquiry;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->inquiry;
        print_r("Hello");
    }
}

0

There are 0 answers