How to send SMS using PHP CURL function - php

I have an account in a website by which I can send sms to mobile phones. In order to do that at first I need to log in using my id and password and then a page shows up where I put the recipient's mobile number and then my message and finally hit the button to send the message.
Now one of my friends told me that I can send sms from my own application through this website using PHP Curl function. I didn't have any prior idea about CURL function so I googled it but I couldn't figure out how to do this. I have checked the HTML code of the login page and the page from where I can send the sms of that website and I am posting it below.
Would you please kindly show me how to send sms using CURL function or any other way.. through this website..
Thanks in Advance :)
Form1
<form name="form" action="/websms/index.php" method="POST">
<input type="hidden" name="HTMLForm_formname" value="form">
<table align="center" size="300" border="0" class="list">
<tr class="r1">
<th colspan="3" class="left">
<label id="label_login_title" for="login_title" class="HTMLForm-label">User Login</label>
</th>
</tr>
<tr>
<td align="right" valign="top">
<label id="label_mobile_no" for="mobile_no" class="HTMLForm-label">Mobile Number</label>
</td>
<td>
<input type="text" id="mobile_no" name="mobile_no" size="20" maxlength="11" value="" onkeypress="return checkNumberOnly(event)" class="HTMLForm-text">
</td>
</tr>
<tr>
<td align="right" valign="top">
<label id="label_password" for="password" class="HTMLForm-label">Password</label>
</td>
<td>
<input type="password" id="password" name="password" value="" class="HTMLForm-password" size="20">
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" id="submit" name="submit" value="Login" class="button_all_action">
<input type="hidden" id="submit_login" name="submit_login" value="1">
</td>
</tr>
</table>
</form>
Second Form
<form name="form" action="javascript:get(document.getElementById('form'));" method="POST">
<input type="hidden" name="HTMLForm_formname" value="form">
<table align="center" size="450" border="0" class="list">
<tr class="r2">
<th class="left">
<label id="label_send_to_no" for="send_to_no" class="HTMLForm-label">To</label>
</th>
<td class="left">
<textarea id="send_to_no" name="send_to_no" class="HTMLForm-textarea" onkeypress="checkValidGPNumner(document.form.send_to_no)" onchange="checkValidGPNumner(document.form.send_to_no)" onkeyup="checkValidGPNumner(document.form.send_to_no)" wrap="soft" style="width:250px;height:50px"></textarea>
</td>
</tr>
<tr class="r1">
<th class="left">
<label id="label_message" for="message" class="HTMLForm-label">Message</label>
</th>
<td class="left">
<textarea id="message" name="message" class="HTMLForm-textarea" onkeypress="textCounter(document.form.message,document.form.counter_message,160)" onchange="textCounter(document.form.message,document.form.counter_message,160)" onkeyup="textCounter(document.form.message,document.form.counter_message,160)" wrap="soft" style="width:250px;height:130px"></textarea>
<input type="text" id="counter_message" name="counter_message" size="5" value="" readonly="" class="HTMLForm-text"> <label id="label_char_remain" for="char_remain" class="HTMLForm-label">Character remained</label>
</td>
</tr>
<tr class="r2">
<td colspan="2" class="center">
<input type="submit" id="submit" name="submit" value="Send" class="button_all_action">
<input type="hidden" id="mid" name="mid" value="1">
<input type="hidden" id="submit_sms" name="submit_sms" value="1">
</td>
</tr>
</table>
</form>

Simple CURL Function to send sms:
function CURLsendsms($number, $message_body){
$api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$mobileno.'&message='.$textmessage;
$smsGatewayUrl = "http://springedge.com";
$smsgatewaydata = $smsGatewayUrl.$api_params;
$url = $smsgatewaydata;
$ch = curl_init(); // initialize CURL
curl_setopt($ch, CURLOPT_POST, false); // Set CURL Post Data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch); // Close CURL
// Use file get contents when CURL is not installed on server.
if(!$output){
$output = file_get_contents($smsgatewaydata);
}
}

You can indeed send SMS messages with cURL, but cURL is just one part of it. Using cURL, you'd make API calls to a provider like Twilio.

