0

I have config email in codeigniter

    'protocol' => 'smtp',
                    'smtp_host' => 'ssl://smtp.gmail.com',
                    'smtp_port' => '465',
                    'smtp_user' => '-----',
                    'smtp_pass' => '-----',
                    'mailtype' => 'html',
                    'charset' => 'utf-8'

$this->load->library('email', $this->session->userdata('config'));
            $this->email->from('[email protected]', 'Rtlx Team');
            $this->email->to($email);
            $message = "Dear ";
            $this->email->subject('Rtlx Team - Account Verification');
            $this->email->message($message);
            $this->email->send();
            $this->email->clear();

But it shows following errors:

Message: mail() [function.mail]: Failed to connect to mail server at "localhost" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

Message: mail() expects parameter 1 to be string, array given

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

1
  • im sure i had a similar problem, it was because the email library expects the smtp username and password to be sent, to get around this issue you may need to extend the email library so it doesn't check the connection. It does this because the SMTP connection fails so it falls back on the mail function. Commented Sep 24, 2013 at 13:51

2 Answers 2

0

Go through the link http://ellislab.com/codeigniter/user-guide/libraries/email.html and your smtp settings...

Sign up to request clarification or add additional context in comments.

Comments

0

You are loading email library incorrectly as $this->load->library('email',$this->session->userdata('config'));.

so load it as $this->load->library('email'); and initialize it as $this->email->initialize($this->session->userdata('config'));

in below example i have taken $config array but you can take your own configuration in session also as in question you have used. but set all option as i have set in $config you can set it in session's variable.

full code below:

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => '[email protected]', // change it to yours
    'smtp_pass' => 'yourpassword', // change it to yours
    'mailtype' => 'html',// it can be text or html
    'wordwrap' => TRUE,
    'newline' => "\r\n",
    'charset' => 'utf-8',
    );
    $this->load->library('email');
    $this->email->initialize($config);
    $this->email->from('[email protected]',"Rtlx Team");
    $this->email->to('[email protected]');
    $this->email->subject('Subject');
    $this->email->message('Sample message');
    if (!$this->email->send()) 
    {
        show_error($this->email->print_debugger()); 
    }
    else 
    {
        echo 'Your e-mail has been sent!';
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.