-1

I want to send mail to inbox using smtp mail method using PHP.Now mail go to spam instead of inbox,i am using smtp mail method.I had set the hostname,username and password.

  <?php

  define("SMTP_HOST", "mail.test.us"); //Hostname of the mail server
  define("SMTP_PORT", "25"); //Port of the SMTP like to be 25, 80, 465 or 587
  define("SMTP_UNAME", "tttt"); 
  //Username for SMTP authentication any valid   email created in your domain
  define("SMTP_PWORD", "tttt"); //Password for SMTP authentication
  ?>

Mail code

//smtp mail
$mail   = new PHPMailer;
$mail->Host = SMTP_HOST; 
$mail->Port = SMTP_PORT; 
$mail->SMTPAuth = true; 
$mail->Username = SMTP_UNAME; 
$mail->Password = SMTP_PWORD; 
$mail->AddReplyTo("test@test.com", "zamisoft"); 
$mail->SetFrom("test@test.com", "zamisoft.com"); 
$mail->Subject = $subject; 
$mail->AddAddress($to, '');
$mail->MsgHTML($message);
$send = $mail->Send(); 
$mail->ClearAddresses();

//smtp mail

Anybody give any solution for these issue?

CodeWithCoffee
  • 1,896
  • 2
  • 14
  • 36
user3422573
  • 9
  • 1
  • 6
  • Please check the following link http://stackoverflow.com/questions/18229279/sending-email-via-php-mail-function-goes-to-spam – purna gattu May 06 '15 at 06:46
  • 1
    You also never specified, are you using the cheap shared hosting, a VPS, or dedicated server? Mailing off shared hosts usually have a low hourly limit of around 200-400 emails per hour, and trying to send too many emails can (and will) get you suspended. A VPS usually is alright to mail low volumes (maybe 30k-50k a month). However, some web hosts don't like emailing off their VPSs or still have an hourly limit. Dedicated servers usually have unlimited, but hosts like GoDaddy can still be picky about you emailing to larger lists. – Wade May 07 '15 at 07:00
  • My server is in godaddy – user3422573 May 07 '15 at 07:33
  • I understand you use GoDaddy. GoDaddy offers a handful of hosting options. There is a huge difference between which hosting type you have. If you are on the cheap shared hosting, you probably don't have access to setup SPF and DKIM, and they usually are extremely picky about emailing on shared accounts. Also, there are probably 60+ other people sharing the same IP address, killing your inbox chances. A VPS and dedicated usually gives you root access and your own IP address. If you are on a shared (paying about $5-$15/mo) then there isn't much you can do. My best advice, just get SendGrid! – Wade May 08 '15 at 04:16
  • Now i am sending mails using ordinary server,not godaddy,but mail go to spam spam,,i have enabled SPF and TKIM,Can you say any solution – user3422573 May 11 '15 at 07:42
  • If you have done everything in my answer, then no, you will need to use something that is ACTUALLY for mailing. Ordinary server doesn't tell us anything either. What kind, from where, is it a VPS, dedicated server? We need details or nobody can help you. Have you checked your new servers IP to ensure it isn't on any blacklists. Have you had them setup rDNS? Have you changed everything in your email (from name, domain name, subject, message, hostname). Have you tried sending to another provider (Yahoo, Gmail)? You literally have to swap EVERYTHING around because it can by anything! – Wade May 12 '15 at 05:50
  • Just go get SendGrid. They allow like 400 emails a day on their free account. They have their own PHP API similar to PHPMailer: https://sendgrid.com/docs/Integrate/Code_Examples/php.html - 10 mins to setup and forget trying to figure out why your emails are going to spam, its not worth it. If you did everything I said in my answer, then your just going to have to pay someone to figure it out or setup SendGrid for you. – Wade May 12 '15 at 05:58

3 Answers3

1

Add Headers to your email

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

It's been a while since I've played with PHP mail, but if that doesn't work it should put you on the right track.

Morgan Green
  • 1,012
  • 2
  • 10
  • 22
  • He is using PHPMailer, it handles the headers for you, your approach would be going backwards for him. His question didn't have anything to do with SQL queries or building a BCC list. Code wise, he is solid. He needs SPF and DKIM setup, and to make sure he isn't triggering spam filters, his email isn't blacklisted, etc. – Wade May 06 '15 at 07:00
  • Well sending with PHP mailer is how I ended up with my mail going to trash. Going backwards worked for me. – Morgan Green May 06 '15 at 07:12
  • There are countless pages all backing up that php mail() is terrible. When sending emails off a server, you should use an SMTP connection and a valid email account, and mail() disabled on the server. Spammers hack into servers and setup spam farms to take advantage of servers that allow mail(). Because of this, most places like Google and Yahoo think of emails coming from a php script as untrusted. When using SMTP your going to need SPF and DKIM setup. Your issue wasn't using SMTP, it was that it wasn't properly setup and there was more you needed to do. – Wade May 06 '15 at 07:44
  • @WadeShuler, dont't make it personal. – Rohit Gupta May 07 '15 at 08:36
