0

I want pass my Default message as well as variable value in url using php. My code not working with default message.. My code here:

 $alertmsg= "Your verification code is $password \r\n";

 $url = "http://01.50.92.51/api/smsapi.aspx?username=xxxxxxx&password=xxxxxx&to=$mobiles&from=xxxx&message=$alertmsg";

    $ch  = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $curl_scraped_page = curl_exec($ch);
    curl_close($ch);

Please anyone help me.

3
  • So what is the problem? Commented Jun 24, 2015 at 9:16
  • With default message not working.. Without that message working fine.. Default message is "Your verification code is" Commented Jun 24, 2015 at 9:18
  • Did you tried URL encode it first before including it to your url ? See PhP URL encode function for further information. Commented Jun 24, 2015 at 9:26

2 Answers 2

1

You can send the parameters in this way.

 $alertmsg= "Your verification code is $password \r\n";
 $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "message=" . urlencode($alertmsg));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    $data = curl_exec($ch);
    curl_close($ch);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use your message variable this way

$alertmsg= "Your verification code is $password \r\n";
$url = "http://01.50.92.51/api/smsapi.aspx?username=xxxxxxx&password=xxxxxx&to=$mobiles&from=xxxx&message=".$alertmsg;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.