user image

Eslam Zedan
Published in : 2022-02-28

PHP mail function goes to spam not inbox

PHP & Mysql


I want to send an email using the PHP mail function not SMTP (I know that is not good practice but the Client request that).

the emails go to the junk/spam folder is there any way to make it goes to the inbox as a normal email?

I tried the solution here

but it goes to junk 

here is my code 

$to_email = '';
$subject = 'Testing PHP Mail';
$message = 'This mail is sent using the PHP mail function';

$headers = "From:\r\n";
$headers .= "Reply-To:\r\n";
$headers .= "Return-Path:\r\n";
$headers .= "CC:\r\n";
$headers .= "BCC:\r\n";

any help please


Shilpa Date : 2022-02-28

Best answers


Best answers


It seems like your SMTP server is not configured well.

To be aware of spam emails, the latest mail clients will check who is sending an email. It uses a test like Reverse-DNS-Lookups.

Your PHP mail() function will fail with this test.


Solution: You can use PHPMailer-Class and configure it to use SMTP-auth along with a well configured, dedicated SMTP Server (Recommended AWS server) and your problems will be fixed 100%.

Eslam Zedan Date : 2022-02-28

My clint does not want me to use SMTP so I am using native php mail function 

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Mysql query: How do I count the day streak of particular user?
Publish date: 2022-03-01 | Comments: 4

Tag: PHP & Mysql

Warning appears in Zend framework
Publish date: 2022-02-24 | Comments: 1

Tag: PHP & Mysql

MySQL - Lost connection to MySQL server during query - Required a solution.
Publish date: 2022-03-03 | Comments: 1

Tag: PHP & Mysql

mysql service start not exist
Publish date: 2022-02-23 | Comments: 4

Tag: PHP & Mysql

ERROR 1410 (42000): You are not allowed to create a user with GRANT
Publish date: 2022-04-01 | Comments: 2

Tag: PHP & Mysql

How the image file have .php extension?
Publish date: 2022-03-01 | Comments: 2

Tag: PHP & Mysql

CodeIgniter route does not work
Publish date: 2022-02-22 | Comments: 4

Tag: PHP & Mysql