0

How to call a PHP function on submit button
My function is

function sendSMS($mobile, $msg, $sender, $sendPass, $sendID)
    {
        $msg=urlencode($msg);
        $ch = curl_init();
        $url="abusms.com/pushsms.php?username=kas&password=6117&sender=SHRIA&to=$mobile&message=$msg";
        //echo $url;
        $url=urlencode($url);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1)or die("error1");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);
        echo $data;
        echo 
        curl_close($ch);
        return $data;
        //return substr($data,0,1);
    }
<tr>
<td colspan="3" align="center"><input type="submit" name="send" value="send" onclick="sendSMS($mobile, $msg, $sender, $sendPass, $sendID)"/> </td>
</tr>
3
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by karthik_ppts
0

Try this

<?php
	if(isset($_POST["send"]))
	{
		sendSMS('999999999','Message','432322245','pass','xxxxxx');
	}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Send Mail</title>
</head>

<body>
<form action="" method="post" name="frm_mail">
<table>
    <tr>
    <td colspan="3" align="center"><input type="submit" name="send" value="send"/> </td>
    </tr>
</table>
</form>
</body>
</html>
<?php
    function sendSMS($mobile, $msg, $sender, $sendPass, $sendID)
    {
		$msg=urlencode($msg);
		$ch = curl_init();
		$url="abusms.com/pushsms.php?username=kas&password=6117&sender=SHRIA&to=$mobile&message=$msg";
		//echo $url;
		$url=urlencode($url);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POST, 1)or die("error1");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
		$data = curl_exec($ch);
		echo $data;
		echo
		curl_close($ch);
		return $data;
		//return substr($data,0,1);
		
    }
?>

Edited by karthik_ppts: n/a

0

Hi karthik i am not getting the value of phone n msg
Please see n give suggestion

<?php
	if(isset($_POST["send"]))
	{
	     $name=$_POST['name'];
         $mobile=$_POST['phone'];
         $msg=$_POST['msg'];
         $sender="kacs";
         $sendPass="698117";
         $sendID="SHRDATIA";
		 sendSMS('$mobile','$msg','kacs','698117','SHRDATIA');
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form  method="post" name="frm_mail" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table>
<tr>
 <td>Name</td>
 <td>:</td>
 <td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Mobile</td>
<td>:</td>
<td><input type="text" name="phone"/></td>
</tr>
<tr>
<td>Message</td>
<td>:</td>
<td><input type="text" name="msg"/></td>
</tr>

    <tr>
    <td colspan="3" align="center"><input type="submit" name="send" value="send"/> </td>
    </tr>
<?php
if(isset($_POST['send']))
{
$name=$_POST['name'];
$mobile=$_POST['phone'];
$msg=$_POST['msg'];
$sender="kacs";
$sendPass="698117";
$sendID="SHRDATIA";

}
?>
</table>
</form>
</body>
</html>
<?php
    function sendSMS($mobile, $msg, $sender, $sendPass, $sendID)
    {
		$msg=urlencode($msg);
		echo $msg;
		$ch = curl_init();
		$url="abulksms.com/pushms.php?username=kcs&password=697&sender=SHATIA&to=$mobile&message=$msg";
		echo $url;
		$url=urlencode($url);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POST, 1)or die("error1");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
		$data = curl_exec($ch);
		//echo $data;
		curl_close($ch);
		return $data;
		//return substr($data,0,1);
		
    }
?>
0

Hi,

Just remove single Quote from following line:
like.,
sendSMS($mobile,$msg,'kacs','698117','SHRDATIA');

May be it's workable...

0
<?php
    if(isset($_POST["send"]))
    {
		$name=$_POST['name'];
		$mobile=$_POST['phone'];
		$msg=$_POST['msg'];
		$sender="kacs";
		$sendPass="698117";
		$sendID="SHRDATIA";
		sendSMS('$mobile','$msg','kacs','698117','SHRDATIA');
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
     
    <body>
    <form method="post" name="frm_mail" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <table>
    <tr>
    <td>Name</td>
    <td>:</td>
    <td><input type="text" name="name"/></td>
    </tr>
    <tr>
    <td>Mobile</td>
    <td>:</td>
    <td><input type="text" name="phone"/></td>
    </tr>
    <tr>
    <td>Message</td>
    <td>:</td>
    <td><input type="text" name="msg"/></td>
    </tr>
     
    <tr>
    <td colspan="3" align="center"><input type="submit" name="send" value="send"/> </td>
    </tr>
    
    </table>
    </form>
    </body>
    </html>
    <?php
    function sendSMS($mobile, $msg, $sender, $sendPass, $sendID)
    {
		$msg=urlencode($msg);
		echo $msg;
		$ch = curl_init();
		$url="abulksms.com/pushms.php?username=kcs&password=697&sender=SHATIA&to=$mobile&message=$msg";
		echo $url;
		$url=urlencode($url);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POST, 1)or die("error1");
		curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
		$data = curl_exec($ch);
		//echo $data;
		curl_close($ch);
		return $data;
		//return substr($data,0,1);
     
    }
    ?>

Edited by karthik_ppts: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.