insight's avatar

How to send test email from localhost ?

Dear Friends, I need to test my email functionality from my localhost. I try to use sendgrid and give in .env file as

MAIL_MAILER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=SG.6sWi-0PqQ8K055dVYMMA0Q.8AfxFU23JrnhHofhNfB1bxxxxxxxxxxxxxxxxxxxxxxxxxx
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"

But I got error as

    "exception": "Symfony\Component\Mailer\Exception\TransportException",

My Controller call is

Mail::send('emails.Help', $request->all(), function($message) use ($name) {
            $message->to('[email protected]');
            $message->subject('New Help Request from ' .$name);
        });

My view is

<!DOCTYPE html>
<html>
<head>
    <title>New Help Request Submission</title>
</head>
<body>
    <h1>New Help Request Submission</h1>
    <p>
        This email is to inform you that a new help request form has been submitted.
    </p>
    <p>
        The following information was submitted:
    </p>
    <ul>
        <li>Name: {{ $name }}</li>
        <li>Email: {{ $email }}</li>
        <li>Mobile: {{ $mobile }}</li>
        <li>Details: {{ $details }}</li>
    </ul>
</body>
</html>

Please help to solve this issue

Thanks

Anes P A

0 likes
5 replies
Snapey's avatar
Snapey
Best Answer
Level 122

if you are going to specify tls then you need to use port 465

1 like
insight's avatar

@Snapey Thanks Dear @snapey I changed port to 465 and php artisan optimize do the wonder. Mail gone and it came in spam folder . Just change the settings of spam will do the change. I am using sendgrid to do this...

Thanks

Anes P A

1 like
Snapey's avatar

@insight to avoid mail going into spam, make sure you create an SPF record in your DNS to say that sendgrid is allowed to send email on behalf of the domain.

1 like
Snapey's avatar

A good solution for a test email account is https://ethereal.email/

You can create a mailbox and send emails to it, similar to mailtrap. An advantage over mailtrap is that it has no rate limiting. A disadvantage might be that it throws away messages after about 16 hours.

Once you create an account you can just plug the credentials straight into your .env file, no messing about verifying domains or sender signatures.

Any and all mail sent by your app will end up in the ethereal mailbox where you can review the layout, headers etc etc

Please or to participate in this conversation.