2

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');
        }
    }
Edwin
  • 1,135
  • 2
  • 16
  • 24
Shahzad Intersoft
  • 762
  • 2
  • 14
  • 35
  • 1
    Whether or not something ends up in spam is not something your app can directly control. It depends on the email content and the recepients' settings. If you're sending to Gmail users then [Google has some guidelines](https://support.google.com/mail/answer/6227174) you should be following – apokryfos Aug 18 '17 at 07:55
  • @apokryfos but same mail content and same recepients got mail in inbox when mail fire from localhost – Shahzad Intersoft Aug 18 '17 at 08:01
  • Maybe localhost is a more trusted domain than whatever host it is you're using. If you're using a shared provider then someone else using the same provider to send spam will cause the same IPs to be blacklisted. Read the Google suggestions – apokryfos Aug 18 '17 at 08:02
  • @apokryfos ok Thank you so much – Shahzad Intersoft Aug 18 '17 at 08:05

4 Answers4

7

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?

Edwin
  • 1,135
  • 2
  • 16
  • 24
0

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.

Peter Szalay
  • 376
  • 3
  • 13
0

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

Amit Kadam
  • 589
  • 6
  • 7
0

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