Send email by using codeigniter library via localhost Send email by using codeigniter library via localhost codeigniter codeigniter

Send email by using codeigniter library via localhost


Please check my working code.

function sendMail(){    $config = Array(  'protocol' => 'smtp',  'smtp_host' => 'ssl://smtp.googlemail.com',  'smtp_port' => 465,  'smtp_user' => 'xxx@gmail.com', // change it to yours  'smtp_pass' => 'xxx', // change it to yours  'mailtype' => 'html',  'charset' => 'iso-8859-1',  'wordwrap' => TRUE);        $message = '';        $this->load->library('email', $config);      $this->email->set_newline("\r\n");      $this->email->from('xxx@gmail.com'); // change it to yours      $this->email->to('xxx@gmail.com');// change it to yours      $this->email->subject('Resume from JobsBuddy for your Job posting');      $this->email->message($message);      if($this->email->send())     {      echo 'Email sent.';     }     else    {     show_error($this->email->print_debugger());    }}


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()){                  }