Mail generated in PHP going to spam [duplicate] - php

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP: How to avoid a system generated e-mail going into spam?
How to send 100.000 emails weekly?
I am using the following script to send mail
$to = 'name#test.com' . ', ';
$to .= 'name2#test.com';
$subject = 'Green apple';
$message = 'Enquiry posted by test ';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Green Apple <info#greenappleme.com>' . "\r\n";
if (mail($to, $subject, $message, $headers))
{
echo "mail send successfully";
}
else
echo "mail can't send";
When I use this script to some servers, the mail is going to spam. But in some servers, it is going to the Inbox as desired.
How can I prevent email going to spam?

To prevent an email going into spam, don't send with mail from PHP. Send it with SMTP from your server, you can use PHP to connect to SMTP and submit the message. You will then need to set the SPF records on your server, and reverse DNS records with whoever your IP address comes from. If you do these three things then you'll be on the whitelist and all your emails will go into the inbox everywhere, assuming you don't abuse the privilege and get put on a blacklist.
So: send using SMTP, research SPF records and reverse DNS.
You won't be able to do this unless you have a dedicated server with dedicated IP for the domain from which you are sending the email from.

Be sure to set the RETURN PATH as the optional 5th parameter to the mail() function.
if (mail($to, $subject, $message, $headers, '-finfo#greenappleme.com'))

TO send ur majority mail in inbox set below headers and dont use test like keywords in your subject line
$headers = "From: My site<noreply#example.com>\r\n";
$headers .= "Reply-To: info#example.com\r\n";
$headers .= "Return-Path: info#example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Related

