CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New

How to Send message in CodeIgniter framework


In this example we will discuss about how to send message in CodeIgniter framework PHP.

We use two file for send message in CodeIgniter framework PHP.

  1. Message_send.php (CodeIgniter\application\controllers\Message_send.php )
  2. hello_world.php (CodeIgniter\application\views\message.php)

Message_send.php

<?php  
class Message_send extends CI_Controller 
{
	public function __construct()
	{
	/*call CodeIgniter's default Constructor*/
	parent::__construct();
           }
public function message()
	{
		/*load registration view form*/
		$this->load->view('message');
	
		/*Check submit button */
		if($this->input->post('save'))
		{
		$phone=$this->input->post(‘phone’);
$user_message=$this->input->post(‘message’);
	    /*Your authentication key*/
$authKey = "3456655757gEr5a019b18";
/*Multiple mobiles numbers separated by comma*/
$mobileNumber = $phone;
/*Sender ID,While using route4 sender id should be 6 characters long.*/
$senderId = "ABCDEF";
/*Your message to send, Add URL encoding here.*/
$message = $user_message;
/*Define route */
$route = "route=4";
/*Prepare you post parameters*/
$postData = array(
'authkey' => $authKey,
'mobiles' => $mobileNumber,
'message' => $message,
'sender' => $senderId,
'route' => $route
);
/*API URL*/
$url="https://control.msg91.com/api/sendhttp.php";
/* init the resource */
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
/*,CURLOPT_FOLLOWLOCATION => true*/
));
/*Ignore SSL certificate verification*/
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
/*get response*/
$output = curl_exec($ch);
/*Print error if any*/
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
		
		
			
		echo “Message Sent Successfully !";
		}
	}
}
?> 

message.php

<!DOCTYPE html>  
<html>
<head>
<title>Send Message</title>
</head>
 
<body>
	<form method="post">
<table width="600" border="1" cellspacing="5" cellpadding="5">
 <tr>
    <td>Enter Your Mobile </td>
    <td><input type="text" name="phone"/></td>
  </tr>

<tr>
    <td>Enter Your Message</td>
   <td><textarea rows="4" cols="50" name="message">

</textarea></td>
  </tr>

 <tr>
    <td colspan="2" align="center"><input type="submit" name="save" value="Save Data"/></td>
 </tr>
</table>
 
</form>
</body>
</html>

Now run the program on your browser with the below URL:

http://localhost/CodeIgniter/index.php/Message_send/message