Send E-mail using codeIgniter.
Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file. CodeIgniter's Email Class supports the following features:
- Multiple Protocols:
- Mail, Sendmail, and SMTP Multiple recipients
- CC and BCCs
- HTML or Plaintext email
- Attachments
- Word wrapping
- Priorities
- BCC Batch Mode, enabling large email lists to be broken into small BCC batches.
- Email Debugging tools
So let's start with controller.
Controller Name : email.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Email extends CI_Controller { function __construct(){ parent::__construct(); //load the library $this->load->library('email'); } function send_mail(){ $this->email->from('mohitj475@gmail.com', 'Mohit'); $this->email->to('mohitj475@gmail.com'); $this->email->subject('mail send demonstration'); $this->email->message('this is testing'); $this->email->send(); echo $this->email->print_debugger(); } }
If you run above code then you will get output like this
Explanation : In controller's constructor method first we load email library so we can use library function.After that we created send_mail function in to we use library function.
Email Function Reference
$this->email->from()
Sets the email address and name of the person sending the email:
$this->email->from('mohitj475@gmail.com', 'Mohit');$this->email->to()
Sets the email address(s) of the recipient(s). Can be a single email, a comma-delimited list or an array:
$this->email->to('mohitj475@gmail.com');
$this->email->to('one@example.com, two@example.com, three@example.com');
$list = array('one@example.com', 'two@example.com', 'three@example.com'); $this->email->to($list);$this->email->subject()
Sets the email subject:
$this->email->subject('mail send demonstration');$this->email->message()
Sets the email message body:
$this->email->message('this is testing');$this->email->send()
The Email sending function. Returns boolean TRUE or FALSE based on success or failure, enabling it to be used conditionally:
if ( ! $this->email->send()) { // Generate error }For function more Visit this link
0 comments:
Post a Comment