sending email using codeigniter email class

Viewed 1484

i have an error by trying to send an email using codeigniter email Class.

I have an error of : Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

How can i test to send email in codeigniter?. I am also using localhost. Is this problem only occurs when i use localhost?

Here is my code:

public function emailme() {
        $this->load->library('email');
        $message = $this->input->post('email_msg');
        $this->email->from('iamjohnx3303@yahoo.com', 'John');
        $this->email->to('iamjohnx3302@gmail.com');
        $this->email->subject('Email Test');
        $this->email->message($message);
        $this->email->send();
    }
2 Answers

Use this before your send mail script

// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");

// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");

// Please specify the return address to use
ini_set('sendmail_from', 'ValidEmailAccount@YourDomain.com');
Related