How to avoid PHP mail output going to junk mail? [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
My mails using php mail() are going to the junk mail folder - why?
<?php
ob_start();
session_start();
//define the receiver of the email
$from='mrashidap#gmail.com';
$to = 'mrashidap#gmail.com';
//define the subject of the email
$subject = 'inform me please, when u receive this mail';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
#Now We Can Use HTML Tags
$headers = "From: " . strip_tags($from). "\r\n";
$headers .= "Organization: appstribes\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Reply-To: ".($from) . "\r\n";
$headers .= "Return-Path: ".($from) . "\r\n";
$headers .= "X-Priority:3 \r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$headers .= "X-MSMail-Priority: high\r\n";
$msg = '<html><body>';
$msg .= '<p>Dear Sir/Madam</p><br/>';
$msg .= '<p><strong>GOOD DAY..!!!</strong></p>';
$msg .= '<p>Thank you for contacting Keita Customer Service. We regret any inconvenience you have experienced. Your request has been received, and a ticket has been created for you with,</p>';
$msg .= '<p><strong>Reference ID : khd004</strong></p>';
$msg .= '<p>Our team is looking into your request and you can expect next to be contacted with either an answer to your question(s) or a solution to the issue(s) raised. Our expected time-frames to respond will vary according to the severity or complexity of the matter being addressed and volume of contacts reaching us. However we assure you that we are working to get back to you as fast as possible and to properly address your questions and concern.</p>';
$msg .= '<p>Regards,</p>';
$msg .= '<p>Keita IT Team</p><br/>';
$msg .= '</body></html>';
$message=$msg;
//send the email
$mail_sent = #mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
Most of the mails are going to junk. However mail sending to gmail are getting in inbox itself.
Your script claims this email is sent from gmail, which is not true
Not clear whether your server signs emails with DKIM or not, does it have SPF or not
Server may be graylisted
Google may not designate your domain as a permitted sender
Any of these reasons may lead to considering your emails as spam.

When i send the email using php in gmail it went to the Spam folder in gmail? How can i prevent that? [duplicate]

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 6 years ago.
please refer the following code.in there am sending username and password.email has sent to the gmail.but it is in spam folder.it happens only in gmail.
Here is my code
$to = $email;
$subject = ' Web Site| login Details'; // Give the email a subject
$message = '
Thanks for signing up!
Your account has been created, you can login with the following credentials.
------------------------
Username: '.$uname.'
Password: '.$upass.'
Web Builder login: '.$ulink.'
------------------------ ';
$headers .= 'From:noreply#ggg.eee.net' . "\r\n";
$headers .= 'Bcc: kae#ggg.eee.net' ."\r\n";
$headers .= 'Bcc: thi#ggg.eee.net' ."\r\n";
mail($to, $subject, $message, $headers);
There are many reasons why email providers mark your messages as spam. Sometimes it has to do with the way your server and DNS are configured or other times it may be the content of your message. I would recommend using this tool to help pinpoint the weak spots of your email messages to help you get through most spam filters
Mail-Tester.com
Use this code may be it work properly
$to = Email;
$subject = ' Web Site| login Details'; // Give the email a subject
$message = '
Thanks for signing up!
Your account has been created, you can login with the following credentials.
------------------------
Username: '.$uname.'
Password: '.$upass.'
Web Builder login: '.$ulink.'
------------------------ ';
$headers = 'From: noreply#ggg.eee.net' . "\r\n" ;
$headers .='Reply-To: '. $to . "\r\n" ;
$headers .= 'Bcc: kae#ggg.eee.net' ."\r\n";
$headers .= 'Bcc: thi#ggg.eee.net' ."\r\n";
$headers .='X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
if(mail($to, $subject, $message ,$headers)) {
echo('<br>'."Email Sent ;D ".'</br>');
}
else
{
echo("<p>Email Message delivery failed...</p>");
}
I have found the soution of this problem:
Solution-1:
Use double quotes to headers.
Solution-2:
The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.
Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.
Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.
https://github.com/PHPMailer/PHPMailer
Source of solution

mail() function not working for domain mail address [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am trying to use php mail() function on my new web server(linux based server) for my website. The issue is, emails are not sending to domain email addresses like some1#domain.com but its working fine for gmail, yahoo. I don't know what is the issue on it?. please give me suggestions or advice how to solve this issue. I want to send emails to domain-based email addresses.
my code is
//$to = $_POST['femail'];
$to = "<toadd#domain.com>";
$message = "
<html>
<head>
<title>".$subject."</title>
</head>
<body>
<p>Registration request from site</p>
<table>
<tr>
<td>Project Requested</td>
<td>".$project."</td>
</tr>
</table>
</body>
</html>";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <info#domain.com>' . "\r\n";
$headers .= 'Cc: <some#domain.com>' . "\r\n";
$headers .= 'X-Mailer: PHP/' .PHP_VERSION. "\r\n";
#mail($to,$subject,$message,$headers);
I have faced the same issue..after a talk with hosting service provider I came to know that either sender or receiver's email id should be of the hosting domain id like if you have a site test.com either sender or receiver should have #test.com so you may do the same or talk to your hosting service provider.
$to = "toadd#domain.com"; //to address
$subject ="Your Subject";
$message = "Your message";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: info#domain.com' . "\r\n"; //from address
if (mail($to, $subject, $message, $headers) )
{
echo "Mail sent successfully";
}
else
{
echo "failed to send mail";
}

email with php BCC and To relations and also spam issue

i am having a issue with sending emails with cronjobs.
actually i need to send email to all the recently joined users
and so the emails are something like $to='acx1#xyz.com,acx2#xyz.com,acx3#xyz.com';
here i need to send the mail to all the receipts but not to let them know that i have sent this mail to all these persons in receipt basically BCC them
but the problem is that if i put the $to into BCC then what should i put in to function of mail
if to is empty then it may be spamed
i want to send this mail to all the receipts but when they check the headers they should see their email only
and one more issue please let me know if i am using correct headers ?
because sometimes my email is spammed by gmail
$from='tests.com';
$to='contact#test.com';
$message="<body> some html data with inline css </body>"
$subject="Hii this is test";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: $from <contact#test.com>" . "\r\n";
$headers .= "Reply-To: contact#test.com" . "\r\n";
$headers .= 'BCC: acx1#xyz.com,acx2#xyz.com,acx3#xyz.com' . "\r\n";
mail($to, $subject, $message, $headers);

PHP mail function is sending emails in Gmail's SPAM folder, How to get rid of it?

i am using this code :
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
it sends email to my gmail's SPAM folder .
Suggest any solution .
i dont want to use any PEAR MAIL type way to send email or dont want to require and include any file.
This functions works without including/requiring any additional php file.
You should use proper header like this from PHP manual
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
The Gmail spam filter has lots of parts to it which determine the spamminess of mail. You could start by seeing the SPF record for your domain. Avoid using sales language, HTML and colours where possible in your email.
There's also an old but fun video from Google about how their spam filtering works.
It's all in the headers. I don't know how GMail works internally, but I've found on my projects that setting Reply-To can Content-Type headers seems to fix this.
See PHP mail() docs for an example of doing this.
(Note: I've got a PHP questionnaire/response system that sets these headers and the e-mails come through correctly to GMail, Hotmail and Yahoo! Mail).

Categories