0
votes

I have problem in my laravel project and don't know how to solve that I use mailtrap smtp server to send mail for special user the mail not sending - I tried every way ! in other new laravel project smtp server working successfully whats your idea?

here is my Controller:

 public function SendContactRespone(ContactReply $request , $id)
{

    Mail::to($request->email)->send(new ContactRespone($request));

    //Contact_form::destroy($id);
    return redirect(route('admin.contact.index'))
        ->with('success', trans('app.err.AnswerEmailed'));
}

here is my ContactRespone Mailable

    <?php

namespace App\Mail;

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

class ContactRespone extends Mailable
{
    use Queueable, SerializesModels;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
     return  $this
           ->from(env('MAIL_FROM_ADDRESS','[email protected]'))
           ->subject($this->request->subject)
           ->markdown('ui.mails.contactReply')
           ->with([
            'subject' => $this->request->subject,
            'message' => $this->request->text,
        ]);

    }
}

env Setting :

    MAIL_DRIVER=smtp
MAIL_HOST="smtp.mailtrap.io"
MAIL_PORT="2525"
MAIL_USERNAME="******"
MAIL_PASSWORD="*******"
MAIL_ENCRYPTION=''
MAIL_FROM_ADDRESS="no-reply@*****.***"

after submit the request an email html source save in Storage/log/laravel.log

1

1 Answers

0
votes

change to your .env file configuration for mailtrap:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=USERNAME
MAIL_PASSWORD=PASSWORD
MAIL_ENCRYPTION=null

Here you can get username and password https://mailtrap.io/inboxes you will see the following mailtrap SMTP credentials, Where the username and password are located

After change of .env edit please clear cache: php artisan config:cache