Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to send smtp mail in codeigniter?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 441
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss how to send SMTP mail in codeigniter?

    In a web applications sending email is a very common feature.This is used for sending Emails messages,notifications and newsletters.
    If you are making a web application in codeigniter framework then you need to create a smtp mail for sending mail to reciepant,because Email is the important functionality in web applications.

    You can use send email when any user has completed his registration form or any user forgot his password then you can send new password on his personal email just after fill some requirment field like his email account.

    In CodeIgniter sending Email  is very Simple process just configuration of Email can be done in one of the Controller file of our Application.

    You can see in below example there is a forgot_password function in which we are sending a smtp mail to user with 9 random number on his emailid and also update that password in database.

    You have to also set a email account and password for sending email to user.Because without sender a receiver can not receive a email.

    /* forgpt password function */ 
        public function forgot_password($username)
          $result= $this->db->get();
            //create a random password of 9 digits
            $pass=rand (99999999 ,999999999);
            //convert in to MD5 password 
            $data1['password'] = MD5($pass);
            $id =$result->result_array[0]['id'];
            $email =$result->result_array[0]['email'];
            //here update tghe password in database
            $this->db->where('id', $id);
            $this->db->update('user_registration', $data1);
             /*send mail function*/
              $mail_message='Dear User your new password is '.$pass.',<br><br><br>';
              $mail_message.='Thanks & Regards<br>Admin';
              $config['protocol'] = "smtp";
              $config['smtp_host'] = "";
              $config['smtp_port'] = "25";
              $config['smtp_user'] = "";
              $config['smtp_pass'] = "123456";
              $config['wordwrap'] = TRUE;
              $config['mailtype'] = 'html';
              $this->email->subject('Password changed and email sent.');
             /*end send mail function*/
              //set massege after send mail into user
              $data['message']="message sent successfullt";
              return $data;
              $data['message']="message not sent";
              return $data;

    I hope this blog is helpful for sending an email in Codeigniter.



 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: