Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sarfaraz1212's avatar

Laravel 11 email error

I am using laravel mailable but for some reason the email is not sending ,also " Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead. " this error message is coming. I don't think there is some issue in the code as i tried every possible combination to make it work.

Mail::to($data->email)->send(new WelcomeMail($data));

MAIL_DRIVER = smtp MAIL_HOST = smtp.gmail.com MAIL_PORT = 587 MAIL_USERNAME = MAIL_PASSWORD = MAIL_ENCRYPTION = MAIL_FROM_ADDRESS = MAIL_FROM_NAME =

can anyone help me with this. I initially though something is wrong with my project, but i also tried sending mail like

Mail::raw('Hi', function ($message) use ($mailFromAddress, $mailFromName) { $message->to('[email protected]') // Recipient's email address ->subject('Test Email') // Email subject ->from($mailFromAddress, $mailFromName); // Sender's email address and name });

in the new project but still it is not going. I have another laravel project where the version is 10 but there the smtp is working

0 likes
14 replies
mostafa-amine's avatar

Just check your mail credentials and ensure that they are correct.

Snapey's avatar

Empty mail from address is not valid

sarfaraz1212's avatar

@Snapey by empty you mean MAIL_FROM_ADDRESS? or the template ... i have just hid the MAIL_FROM_ADDRESS in actual i am passing it.

Snapey's avatar

@sarfaraz1212 then don't share the config if it does not reflect the actual setup. In future just write 'redacted' or similar so that we know there is a value but you don't want to share it.

1 like
click's avatar

"in the new project but still it is not going."

What does that mean? You get an error when you send it or you never see an email coming in?

Do you use an SMTP via a service like mailgun or postmark? If so, you can login there and see what happened with your email. They will be able to tell you if the email was actually sent, it bounced and sometimes they can tell you if it ended up in spam.

If you do not get an error in your application and you are sure the smtp is correct. It might end up in the spam folder or it might be blocked already by the mail service of the recipient. This can be related to a lot of things. Make sure you are allowed to send emails on behalf of the sending email. For example your "from" email is the same as the SMTP. You added the DKIM / SPF / DMARC records to your dns (https://www.cloudflare.com/learning/email-security/dmarc-dkim-spf/).

sarfaraz1212's avatar

@click i am using a yopmail, [email protected]. I don't see any email coming in. I am using MAIL_DRIVER as smtp (gmail) i have not changed anything with the configuration, it is default as it comes with laravel 11.

i managed to send mail like this but i don't think this is optimal.

$transport = (new \Swift_SmtpTransport($setting['host'], $setting['port'], $setting['encryption'] )) ->setUsername($setting['username']) ->setPassword($password);

       // Create the Mailer using your created Transport
       $mailer = new \Swift_Mailer($transport);
       
       // Create a message
       $message = new \Swift_Message();
       $message->setSubject($data['subject']);
       $message->setFrom([$setting['from_email'] => $setting['from_name']]);
       $message->setTo($data['to']);
       
       $message->setBody($data['html'], 'text/html');
   
       // Send the message
       $result = $mailer->send($message);
sarfaraz1212's avatar

@Snapey i know it's not optimal i wrote it but the default is not working idk what else to do.

Snapey's avatar

put it back how it was, ensure config is correct (check it with tinker) and then tell us what error you get.

earnbyshare2016's avatar

I have a similar issue on laravel 11. Hope this could help some of people. It turns out that in since some versions laravel, MAIL_DRIVER has been changed to MAIL_MAILER Thats why MAIL_DRIVER is not working.

And in config/mail.php, MAIL_MAILER default value is 'log'. So my SMTP settings are not applied.

So to fix the problem, just change MAIL_MAILER to MAIL_MAILER in .env.

Ford555's avatar

@earnbyshare2016 ir has been a hell for me, my entire web site failed sendings email. Thank you very much.

In the solución you have a mistake and you put same variables

Please or to participate in this conversation.