Codeigniter Email Helper


Codeigniter Email Helper – Codeigniter email helper provides various functions that are used to send the emails. $this->load->helper(’email’); is used to load the helper. This contains the functions – valid_email and send_email. Here in this tutorial we are going to explain how to send an email in codeigniter.


Codeigniter Email Helper Example

Now we will see how to load email helper in codeigniter and then use its function-

Load Email Helper

How To Load Email Helper in Codeingniter Example:

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

Functions:-

Following functions are available in email helper.

  • 1. Validate Email
  • 2. Send Email

1. Validate_Email

Syntax of Validate_email function is

Syntax of validate_email function is:-

(valid_email($email))		

    Parameters:

  • $email (string) : E-mail address
  • Returns : TRUE if a valid email is supplied, FALSE otherwise
  • Return type : bool

2. Send_Email

Syntax of Send_email function is

Syntax of Send_email function is:-

send_email($email,$subject,$message)		

    Parameters:

  • $email (string) : E-mail address
  • $subject (string) : Mail subject
  • $message (string) :Message body

EXAMPLE 1

Here is simple example to validate email.

| Validate Email in Codeigniter Example:-

public function ValidateEmail()
	{
		$this->load->helper('email');
		//$this->load->view('email_view');
		$email = 'sonukr321@gmail.com';
		
		if (valid_email($email))
		{
				echo 'email is valid';
		}
		else
		{
				echo 'email is not valid';
		}
	}

EXAMPLE 2

Here is simple example to send email.

Send Email in Codeigniter Example:-

public function sendemail()
	{
		$this->load->helper('email');
		//$this->load->view('email_view');
		$email = 'sonukr321@gmail.com';
		$subject = 'hello';
		$message = 'hi';
		if (send_email($email,$subject,$message))
		{
				echo 'sent succesfully';
		}
		else
		{
				echo 'unable to send';
		}
	}

Advertisements

Add Comment

📖 Read More