This is a solution using Twilio.
First of all you have to download the twilio library for PHP:
https://github.com/twilio/twilio-php/downloads
Then copy the Services folder in your Server and take in mind the location.
Now you have to create a simple program like the one below, (this is an example an easy php sms sender):
<?php //lets say that the name of this php is smsSender.php
$contactname = $_POST['name'];
$contactphone = $_POST['mobile_no'];
$message = $_POST['message'];
require 'Services/Twilio.php';//<<<<<<<<<HERE! make sure the path is ok.
$AccountSid = "AXXXXXX"; // this numbers you can find it in your twilio dashboard
$AuthToken = "TXXXXXXXXX";// also this number .
$client = new Services_Twilio($AccountSid, $AuthToken);
$people = array(
//"4566789903" => "Curious George",
$contactphone => $contactname,
);
foreach ($people as $number => $name) {
$sms = $client->account->sms_messages->create("7035960031",$number,
$message);
echo "Sent message to $name";
}
?>
So you will need to change in your forms the action like this:
<form name="form" action="smsSender.php" method="POST">
Note: if you are using a trial account, you will be only able to send to verified numbers in your account, but if you register a phone number (1USD/month) then you can send to any number and without the sandbox message).
IMPORTANT: Curl library must be installed in the php server, if you are using your own server, lets say in UBUNTU, this command will install those libraries:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

