How to send email using php codeigniter

 Posted On  | Yashwant Chavan | Views :- 8448

Codeigniter supported inbuilt Email library class which simplify the email sending process. To send email we need to do some configuration , need to load email library.codeigniter supports Multiple Protocols, Mail, Sendmail, and SMTP, Multiple recipients, CC and BCCs,HTML or Plain text email, Attachments ,Word wrapping and many more

Setting Email Preferences

Lets start with Codeigniter email program configuration. First load the built in email library in controller constructor.

$this->load->library('email');

Configure the smtp details like domain name, port, username and password

// Email configuration
		$config = Array(
			  'protocol' => 'smtp',
			  'smtp_host' => 'smtp.yourdomainname.com.',
			  'smtp_port' => 465,
			  'smtp_user' => 'admin@yourdomainname.com', // change it to yours
			  'smtp_pass' => '******', // change it to yours
			  'mailtype' => 'html',
			  'charset' => 'iso-8859-1',
			  'wordwrap' => TRUE
		);	

Refer the complete Codeignitor email sending program. In this program you just need to configure your domain smtp details

load->library('email'); // load the library
	}
	
	function index(){
		$this->sendEmail(); 	
	}
	
	public function sendEmail(){			
		// Email configuration
		$config = Array(
			  'protocol' => 'smtp',
			  'smtp_host' => 'smtp.yourdomainname.com.',
			  'smtp_port' => 465,
			  'smtp_user' => 'admin@yourdomainname.com', // change it to yours
			  'smtp_pass' => '******', // change it to yours
			  'mailtype' => 'html',
			  'charset' => 'iso-8859-1',
			  'wordwrap' => TRUE
		);	
	
		$this->load->library('email', $config);
		$this->email->from('admin@yourdomainname.com', "Admin Team");
		$this->email->to("test@domainname.com");
		$this->email->cc("testcc@domainname.com");
		$this->email->subject("This is test subject line");
		$this->email->message("Mail sent test message...");
			
		$data['message'] = "Sorry Unable to send email...";	
		if($this->email->send()){					
			$data['message'] = "Mail sent...";			
		}	
		 				
		// forward to index page
		$this->load->view('index', $data);		
	}

}
?>

Tags Php Codeigniter 

HTML Comment Box is loading comments...

Hi I am Yashwant Chavan founder of www.technicalkeeda.com, Purpose of this website to share the programming knowledge in the form post , blogs and articles.

Latest Updates

Stay updated with latest post, articles and technical discussions.

Most Popular Articles



© technicalkeeda.com 2014