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

Randy_Johnson's avatar

How do I setup up Mail.

I am trying to set up mail and there are some new things which I am not used to. Can any clarify if this is looking legit, or am I missing something.

.env

MAIL_MAILER=smtp
MAIL_HOST=smtp.hostinger.com
MAIL_PORT=465
MAIL_USERNAME=************************
MAIL_PASSWORD=************************
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS="************************"
MAIL_FROM_NAME="************************"

RegisterUserController

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

ContactMail

class ContactMail extends Mailable
{
    use Queueable, SerializesModels;

    public $details;

    /**
     * Create a new message instance.
     */
    public function __construct($object)
    {
        $this->details = $object;
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            from: new Address($this->details['from'], $this->details['name']),
            subject: $this->details['subject'],
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            text: $this->details['content'],
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}
0 likes
4 replies
LaryAI's avatar
Level 58

The configuration in the .env file and the code in the RegisterUserController and ContactMail classes look correct for setting up mail using SMTP with SSL encryption. However, it's important to ensure that the credentials provided in the .env file are correct and that the SMTP host is reachable from the server where the application is running.

To test if the mail setup is working, you can try sending a test email using the tinker REPL:

php artisan tinker

Then, run the following command to send a test email:

\Mail::raw('Test email', function($message) {
    $message->to('[email protected]')
            ->subject('Test email');
});

If the email is sent successfully, then the mail setup is working correctly.

Randy_Johnson's avatar

@LaryAI Lary, I got the response error of

Connection could not be established with host "mailpit:1025": stream_socket_client(): php_network_getaddresses: getaddrinfo for mailpit failed: No such host is known.

Also I cannot find any reference to mailpit:1025 in my app.

1 like
Snapey's avatar
Snapey
Best Answer
Level 122

@Randy_Johnson 1st step is php artisan config:clear

next, check the content of config/mail.php

next, confirm the smtp credentials for hostinger

2 likes
Randy_Johnson's avatar

This is for future reference for myself, and anyone else. The problem was to do with the verify_peer and its position since it has changed since v9.

        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode'  => null,
            'verify_peer' => false,
        ],

Please or to participate in this conversation.