Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Friday, January 19, 2018

How to Send SMS and Email Using PHP?

SMS
To send sms we need an API from the sms service provider. 
Here we are providing some of the sms service providers list.
Text Local: https://www.textlocal.in/
kapsystem: https://kapsystem.com/ 
msg91: https://msg91.com/
<?php $authKey = "XXXXX"; //Your Authentkation key $mobileNumber = "9999999"; //Sender ID,While using route4 sender id should be 6 characters long. $senderId = "AAABBB"; $mymsg = "Hello world"; //Your message to send, Add URL encoding here. $message = urlencode("$mymsg"); $route = "default"; $postData = array( 'authkey' => $authKey, 'mobiles' => $mobileNumber, 'message' => $message, 'sender' => $senderId, 'route' => $route ); //API URL provided by your SMS service provider $url = "http://api.msg91.com/api/sendhttp.php"; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData )); //Ignore SSL certificate verification curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $output = curl_exec($ch); if (curl_errno($ch)) { echo 'error:' . curl_error($ch); } curl_close($ch); echo $output; ?>
EMAIL
mail() is a predefined function in php and this is the simplest way
to send mail using php.
<?php
//message
$msg = "Hello World";

// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);

// send email
mail("someone@example.com","My subject",$msg);
?>

1 comment:

  1. Hello there! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I'm getting sick and tired of Wordpress because I've had problems with hackers and I'm looking at alternatives for another platform. I would be great if you could point me in the direction of a good platform.Singapore

    ReplyDelete

More Posts

FOLLOW