[codeigniter] Send email by using codeigniter library via localhost

public function sendemail(){
  $config = Array( 
  'protocol' => 'smtp', 
  'smtp_host' => 'ssl://smtp.googlemail.com', 
  'smtp_port' => 465, 
  'smtp_user' => '[email protected]', 
  'smtp_pass' => 'password', ); 

  $this->load->library('email', $config); 
  $this->email->set_newline("\r\n");
  $this->email->from('[email protected]', 'Name');
  $this->email->to('[email protected]');
  $this->email->subject(' My mail through codeigniter from localhost '); 
  $this->email->message('Hello World…');
  if (!$this->email->send()) {
    show_error($this->email->print_debugger()); }
  else {
    echo 'Your e-mail has been sent!';
  }
}   

I get an error when I use codeigniter to send the email:

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

and

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

What am I doing wrong?

This question is related to codeigniter email

The answer is


I had the same problem and I solved by using the postcast server. You can install it locally and use it.


$insert = $this->db->insert('email_notification', $data);
                $this->session->set_flashdata("msg", "<div class='alert alert-success'> Cafe has been added Successfully.</div>");

                //require ("plugins/mailer/PHPMailerAutoload.php");
                $mail = new PHPMailer;
                $mail->SMTPOptions = array(
                    'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true,
                ),
                );

                $message="
                     Your Account Has beed created successfully by Admin:
                    Username: ".$this->input->post('username')." <br><br>
                    Email: ".$this->input->post('sender_email')." <br><br>
                    Regargs<br>
                    <div class='background-color:#666;color:#fff;padding:6px;
                    text-align:center;'>
                         Bookly Admin.
                    </div>
                ";
                $mail->isSMTP(); // Set mailer to use SMTP
                $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
                $mail->SMTPAuth = true; 
                $subject = "Hello  ".$this->input->post('username');
                $mail->SMTDebug=2;
                $email = $this->input->post('sender_email'); //this email is user email
                $from_label = "Account Creation";
                $mail->Username = 'your email'; // SMTP username
                $mail->Password = 'password'; // SMTP password
                $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
                $mail->Port = 465;
                $mail->setFrom($from_label);
                $mail->addAddress($email, 'Bookly Admin');
                $mail->isHTML(true);
                $mail->Subject = $subject;
                $mail->Body = $message;
                $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
             if($mail->send()){

                  }