0

Make sure you have SPF and DKIM setup. Since you are mailing from your own server, this is highly recommended.

Here is a link to Namecheap with screenshots. I couldn't explain it better: https://www.namecheap.com/support/knowledgebase/article.aspx/9214/31/email-authentication-tool-in-cpanel-spf-records

Also, there are various checkers out there that well validate your SPF, DKIM, and check other things, and give it a score.

http://www.port25.com/support/authentication-center/email-verification/

https://www.mail-tester.com

http://dkimvalidator.com

The only things you can do when mailing from your own server. Use SPF and DKIM. Stay away from spammy words. One wrong word can make the difference of spam or inbox. Have a baseline email and baseline subject for testing. I had a slogan of mine that landed me in the spam folder, so I had to change it because I wanted it in the signature of my emails. Using certain link shorteners could land you in the spam folder. I am not saying they do, but using bit.ly or tinyurl links could land you there. Using tinypic or another image hosting service could. Your domain name could be the problem! The from name..

Remember, every word (whether it's in your email address, domain name, hostname, subject, or the body of the email) is looked at.

As well as your server's IP address. Is it on any blacklists? Check it with http://mxtoolbox.com/blacklists.aspx

Without one of us actually getting on your server and sending dozens of test email to see what is actually causing it, I can only tell you the dozens of things to check.

With all that said, mailing off your server sucks and I don't recommend it. I suggest using SendGrid or Mailgun. I had a client landing in the spam folder, on a new server, clean IP, new domain, everything. I put him on SendGrid and he wasn instantly going into the inbox.

For development, or a low level site, mailing off your server is fine if your hitting the inbox most of the time. But anyone that takes their site serious and the emails hitting the inbox is important, use a 3rd party. Most servers (from GoDaddy, Hostgator, etc.) are not for sending emails to tens of thousands of customers. They are web servers, not mailing (MX) servers, and they will tell you that it isn't their problem.

Update: I forgot to mention reverse DNS. You should have rDNS setup, and that is done by your upstream. So you would need to contact your webhost and ask them to setup "Reverse DNS" on your server.

Wade
  • 3,757
  • 2
  • 32
  • 51
  • In my server cpanel dont see the option 'Email Authentication' – user3422573 May 06 '15 at 07:16
  • server is goddady server – user3422573 May 06 '15 at 07:21
  • 1
    I don't know GoDaddy servers, but I do know cpanel. GoDaddy probably has their own custom, hacked up version of the cpanel template. I don't like GoDaddy, and know of many people who don't like them either. You may be able to change the cpanel theme to x3, which is the default one. - Here is a screenshot of what the real cpanel looks like: http://www.cpaneldemos.com/images/screenshot_x31.gif – Wade May 06 '15 at 07:49
  • 1
    Regardless, they are not emailing servers, they are web servers for hosting your websites. Sending emails that hit the inbox is not their problem or the service they are providing. They might help you get SPF and DKIM setup, but after that they will tell you too bad. I have used tons of hosts with dedicated servers, VPSs, it's all the same. They are not emailing servers. If you need to send emails, reliably, then get an MX provider. You can but MX servers for high volume, or just an SMTP account, or use SendGrid or Mailgun. – Wade May 06 '15 at 07:53
  • 1
    It seems I was down voted by someone who doesn't really know what they are talking about. I use to send to over 100k contacts about 2-4 times a month from my dedicated server. Inbox rates are always lower mailing from your own web server. If you follow everything I said, and still are having issues, then you may need to try a different server. If you are sending high volumes of emails, then you shouldn't be mailing off your web server anyways. - My answer is the most informative and thorough one posted here so far. Dropping PHPMailer for mail() is like going from a Ferrari to a horse and buggy – Wade May 07 '15 at 06:56
  • Very thorough answer. Updated to counteract a senseless downvote – Morgan Green May 07 '15 at 20:45
  • @MorganGreen Thanks. Unfortunately, this type of question can lead to a ripple affect. He may never clear up the spam problem if he doesn't follow my answer. He can do ALL of what I said and still land into the spam folder. It is subjective on the receiving end. Yahoo or Gmail may just not like his server even if it isn't blacklisted and everything is done properly. Sometimes it just takes moving to another server. If it was me, I wouldn't bother and just use SendGrid. I just expect this to be another question that never has an answer selected... – Wade May 08 '15 at 04:06
-1

Can you show the content of your mail? Are you trying to send HTML or text mail? Maybe the provider is on blacklist, check the sending IP address (see mail header) at a blacklist check.

I had these spam problems with Google Mail only when sending with mail() - after the change to SMTP all works properly.

Richard
  • 2,840
  • 3
  • 25
  • 37