Cyberomin
Cyberomin

Reputation: 523

PHP mails always ends up in the spam folder

i have an issue here, my mails sent from my PHP script never gets delivered to my inbox, but spam instead. Any help on how to get it to the inbox. Thank y'all Here is my code sample

public function sendMail($name,$email,$message)
{
    $this->validateInput($name,"Empty Name","Invalid Name");
    $this->validateEmail($email,"Empty Email","Invalid Email");
    $this->validateLargeData($message,"Invalid Message","Empty Message","Message Too Short");
    if (empty($this->errors))
    {
        $fromName = $name;
        $fromEmail = $email;
        $from   = "From: $fromName <$fromEmail>\r\n";
        $reply = "Reply-To: $fromEmail\r\n";    
        $mime = "MIME-Version: 1.0\r\n";
        $content = "Content-Type: text/html; charset=ISO-8859-1\r\n";
        $headers = $from.$reply.$mime.$content;
        if (mail("[email protected]","Contact",$message,$headers))
        {
            echo "<div class='success1'>Thank you $name, we will get back you immediately.</div>";
        }

    }
    else
    {
        echo "<div class=''>";
        echo "</div>";
    }
}

edit Pls here is the header information i am using

$fromName = $name;
$fromEmail = $email;
$from   = "From: $fromName <$fromEmail>\r\n";
$reply = "Reply-To: $fromEmail\r\n";    
$mime = "MIME-Version: 1.0\r\n";
$content = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$mailer = "X-Mailer: PHP's mail() Function";
$headers = $from.$reply.$mime.$content.$mailer;

@cyberomin

Upvotes: 1

Views: 1980

Answers (2)

Wouter Dorgelo
Wouter Dorgelo

Reputation: 11978

Make sure your headers are complete:

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "From: aaa.bbb <[email protected]>\n";
$headers .= "X-Mailer: PHP's mail() Function\n";
mail("[email protected]", "subject","message",$headers); 

And if you are on shared hosting, it might be that there's a blacklisted spammer on your ip.

The best suggestion I can probably make is to try a different way of sending your emails. For example phpmailer or Swift Mailer.

Upvotes: 2

thejh
thejh

Reputation: 45568

We can only give you an exact answer if you give us the headers of the mail in your spam folder, but I think that it's because you are sending from a computer that has an IP in an IP range that contains consumer internet connections. Email from consumer computers usually is spam.

Upvotes: 0

Related Questions