简体   繁体   English

如何使用PHP将echo语句和变量值传递给url

[英]How to pass echo statement and variable value to url using php

I want pass my Default message as well as variable value in url using php. 我想使用php在URL中传递我的默认消息以及变量值。 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. 请任何人帮助我。

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);

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM