簡體   English   中英

如何使用PHP將echo語句和變量值傳遞給url

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

我想使用php在URL中傳遞我的默認消息以及變量值。 我的代碼無法使用默認消息。.我的代碼在這里:

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

請任何人幫助我。

您可以通過這種方式發送參數。

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

您可以通過這種方式使用消息變量

$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