PHP PEAR Mail Marked As Spam?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
djlex1928
Forum Commoner
Posts: 31
Joined: Sun Sep 19, 2010 3:23 pm

PHP PEAR Mail Marked As Spam?

Post by djlex1928 »

I cannot understand the problem here:

I've marked all my info as "***" this is correct in the original code.

Code: Select all

<?php
 require_once "Mail.php";
 
 $from = "***";
 $to = "***";
 $subject = "***";
 $body = "***";
 
 $host = "***";
 $username = "***";
 $password = "***";
 $replyto = '***';
 
 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject,
   'Reply-To' => $replyto,
   'MIME-Version' => '1.0',
   'Content-type' => 'text/html; charset=iso-8859-1');
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => false,
     'username' => $username,
     'password' => $password));
 
 $mail = $smtp->send($to, $headers, $body);
 
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }
 ?>
I cannot understand why this is happening, mail sent using this method is moved to the Junk folder in Outlook, and I beleive in Hotmail too. Gmail works just fine, any others I'm not sure.

Something that might affect this is that it's being run from a local server at my place of work. All I want to do is confirm orders placed on our website, but it seems pointless if the emails are being marked as spam? Is there any way I can stop this happening?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP PEAR Mail Marked As Spam?

Post by Jonah Bron »

Spam filters often trigger when an email's From and Reply-To headers don't match the actual server it came from.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP PEAR Mail Marked As Spam?

Post by califdon »

In any case, it has nothing to do with your PHP code. Your question pertains to whatever the spam filter rules are in each email client.
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: PHP PEAR Mail Marked As Spam?

Post by internet-solution »

Spam filter rules will also be affected by "reputation" of your mail / webserver. If you are on a shared server and some users send out spams from it, the server will end up in spam blacklists. A workaround might be to use external SMTP mail servers (your ISP / Gmail) for sending out mails.
djlex1928
Forum Commoner
Posts: 31
Joined: Sun Sep 19, 2010 3:23 pm

Re: PHP PEAR Mail Marked As Spam?

Post by djlex1928 »

I fixed it adding a couple things to the the headers, works perfect now.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP PEAR Mail Marked As Spam?

Post by Jonah Bron »

For the sake of other people that experience this problem in the future, what did you change?
Post Reply