2

i tried to send the mail using codeigniter framework.but it will raise the error "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

From: "prakash t" <tprakashkce@gmail.com>
Return-Path: <tprakashkce@gmail.com>
Reply-To: "tprakashkce@gmail.com" <tprakashkce@gmail.com>
X-Sender: tprakashkce@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5aed4eed40506@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
=?UTF-8?Q?Test=20Mail?=
hai this my test mail

" but no use

here is mycode:

public function sendMail(){

    $config = Array(
        'protocol' => 'mail',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 587,
        'smtp_user' => 'example@gmail.com',
        'smtp_pass' => '*********'
    );

I know it's duplicate question.but i didn't find solution for my question

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

    $this->email->set_newline("\r\n");
    $this->email->from('tprakashkce@gmail.com','prakash t');
    $this->email->to('tprakash11121996@gmail.com');
    $this->email->subject('Test Mail');
    $this->email->message('hai this my test mail');

    if($this->email->send()){
        echo "mail send succesfully";
    }
    else{
        show_error($this->email->print_debugger());
    }

}
PrakashT
  • 883
  • 1
  • 7
  • 17

2 Answers2

5

You are done all correct but you have issue on initialize the mail

Just change this

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

to

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

You can check in details here.

Bibhudatta Sahoo
  • 4,808
  • 2
  • 27
  • 51
0

I got same error but my problem was with Apache configuration. Ensure that Apache can send emails.

To check your current sendmail status: sestatus -b | grep httpd_can_sendmail

Change it to this if it is off: sudo setsebool -P httpd_can_sendmail on