0

PHP code:

    $from  = 'shahrushabh1996@gmail.com';
    $config = array(
            'protocol'=>'smtp',
            'smtp_host'=>'ssl://smtp.googlemail.com',
            'smtp_port'=>'465',
            'smtp_user'=>'shahrushabh1996@gmail.com',
            'smtp_pass'=>'********',
            'mailtype'=>'html',
            'charset'=>'UTF-8'
        );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->to($personemail);
    $this->email->from($from);
    $this->email->subject('it is a demo email by Rushabh Shah');
    $this->email->message('demo message');
    if(!$this->email->send()){
        show_error($this->email->print_debugger());
    }
    else{
        echo 'email is sent';
    }

Error:

Unable to send email using PHP mail().

Please help me how to resolve following error? this method is working fine in different controller but not working in this controller how to resolve it? please help me.

Shah Rushabh
  • 147
  • 4
  • 16
  • What library is the `$this->load->library('email', $config);` loading? It looks like it is just using the base mail function provided by PHP. Since the error that you're getting is pretty useless as far as describing what went wrong this thread may help get a more detailed error message. http://stackoverflow.com/a/20203870/1804656 – kyle Nov 04 '16 at 16:27
  • Any special reason your using windows line endings? I've found some mail severs are very sensitive to mixing the line endings. – ArtisticPhoenix Nov 04 '16 at 16:28

1 Answers1

0

Try this

$config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => '465',
        'smtp_user' => 'xxxx@gmail.com',
        'smtp_pass' => 'xxxxx',
        'mailtype'  => 'html',
        'starttls'  => true,
        'newline'   => "\r\n"
    );

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

    $this->email->from('someuser@gmail.com', 'Test');
    $this->email->to('test@test.com');
    $this->email->subject('Test Email');
    $this->email->message('Hello World');

    $this->email->send();
Muhammad Usman
  • 1,403
  • 13
  • 24