Sent Email Using Codeigniter
Sent Email Using Codeigniter
Published Mar 10,2019 by Kailash Singh
1 Comment 2087 Views
In this tutorial, we are going to learn about how to sent email using codeigniter.
Nowadays, pretty much every PHP structure bolsters a very much created email the executives library. CodeIgniter is the same as it has an incredible email sending class that guarantees that CodeIgniter undertakings could send messages without trouble.
Sending email in CodeIgniter is much easier. You also configure the preferences regarding email in CodeIgniter. CodeIgniter provides following features for sending emails −
- Multiple Protocols − Mail, Sendmail, and SMTP
- Multiple recipients
- CC and BCCs
- HTML or Plaintext email
- Attachments
- Word wrapping
- BCC Batch Mode, enabling large email lists to be broken into small BCC batches.
- Email Debugging tools
Step 1 :- Create Controller in Controller Folder (Email_sent.php)
<?php
class Email_sent extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
}
public function index()
{
$this->load->view('email_form');
}
}
Step 2 :- Create Html View in View Folder (email_form.php)
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>Sent Mail in Codeigniter</title>
</head>
<body>
<?php
echo $this->session->flashdata('mail_sent');
?>
<fprm action="<?php echo base_url(); ?>mail_sent" method="post">
<input type = "email" name = "email" required />
<input type = "submit" value = "SEND MAIL">
</form>
</body>
</html>
Step 3 :- Create sent mail function in Controller (Email_sent.php)
public function send_mail() {
$from_email = "[email protected]";//your mail
$to_email = $this->input->post('email');
$this->email->from($from_email, 'Identification');
$this->email->to($to_email);
$this->email->subject('Demo Email by Codeigniter');
$this->email->message('This email send by codeigniter only for testing');
//Send mail
if($this->email->send()){
$this->session->set_flashdata("mail_sent","Congratulation! Mail Sent Successfully.");
}
else{
$this->session->set_flashdata("mail_sent","Some errors....");
}
return redirect('Email_sent')
}
Hope this will help our developers.
Elevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date