Sunday, 13 December 2015

send UTF sms through php using cdac service

Before using the sms service we must first install PHP5_CURL as we are using curl function

Command to install is : sudo apt-get install php5-curl

then after restart the apache server:
              sudo   /etc/init.d/apache2 restart

If the above step not done we will receive a error " CALL TO UNDEFINED FUNCTION CURL_INIT"

and, if it is executed in browser you may receive 500 - server error.

So, before proceeding please install the above step.


<?php 
header('Content-Type: text/html; charset=UTF-8');
// $message = "नमस्कार सुभोदय";
// $message = "�� �� मु�्य समा�ार";
$message="ఇది టెస్ట్ మెసేజ్";
$finalmessage = "";
$sss = "";
for($i=0;$i<mb_strlen($message,"UTF-8");$i++) {
$sss=mb_substr($message,$i,1,"utf-8");
$a=0;
$abc="&#" .ordutf8($sss,$a).";";
$finalmessage.=$abc;
}
echo $finalmessage;
function ordutf8($string, &$offset){
$code=ord(substr($string, $offset,1));
if ($code >= 128) 
{ //otherwise 0xxxxxxx
if ($code < 224) $bytesnumber = 2; //110xxxxx
else if ($code < 240) $bytesnumber = 3; //1110xxxx
else if ($code < 248) $bytesnumber = 4; //11110xxx
$codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0);
for ($i = 2; $i <= $bytesnumber; $i++) {
$offset ++;
$code2 = ord(substr($string, $offset, 1)) - 128; //10xxxxxx
$codetemp = $codetemp*64 + $code2;
}
$code = $codetemp;
}
return $code;
}
$data = array(
"username" => "XXXXXX", // type your assigned username
"password" => "XXXXXXX", //type your password
"senderid" =>"XXXXXX", //type your senderID
"smsservicetype" => "unicodemsg", 
"bulkmobno" => "97305XXXXX,762067XXXX",//*Note*:for single number enter one number
"content" => $finalmessage //type the message.

);
function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . urlencode($value) . '&'; 
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($post, CURLOPT_HTTPHEADER, array("Content-length:" . strlen($fields) ));
curl_setopt($post, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"));
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
echo $result = curl_exec($post);
curl_close($post);
}
post_to_url("http://msdgweb.mgov.gov.in/esms/sendsmsrequest", $data);
?>
   

Sending E MAIL using PHPMailer

Download the PHPMailer from the website before proceeding : https://github.com/PHPMailer/PHPMailer

Extract the ZIP file and keep in the same location where our sendMail.php residing ( the apache/xampp default location) and

Now here is the sendMail.php , copy the below code and paste it in a file,name the file as sendMail.php. Change the Mail domain name, username and passwords respectively at the locations given and run the program using the command

> php sendMail.php

Then check the output in your inbox.


<?php
                                           /* Send Mail through PHP code */
try{
require_once('PHPMailer/class.phpmailer.php');

$mail = new PHPMailer();
// Dialog::message('Mail', "Mail object created with $this->email");
// $uname=Yii::app()->user->name;  No need if this is not a webapplication ( The logged in username say example, Admin)
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'ssl';
$mail->Host = 'mail.domain.in';
$mail->Port = 465;
$mail->Username = 'username@domain.in';
$mail->Password = 'password@123';
$mail->SMTPAuth = true;
$mail->From = 'username@domain.in';
$mail->FromName = "Email";
$mail->AddAddress('username@domain.in');

$mail->AddReplyTo("Someone@domain.in", "someone");
//$ipadd=Yii::app()->request->userHostAddress;
$ipadd=null;
$mail->IsHTML(true);
$mail->Subject = "Testing the mail service";
$mail->AltBody = "Mail From Server. To view the message, please use an HTML compatible email viewer!";
$mail->Body = "From Email : username@domain.in <br/> Logged in Application as <b>Admin</b>";


if(($ipadd!=null)and($ipadd!='')) {
// $mail->Body= $mail->Body." through Ip address $ipadd<br/> Content: ".$this->body;
$mail->Body= $mail->Body." through Ip address $ipadd<br/> Content: Testing the application using XAMPP";
}
else {
// $mail->Body= $mail->Body."<br/> Content: ".$this->body;
$mail->Body= $mail->Body."<br/> Content: Test mail from the XAMPP server code";
}
if(!$mail->Send())
{
 echo "<h1>"."Mailer Error: " . $mail->ErrorInfo."</h1>";
 exit(0);
}
else
{
 echo "<h1>Mail sent Successfully!</h1>";
}
     }catch(Exception $e){
        echo 'caught exception:',$e->getMessage();
     }

     ?>

Thursday, 10 December 2015

Got Error "C:\users\..\AppData\Local\Temp;c:" while installing a software

err.jpg
If you encounter the above error while installing a software, Do the following steps:
The above error encounters when the user defined environment variable "TEMP" is updated. For example, If we installed JDK , the main important part after installing JDK is setting PATH .. somehow, for some need we need to set TEMP variable also, In that case, this TEMP variable creates the error while installing since the ":" is not allowed in the folder names and here in path we have a ';' followed by 'C:' generates a windows error 
Your %TEMP% environment variable is screwy.  Do this:
- Open Control Panel
- System
- Advanced System Settings
- Environment Variables
- In the User Variables, select TEMP and click Edit
- Remove the semi-colon (;) and everything after it
- OK your way out of all the dialogs
- Try installing Software again
Hope this helps!!!