Shahzad Intersoft
Shahzad Intersoft

Reputation: 772

How to configure .env file avoid spam mail in Laravel 5.4

I am working with Laravel 5.4. When I am sending mail from Local server mail is going to the inbox folder working fine, configure file .env following :-

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=email
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

After that I shift to live server and I configure the .env file following:->

MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=ssl

mail receive but in spam folder.How to avoid from spam folder.

Here is my Controller function

function createSchool(Request $request){

        $this->validator($request->all())->validate();

        $user = $this->create($request->all());

        if($user){

            $mailInformation = $request->all();

            if($mailInformation){

                Mail::to($request->user())
                ->cc($mailInformation['email'])
                ->send(new SchoolRegistration($mailInformation)); 
            }

            return redirect('admin/schools')->with('success', 'School  added Successfully');
        }
    }

Upvotes: 3

Views: 26066

Answers (4)

Avinash Kumar
Avinash Kumar

Reputation: 29

use view insted of markdowm in your mail.php . it will solve your problem :)

Upvotes: 0

Amit Kadam
Amit Kadam

Reputation: 629

In my case the main reason was markdown, I switched markdown to simple views and problem solved!

Upvotes: 0

Edwin
Edwin

Reputation: 1135

Your emails landing is spam has nothing to do with the framework but there are a couple of things that you could check why it happens:

  • Is the domain hosted on the server that is sending the email?
  • Is a correct SPF record setup for my domain?
  • Is my message source valid? Does it contain content that might trigger spam filters?
  • Are the headers set properly?

These questions contribute to emails not landing in spam but it's not a definite solution. :-)

Some reading material:
php email - how to avoid mail ending up in spam box
How do you make sure email you send programmatically is not automatically marked as spam?

Upvotes: 7

Peter Szalay
Peter Szalay

Reputation: 386

Your problem is probably Reverse-DNS-Lookup. If you want to be sure that your emails arrive and are not marked as spam then you need to set up your own email server. I use sendmail on linux servers.

Upvotes: 0

Related Questions