Bj bhatta
Bj bhatta

Reputation: 11

sending email in codeigniter

hey anyone can help me to get out of this problem, I am getting following error A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:587 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?)

Filename: libraries/Email.php

Line Number: 1689

A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846

And I have the following code in my emailer class

Class MailSender extends CI_Model{

    function __construct(){
        parent::__construct();
    }

    public function sendMail(){
        $config=array(
                'protocol'=>'smtp',
                'smtp_host'=> 'ssl://smtp.googlemail.com',
                'smtp_port' => 587,
                'smtp_user' => '[email protected]',
                'smtp_pass' => 'signature08'
        );

        $this->load->library('email',$config);
        $this->email->set_newline("\r\n");

        $this->email->from("[email protected]");
        $this->email->to("[email protected]");
        $this->email->subject("this is a sample mail");
        $this->email->message("this is a sample message please check this");

        if($this->email->send()){
            //$data['message']="Email sent successfully";
            return true;

        }else{
            //$data['message']="Couldnt sent the email, please provide me valid email address";
            return false;
        }

    }
}

Upvotes: 0

Views: 1526

Answers (2)

N1ck
N1ck

Reputation: 2001

The code works fine, please ensure you have the openssl extension loaded.

http://www.devcha.com/2010/01/php-fsockopen-unable-to-connect-ssl.html

Upvotes: 1

Ahmad
Ahmad

Reputation: 1931

Do you have openssl extension actually loaded? Use a phpinfo();in a .php file to see if the openssl extension is loaded or Have you done any modifications to php.ini that caused this?

Upvotes: 0

Related Questions