Laravel 9 Mail not delivering to yahoo

223 Views Asked by At

I have a sign up page, and I want to implement send a welcome mail and a verify mail manually. I used mailtrap as my mail host. I set up the mail block of .env like so

MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=2c13ecf1f27070
MAIL_PASSWORD=6f6562df21bc72
MAIL_ENCRYPTION=tls

I have a mail verification file:

class MailVerification extends Mailable
{
    use Queueable, SerializesModels;
    public $data;

    public function __construct($data)
    {
        //
        $this->data = $data;
    }

    public function envelope()
    {
        return new Envelope(
            subject: 'Mail Verification',
        );
    }

    public function build()
    {
        $subject = 'Mail Verification';
        return $this->view('emails.index')
                    ->subject($subject);
    }
}

From my UserController i want to fire the mail once sign up is successful; so my UserController looks like:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Listing;
use App\Models\Company;
use Dotenv\Parser\Value;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Mail;
use App\Mail\MailVerification;

class UserController extends Controller
{
    //show sign up form
    public function create(User $user){
        return view('users.signup');
    }
    //Store form fields to database
    public function store(Request $request){
        $chkUser = User::where('email', '=', $request->input('email'))->first();
        if ($chkUser) {
            return 0;
        }else{
            $user = new User;
            $user->firstname = $request->fname;
            $user->lastname = $request->lname;
            $user->email = $request->email;
            $user->image = 'storage/profile_images/placeholder.png';
            if ($request->has('subscribe')) {
                $user->subscribe = 'subscribed';
            }else {
                $user->subscribe = 'unsubscribed';
            }
            $user->password = bcrypt($request->password);
            $user->save();
            auth()->login($user);
            $data = [
                "firstname" => $request->fname,
                "email" => $request->email
            ];
            Mail::to($request->email)->send(new MailVerification($data));
            return 1;
        }
    }
}

I create the first user account an it sent the mail successfully, screenshot of mail in yahoo mailbox. However, subsequent mail does not deliver at all, i only see them in my Mail trap inbox. I also noticed that the sender id in the mail shows Laravel.

2

There are 2 best solutions below

0
Brn.Rajoriya On
  1. Set MAIL_FROM_NAME in .env file to change name Laravel.
  2. Need to check the SMTP delivery or failed massage from your SMTP host panel. It may be IP block / SPF,DKIM failure.
0
Ikenitenine On

You may use service mail tester to find your SMTP server problems.