Views :- 2607

How to send email using php codeigniter

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');

// 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);		
	}

}
?>

php-codeigniter 

Current Donation 10 $

You also Like this Tutorials

HTML Comment Box is loading comments...

Other Posts

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

| Rss Feed | Contact Us | Find us on Google+