Subscribe For Free

Friday, January 19, 2018

How to Send SMS and Email Using PHP?

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:
<?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 = ""; $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; ?>
mail() is a predefined function in php and this is the simplest way
to send mail using php.
$msg = "Hello World";

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

// send email
mail("","My subject",$msg);

No comments:

Post a Comment

click it