After changing to this, the code worked great for me.
foreach ($people as $number => $name) {
$client->account->messages->sendMessage("+12055xxxxxx",$number,
$message);

I am not sure that you can send SMS's with CURL, however you can with PHP's mail function.
I have never done so however.

Curl basically used for scrapping contents from another web site, it doesnt have any function to send sms. You have to use other way.
there re few tools by which you can connect to your sms (text Server) from there you can send sms. you can use curl to get your sms replies or etc later part if you need and eager to use that.

Related

Problem with passing variables between two php files

I am following an online tutorial on php and i'm having a problem. I have no idea what could be the problem
<h1>Order Online!</h1>
<form action="order.php" method="POST">
Bread (0.99 USD):
<input type="text" name="bread" />
<br /><br />
Cookie (1.29 USD):
<input type="text" name="cookie" />
<br /><br />
<input type="submit" value="Submit order" />
</form>
This file is supposed to take two numbers (yes I know that the inputs should be type="number") and send them to order.php
<?php
$bread = $_POST['bread'];
$cookie = $_POST['cookie'];
$sum = 0.99 * $bread + 1.29 * $cookie;
echo<<<END
<h2>Order Summary</h2>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<td>Bread (0.99 USD)</td> <td>$bread</td>
</tr>
<tr>
<td>Cookie (1.29 USD)</td> <td>$Cookie</td>
</tr>
<tr>
<td>Total</td> <td>$sum USD</td>
</tr>
</table>
END;
?>
In the video everything was working perfectly, meanwhile everytime i try it, it results with
this:
Earlier today I was able to run a php file perfectly fine, and now i have been stuck with this problem.

$post return array() php

i'm trying to create a simple input program for an online site however when i try to insert data with
query : INSERT INTO tbl_integritytype (type) VALUE ('$type')
With the $type it self is $type=$_POST['ref22'];.
But the output of the $type is always blank
i used :
<form action="insert_integrity.php" method="POST">
<tr class="content-specific-pg">
<td width="104" height="26"><div align="left" class="style6">
<div align="left">Type </div>
</div></td>
<td width="10"><div align="right" class="style6"> :</div></td>
<td width="126"><span class="style6">
<input type="text" id="ref22" name="ref22" size="20" class="easyui-textbox"/>
</span></td>
<td><td width="141"><input type="submit"/></td></td>
</tr>
</table></td>
</form>
as the form.
when i try using print_r($_post); the output is
array()
which i believe means empty.
However, if i set the $type into $type="txt"
the output in database will be
txt
i can't seems to find the solution for this.
Please help me.
Any help will be very appreciated.
post array can't be accessed with $_post instead you should use $_POST to access post array
print_r($_POST)
Your input 'ref22' does not have a value.
<input type="text" id="ref22" name="ref22" value='xxx' size="20" />
^..........^
so the posted array will be empty.
Strip your form code down to bare minimum and test that your 'form' submits 'name:value's
<form action="insert_integrity.php" method="POST">
<input type="text" name="ref22" value='123' />
<input type="submit" name='submit' />
</form>

Amazon remote log-in (PHP cURL) | Cookies

I'm trying to make a remote log-in for Amazon. So basically, an user will log-in through our local form. And if everything he filled in is correct, he will be logged in at Amazon.
`
if(isSet($_POST['submit']))
{
$account = $_POST["account"];
$pass = $_POST["pass"];
$ch = curl_init("https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26ref_%3Dnav_ya_signin");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIESESSION, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, "ap_email=" .$account."&ap_password=".$pass."");
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
else
{
curl_close($ch);
}
}
else
{
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="login">
<table width="100%">
<tr align="center">
<td width="50%" align="right"><font color="navy">E-Mail</font></td>
<td width="50%" align="left"><input type="text" name="account" size="10"></td>
</tr>
<tr align="center">
<td width="50%" align="right" width="100"><font color="navy">Password</font></td>
<td width="50%" align="left"><input type="password" size="10" name="pass"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr align="center">
<td colspan="2" align="center"><input name="submit" type="submit" value="Inloggen"></td>
</tr>
</table>
</form>
<?php } ?>`
This is the code I've used. And I'm getting the following error:
Please Enable Cookies to Continue
To continue shopping at Amazon.com, please enable cookies in your Web browser. Learn more about cookies and how to enable them.
Once you have enabled cookies in your browser, please click on the button below to return to the previous page.
How can I fix this error? I've tried everything.
I'm using XAMPP at the moment.
Just for marking as answer:
you have to 2 things:
1 - Request login page from server using get method
2 - Send login data using new session and with hidden inputs
to see the script : https://stackoverflow.com/a/7532730/889678

Wordpress Contact Form 7 and 3'rd Party integration

I am trying to integrate wordpress CF7 with a third party CRM.
I managed to send the data to the CRM using the following filter:
add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url()
{
return 'https://www.myapps-systems.com/api/WebToLeed.asp';
}
Basically what i did is changing the "form action" from the regular CF7 to the WebtoLead action.
I also mapped the Cf7 form with the following attributes (taken from the CRm sample form):
[hidden mbp1 "222626"]
[hidden URLToReturn "http://thankyoupage.com/thankyou"]
[hidden Companies_Account_Status_Code "546"]
[hidden Companies_Company id:Companies_Company "Website Enquiry"]
<div>
[text* Contacts_Contact id:Contacts_Contact class:name]<label>name*:</label>
[tel* Companies_PhoneNumber id:Companies_PhoneNumber class:telelabelhone]
<label>phone*: </label>
[email Companies_Email id:Companies_Email class:email]<label> mail:‬</label>
[textarea Companies_Note 50x8 id:Companies_Note]<label>message:</label>
</div>
[submit onclick="return OnButton1(); id:send_contact class:submit]
So this did work for me and i managed to receive the data on the CRM, but as i need the data to be stored in the wordpress database as well, i would like it to be both send to the CRM and keep the regular wordpress functionality.And as I cannot use 2 "actions" in 1 form i have to use some different way.
I was trying to implement this by using a few methods , like using "wpcf7_before_send_mail" hook or "wpcf7_after_send_mail", and even using a 3'rd party integration plugin for CF7 (http://wordpress.org/plugins/contact-form-7-3rd-party-integration/screenshots/)
but unfortunatly with ot much success.
I would greatly appreciate your help on the matter.
Here is the full code of the sample Crm integration
<!--
URL is in action attribute.
For all inputs the name attribute is used by the back-end system so don't change them
-->
<form id="big_contact_form" name="Web2LeedForm" action="https://www.myapps-systems.com/api/WebToLeed.asp" method="POST" onsubmit="return submitForm();">
<input type="hidden" name="mbp1" value="222626"/>
<input type="hidden" name="URLToReturn" value="http://test.co.il/contact/thankyou"/>
<input type="hidden" name="Companies_Account_Status_Code" value="546" /> <!-- must be exactly this name and value -->
<input type="hidden" id="Companies_Company" name="Companies_Company" value="website enquiry"/> <!-- the Companies_Company field is mandatory, we don't use it so we just fill it with a value -->
<table>
<tr>
<td>*</td>
<th class="form_label"><label for="Contacts_Contact">name: </label></th>
<td><input class="input" type="text" id="Contacts_Contact" name="Contacts_Contact"/></td>
</tr>
<tr>
<td>*</td>
<th class="form_label"><label for="Companies_PhoneNumber">phone: </label></th>
<td><input class="input" type="text" id="Companies_PhoneNumber" name="Companies_PhoneNumber"/></td>
</tr>
<tr>
<td></td>
<th class="form_label"><label for="Companies_Email">mail: </label></th>
<td><input class="input" type="text" id="Companies_Email" name="Companies_Email"/></td>
</tr>
<tr>
<td></td>
<th class="form_label"><label for="Companies_Note">message:</label></th>
<td><textarea id="Companies_Note" name="Companies_Note" rows="8" cols="50"></textarea></td>
</tr>
<tr>
<td></td>
<td><input id="send_contact" name="submit" type="submit" value="שלח" /></td>
</tr>
</table>
</form>
Thank you
I managed to fix the problem using this great plugin:
http://wordpress.org/plugins/contact-form-7-3rd-party-integration/screenshots/
needs some modification but works great.

PHP can't find variable

So Im relatively new to PHP from ASP. And After converting alot of ASP code into PHP I have come across a problem where my PHP code seems unable to find the hidden variable I have set. It worked fine in ASP and was just wondering the best way to resolve this.
Start of the Form:
<form name="LogIn" action="login.php" method="post">
<td bgColor=#ffffff>
<table align="center" cellSpacing="2" cellPadding="2" border="0">
<tr>
<td> </td>
<td align="right"><font color="#4d71a1">User name:</font> </td>
<td><input name="UserName" size="25" type="Text" autocomplete="OFF"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td align="right"><font color="#4d71a1">Password:</font> </td>
<td><input name="Password" size="25" type="Password" autocomplete="OFF"></td>
<td> </td>
</tr>
PHP script:
<?
if ($_POST["BtnPress"]=="Pressed")
{
if ($_POST["Username"]=="*****" && $_POST["password"]=="*********")
{
$_SESSION['AdminID']="1";
header("Location: "."index.php");
}
else
{
print "<font color=#ff0000>Sorry you cannot access this part of the site.</font>";
}
}
?>
then the rest of the form:
<tr>
<td align="center" colspan="4">
<input type="hidden" name="BtnPress" value="Pressed">
<input type="Submit" value="Log In" class="mybutton" onclick="return CheckForm();">
</td>
</tr>
</table>
</td>
</form>
The PHP seems unable to find the variable BtnPress, its a similar problem throughout alot of my translated ASP to PHP script. Sorry if it is a simple solution but can anyone tell me where I am going wrong?
You have name="Password" and $_POST["password"]
Password != password
Watch your case.
<form name="LogIn" action="login.php" method="post">
<td bgColor=#ffffff>
That is invalid HTML. A <td> element cannot be a child element of a <form>. Browsers are likely to error recover in ways that break your HTML (e.g. by moving the form, but not its contents, outside the table). Do use a validator.
And stuff that isn't likely to be the cause of the problem, but is likely to be the cause of other problems.
Don't use layout tables
Do use the label element
Do use CSS for presentation (you can style your label elements instead of using the obsolete font element
Do not use a hidden input to test if a form is submitted.
use:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// processing of $_POST
}
The name of the submit button should be "BtnPressed" not the hidden field.
What I would do would be to set the form action to ?id=submit or something like that, and then check "if $_GET['id'] == "submit" then process data.
<form action="login.php?do=submit">
.... <input .....
</form>
<?php
if($_GET['do'] == "submit"){
//process data
} ?>

Categories