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

loslara's avatar

problem sending mail using laravel 11 and mailtrap

i'm tring to send test email using mailtrap but i get this error: Trying to access array offset on value of type null in file... my env file: MAIL_MAILER=smtp MAIL_HOST=sandbox.smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=//myusername MAIL_PASSWORD= //mycode MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS="[email protected]"

my controller

    use Illuminate\Support\Facades\Mail;
    
    class RespController extends Controller{
    //code...
    Mail::to('[email protected]')->send(new PasswordMail()); // the problem on this lign
}

PasswordMail:


namespace App\Mail;

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

class PasswordMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     */

    public function __construct(){
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'identifiants de connexion',
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            view: 'PasswordMailContent',
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}

PasswordMailContent is just normal html file with h1 element

my error trace:

im not allowed to post links on my first day here: some of my error trace: #0 C:\xampp\htdocs\gs-backend\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(256): Illuminate\Foundation\Bootstrap\HandleExceptions-&gt;handleError(2, &#039;Trying to acces...&#039;, &#039;C:\\xampp\\htdocs...&#039;, 91) #1 C:\xampp\htdocs\gs-backend\vendor\symfony\mailer\Transport\Smtp\Stream\AbstractStream.php(91): Illuminate\Foundation\Bootstrap\HandleExceptions-&gt;Illuminate\Foundation\Bootstrap\{closure}(2, &#039;Trying to acces...&#039;, &#039;C:\\xampp\\htdocs...&#039;, 91) #2 C:\xampp\htdocs\gs-backend\vendor\symfony\mailer\Transport\Smtp\SmtpTransport.php(341): Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream-&gt;readLine() #3 C:\xampp\htdocs\gs-backend\vendor\symfony\mailer\Transport\Smtp\SmtpTransport.php(196): Symfony\Component\Mailer\Transport\Smtp\SmtpTransport-&gt;getFullResponse() #4 C:\xampp\htdocs\gs-backend\vendor\symfony\mailer\Transport\Smtp\EsmtpTransport.php(118):

0 likes
3 replies
Jsanwo64's avatar

try this format

 use Illuminate\Support\Facades\Mail;
use App\Mail\EplusFormSubmissionWard;

// Assuming $request is available and has 'email' field
Mail::to($request->email)->send(new EplusFormSubmissionWard());

or

use Illuminate\Support\Facades\Mail;
use App\Mail\EplusFormSubmissionWard;

$info = '[email protected]';
Mail::to($info)->send(new EplusFormSubmissionWard());
1 like
Jsanwo64's avatar
Jsanwo64
Best Answer
Level 11

Also Ensure that PasswordMail is instantiated correctly.

1 like
loslara's avatar

@jsanwo64 dang, that was the problem i selected the password and copied it wrong in env file, thanks man

Please or to participate in this conversation.