Error sending email via php mail function goes to spam

0 votes

I am facing problem in sending mail to my inbox (gmail account) but everytime it goes to spam folder. Here is the code snippet

     //$ticketDetail is array which contain required information to send.
       sendOwnershipEmail('dineshnagarscriet@gmail.com', $ticketDetail);

       function sendOwnershipEmail($email, $ticketDetail) {
            $param = new stdClass();


$param->content = "<div>
    <div><b>".$ticketDetail[0]['ticket_number']."</b></div><br/>
    <div><img src='".$ticketDetail[0]['image_path']."'/></div><br/>
    <div>Ticket with ticket number ".$ticketDetail[0]['ticket_number']." has been requested for tranfer from <div/>
    <div>".$ticketDetail[0]['oldDepartment']." to ".$ticketDetail[0]['newDepartment']." Department <div/>
  </div>";

            $param->sendTo = $email;
            $param->subject = "Request for Department transfer";

        sendMailFunction($param);
    }


    function sendMailFunction($param) {
            $to = $param->sendTo;
            $subject = $param->subject;
            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
            $headers .= 'From: successive.testing@gmail.com' . "\r\n";
            $message = "<html><head>" .
                   "<meta http-equiv='Content-Language' content='en-us'>" .
                   "<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>" .
                   "</head><body>" .$param->content.        
                   "<br><br></body></html>";
          mail($to, $subject, $message, $headers);
    }

And I have tried a lot like setting headers as Reply-To, Return-Path etc but every time it goes to spam. Can u please figure out whats the problem?

Jul 30, 2020 in Laravel by kartik
• 37,520 points
11,107 views
Где Вы ищите свежие новости?
Лично я читаю и доверяю газете https://www.ukr.net/.
Это единственный источник свежих и независимых новостей.
Рекомендую и Вам

1 answer to this question.

0 votes

Hello @kartik,

Try changing your headers to this:

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: successive.testing@gmail.com" . "\r\n" .
"Reply-To: successive.testing@gmail.com" . "\r\n" .
"X-Mailer: PHP/" . phpversion();

For a few reasons.

  • One of which is the need of a Reply-To and,

  • The use of apostrophes instead of double-quotes. Those two things in my experience with forms, is usually what triggers a message ending up in the Spam box.

You could also try changing the $from to:

$from = "successive.testing@gmail.com";

Hope it helps!!

Thank you!!

answered Jul 30, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

+1 vote
1 answer

How to load blade or php content into a view via ajax/jquery in laravel?

Hello @kartik, Assuming you're using jQuery... create a route ...READ MORE

answered Apr 14, 2020 in Laravel by Niroj
• 82,840 points
28,049 views
0 votes
1 answer

How can I get the error message for the mail() function?

Hello @kartik, You can use error_get_last() when mai l()returns false. $success = mail('example@example.com', ...READ MORE

answered Jul 30, 2020 in Laravel by Niroj
• 82,840 points
9,656 views
0 votes
1 answer

Error: Class 'SoapClient' not found in /home/user/mysite.com/path/to/file.php on line 16

Hello @kartik, find this line in php.ini : ;extension=soap then ...READ MORE

answered Oct 29, 2020 in Laravel by Niroj
• 82,840 points
3,400 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,080 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,016 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,948 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,888 views
0 votes
1 answer

Error:PHP mail function doesn't complete sending of e-mail

Hello @kartik, If you are using an SMTP ...READ MORE

answered Jul 30, 2020 in Laravel by Niroj
• 82,840 points
2,395 views
0 votes
1 answer

How to configure Laravel mail.php to use built-in mail function?

Hello, To do the same as mail() PHP ...READ MORE

answered Dec 3, 2020 in Laravel by Niroj
• 82,840 points
3,237 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP