1

I am using codeigniter mail function. Its sends mail perfectly. But all the time mail going to the spam folder. How can I overcome this.

Function

function msg_now(){ $this->load->library('email'); $this->load->library('parser'); $config['protocol'] = 'sendmail'; $config['wordwrap'] = TRUE; $config['mailtype'] = 'html'; $this->email->initialize($config); $email_id='[email protected]'; $name=$this->'test'; $this->email->from('[email protected]'); $this->email->to($email_id); $this->email->subject('Test subject'); $this->email->message("<p>Lorem ipsum dummy content</p>"); $this->email->send(); } 
4
  • 1
    Try to avoid subject name with test try with other subject name. Commented Feb 16, 2016 at 6:01
  • 3
    There are lots of reasons an email service will throw emails from a random server into the spam folder (stackoverflow.com/questions/250234/…) Commented Feb 16, 2016 at 6:03
  • 1
    [email protected] is this real gmail id? if not try to replace with some real registered gmail id and check Commented Feb 16, 2016 at 6:05
  • 1
    am using a valid email address for sending mail, this is my sample email id. Commented Feb 16, 2016 at 6:10

2 Answers 2

3
 $this->load->library('parser'); $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => 'google email id', 'smtp_pass' => 'password', 'mailtype' => 'html', 'charset' => 'iso-8859-1' ); $this->load->library('email', $config); $this->email->set_newline("\r\n"); $this->email->from('google email id','Title'); // change it to yours $this->email->to(your send email id);// change it to yours $this->email->subject('you subject'); $this->email->message('your message'); if($this->email->send()) { return true; } else { show_error($this->email->print_debugger()); } 
Sign up to request clarification or add additional context in comments.

3 Comments

$this->load->library('parser'); is the key to avoid spam. Please note it...
how will the issue be resolved by just loading a library?
I am not entirely sure why, but after adding a parser, it worked. Then, even if I got rid of the parser, the emails weren't going to spam. I don't understand this, but I am not going to question it.
1

There are many reasons for mail to go in spam, but easy solution for it is to set the headers of the mail before sending and giving it priority.

Here's how to do that in CodeIgniter. The function is set_header():

$this->email->set_header($header, $value); 

also check this link for reference.

It has always worked for me.

2 Comments

Codeigniter doc's now located here. codeigniter.com/docs
thanks, actually I was using previous version docs

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.