0

my model:

<?php
class email_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

        public function sendEmail($from = null, $to = null, $subject = null, $message = null){

            $this->load->library('email');

            $config['protocol'] = 'sendmail';
            $config['mailpath'] = '/usr/sbin/sendmail';
            $config['charset'] = 'utf-8';
            $config['mailtype'] = 'html';
            $config['wordwrap'] = TRUE;

            $this->email->initialize($config);

            $this->email->from('email@mydomain.com', 'Website name');

            $this->email->to($to);

            $this->email->subject($subject);

            $this->email->message($message);

            $this->email->send();

        }
}

my domain is hosted on GoDaddy also i have created an email there and redirect it to my gmail email...

why does my email is sent to spam folder and not on Inbox?

EDIT: my email content is basically an invitation welcome

Hello $email

$website has invited you to join the website

to join visit the following link

$link_goes_here

Thanks, the team
stergosz
  • 5,754
  • 13
  • 62
  • 133
  • 1
    Depends on what you are sending and has little to do with the code you use to send it. Gmail's spam filter is very good, and if it considers your email spam I am curious what its contents are. – Jeshurun May 21 '12 at 09:08
  • 1
    Consider having a look at [this solution](http://stackoverflow.com/questions/1555145/sending-email-with-gmail-smtp-with-codeigniter-email-library). – Robin Castlin May 21 '12 at 09:10
  • Agreed with the above 2 comments, you may also wish to look at your previous questions and select answers where appropriate – lethalMango May 21 '12 at 09:12
  • @jeshurun i have updated my question with the content of the email – stergosz May 21 '12 at 09:12
  • It could be a number of things... The subject, content, sender or even the IP address you are sending from. a) Subject, content and sender: try putting the content of your email etc through tools such as http://www.americaint.com/spam-filter-messagetest/spam-checker.html b) go to http://www.mxtoolbox.com/blacklists.aspx and put in the IP address of your server. – Gavin May 21 '12 at 09:12
  • @gavin, first link is clear but how the hell am i on 2 blacklists when i sent non spam mails? – stergosz May 21 '12 at 09:16
  • It all depends on the way your server is setup. If you have a dedicated server, it could depend on the ISP that your server uses, if your on a shared server, it's most likely because the range of IP's they own have been abused by other users and have been blacklisted. – Gavin May 21 '12 at 09:19
  • i am on a VPS... do i have to structure my email content better to avoid the spam because its plain text with some colors? – stergosz May 21 '12 at 09:30
  • Unfortunately, if the IP of your server is blacklisted, there is very little you can do, other than appeal to the companies who have blacklisted you and advise them you are not sending spam emails. I found that even if you are on a single, dedicated IP, the ISP it self could be blocked due to a vast number of spam emails being sent from IP's in it's range. – Gavin May 21 '12 at 09:54
  • thing is that it works if i use gmail smtp but fails with the codeigniter method... i can even send 4 words with gmail and it wont be sent to spam folder – stergosz May 21 '12 at 10:16
  • Unless you change the CodeIgniter email configuration to use an external SMTP such as GMail, any emails you send, will be sent via the VPS, thus via the blacklisted IP addresses, resulting in them ending up in spam. – Gavin May 21 '12 at 10:27
  • i ended up using sendgrid... thanks for the help all! – stergosz May 21 '12 at 11:01
  • See this: http://stackoverflow.com/questions/10288590/codeigniter-email-weirdness/10290530#10290530 – NDBoost May 21 '12 at 15:48

2 Answers2

-1

If you are using HTML to display your mail, you have to ensure that your mail is sent with valid html. You can validate your mail here: http://validator.w3.org/

f4der
  • 711
  • 4
  • 18
-1

if it, a contact us form.. maybe you can try to send an email through Amazon SES, so google / yahoo didn't think it as a spam

mochadwi
  • 1,190
  • 9
  • 32
  • 87