-2

I'm making a simple PHP mail sender to send an image to multiple addresses at a time. Don't know why, but the emails keep on arriving at the SPAM folder, no matter what email manager I send them...

Here's how I call the PHP mail sender file:

$.ajax({ url: 'mail_sender.php?receiver=' + receiver + '&=lang' + lang,

    success: function (response)
    {
        console.log('Mails ' + response);
    }
});

And this is my PHP file structure:

<?php

// Reciever
$_to           = $_GET["receiver"];
$_lang      = $_GET["lang"];

// subject
$subject        = 'My Subject';

// sender
$sender         = "sender@sender.es";

// message
$message        = '
                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                <head>
                <META name="generator" content="HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org">
                <TITLE></TITLE>
                <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
                </head>
                <body>
                  <img src='."https://www.mysite.es/demo/img/emails/imagen_".$_lang.".jpg".' />
                </body>
                </html>
';

// To send HTML mail, the Content-type header must be set
$headers  = "Reply-To: <sender@sender.es> \r\n";
$headers .= "Return-Path: <sender@sender.es>" . "\r\n";
$headers .= "From: <sender@sender.es>" . "\r\n"; 
$headers .= "Organization: My organization" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
$headers .= "X-Priority: 3" . "\r\n";
$headers .= "X-Mailer: PHP/". phpversion();

// Mail it
$ret = mail($_to, $subject, $message, $headers);

if ( $ret == '' || $ret )
{
    echo $ret;
}else{
    echo $ret;
}

?>

Can anyone give some clues?

Thank you very much!

  • 1
    change your hosting ip. This is not for sure a script problem, the script is good while your email arrive into your email account, even if it does in spam folder. You can use PHP Mailer https://code.google.com/a/apache-extras.org/p/phpmailer/ if you want to be sure your code is fine – Mihai Matei Dec 16 '12 at 19:26
  • large number of possibilities, answered here multiple times –  Dec 16 '12 at 19:26
  • 1
    I strongly recommend you to use an authentication. This framework (http://swiftmailer.org/) is absolutely amazing and very simple for usage. It resolves you problem for 99%. – kpotehin Dec 16 '12 at 19:27
  • 1
    -1, duplicate of about 2/3s of the Related sidebar. `mail()` sucks, use a third-party library to speak to a known-good SMTP server. – Charles Dec 16 '12 at 19:30
  • make sure the domain you use in the From header actually is the domain you're sending the email from. This was the cause when I was working on it before – kennypu Dec 16 '12 at 19:33
  • @Charles, did a previous search, of course. Just thought that might be something wrong with my code. – Albert Espinosa Aguado Dec 16 '12 at 19:44
  • Thanks @kpotehin, that solved everything! – Albert Espinosa Aguado Dec 17 '12 at 00:23

4 Answers4

2

Try sending a plain text email instead of HTML (if that suits your needs). In my experience the HTML often triggers spam filters but f you really need to use HTML try to look at some of the email templates that mailchimp uses.

https://github.com/mailchimp/Email-Blueprints

Slavenko Miljic
  • 3,836
  • 2
  • 23
  • 36
1

There doesn't seem to be anything technically wrong with your code, and there could be many reasons your emails are being rejected by spam filters, but my guess would be that your email content is just an image. This is a strong indicator to spam filters. Try to design your emails using text, and only use images to support your information.

Gareth Cornish
  • 4,357
  • 1
  • 19
  • 22
0

The matter should be the IP of your server. if a provider recieves much mails from the same IP it is considered as spam, no matter what comes.

Theolodis
  • 4,977
  • 3
  • 34
  • 53
  • so gmail ip's, that sends a few million emails is always considered spam then ? –  Dec 16 '12 at 19:27
  • I don't think he's sending from a google server dude. – Theolodis Dec 16 '12 at 19:28
  • What are you talking about then? LOL there are mailservers that know each other (google/yahoo/etc.) and normal servers. as every server is able to send emails, the big providers simply categorize every little server sending them mails. – Theolodis Dec 16 '12 at 19:33
  • the point is your assertion that a mail server may block email from another mail server based on volume is simply wrong. –  Dec 16 '12 at 19:35
  • nope it isn't. It is just true that not every mailserver is concerned. not those you don't usually have access to to upload and execute scripts. ok, that point goes to you. – Theolodis Dec 16 '12 at 19:40
0

You should consider testing your emails through spamassassin which will give your email a spam score based on a given set of rules.

Many email providers use these kind of tools.

Edit: http://wiki.apache.org/spamassassin/StartUsing might be a good place to start.