salesforce api add leads from form - php

I am trying to add leads from my contact form to salesforce. Currently I am using this solution that passes them through what I assume is the Web-to-Lead solution they have:
if (isset($_POST['submit'])) {
$ch_register_first_name = $_POST['ch_register_first_name'];
$ch_register_last_name = $_POST['ch_register_last_name'];
$ch_register_dob = $_POST['ch_register_dob'];
$ch_register_phone = $_POST['ch_register_phone'];
$ch_register_email = $_POST['ch_register_email'];
$ch_register_street = $_POST['ch_register_street'];
$ch_register_street2 = $_POST['ch_register_street2'];
$ch_register_city = $_POST['ch_register_city'];
$ch_register_state = $_POST['ch_register_state'];
$ch_register_zip = $_POST['ch_register_zip'];
//set POST variables
$url = 'https://test.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
$fields = array(
'last_name'=>urlencode($ch_register_first_name),
'first_name'=>urlencode($ch_register_last_name),
'street'=>urlencode($ch_register_street),
'city'=>urlencode($ch_register_city),
'state'=>urlencode($ch_register_state),
'zip'=>urlencode($ch_register_zip),
'company'=>urlencode($company),
'description'=>urlencode($ch_register_dob),
'email'=>urlencode($ch_register_phone),
'phone'=>urlencode($ch_register_email),
'mycustomefieldid' => urlencode($ch_register_dob), // custom field
'oid' => $ch_register_salesforce_id, // insert with your id
'retURL' => urlencode('http://thank-you/'), // sending this just in case
'debug' => '1',
'debugEmail' => urlencode("email#email.com"), // your debugging email
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
}
The issue by doing this (if I am correct that its using the Web-to-Lead solution) the max limit is 500 in 24hrs. Some events this form will be used at day of will have more than 500 for sure. How can I use just their API I have read about? Or should I save the locally to the database then run a batch using the Force api?

Related

Make several POST CURL API in one request PHP

I am trying to do some POST with CURL in some way, I explain:
I am using the PhpExcel library, the idea is to upload an excel file that contains a table with several records and the names of the field, with a PhpExcel function I go through each record, so I save it in an array.
The next step is to make a request that sends each of the records to a URL, in this case it is an API URL to edit several products, waiting for parameters (which are each of the fields that are sent in a record) , I have already armed the function to send a single request, I just need to know how I can send several records at once in a single request.
Summary:
I upload the excel file that contains several records. (done)
I keep these records in an array through a function that collects the contents of PhpExcel (done)
Make a POST request with CURL that runs through each of the records and send them at the same time (I have only managed to send only one record)
This code is for call function send POST
private function peticion_get_post($ruta,$formdata,$tipo){
$apiurl = 'https://url/api/v1/';
$url = $apiurl.$ruta;
$postvars = '';
foreach($formdata as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
$ch = curl_init();
if($tipo == 'GET'){
curl_setopt($ch,CURLOPT_URL,$url."?".$postvars);
}
if($tipo == 'POST'){
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST, $tipo);
//curl_setopt($ch,CURLOPT_POST, $tipo);//0 for a GET request y 1 para POST
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch,CURLOPT_TIMEOUT, 20);
$respuesta = curl_exec($ch);
$resultado = json_decode($respuesta);
return $resultado;
}
This code is for call function before and sends content from form
$formdata_post = array(
'id_box' => $id_box,
'number' => $number,
'label' => $label
);
$ruta = 'edit.json';
$resultado_post = $this->peticion_get_post($ruta, $formdata_post, 'POST');
I work with Codeigniter, currently, I send the content by JSON through a form and just send a record, I just have to edit the form and send the content that is in the array that generated the PhpExcel when uploading the file.

How to send an sms to a phone number using php- Codeigniter?

How to send an sms to a phone number using php- Codeigniter?
We have an sms-gateway-provider and I have a user-id, password and api-url. What I wanted to know is, how would I use these in a codeigniter framework, could I get a sample codes? I just wanted the proper codes to achieve this in Codeigniter.
There is simple sms helper available for codeigniter
Copy below file from github as sendsms_helper.php in /application/helpers/
https://github.com/SpringEdgeIndia/codeigniter-sms-api/
Usage:
Load sendsms helper as $this->load->helper('sendsms_helper');
Call sendsms function Ex. sendsms( '919918xxxxxx', 'test message' );
its a simple script
$sending = http_post("your_domain", 80, "/sendsms", array("Username" => $uname, "PIN" => $password, "SendTo" => $Phone, "Message" => $usermessage));
and bingo
you must use cURL for better security in CodeIgniter. this function works fine for sending SMS.
function sms_code_send($number='',$message='')
{
$username = 'username';
$password = '*******';
$originator = 'sender name';
$message = 'Welcom to ......, your activation code is : '.$message;
//set POST variables
$url = 'http://exmaple.com/bulksms/go?';
$fields = array(
'username' => urlencode($username),
'password' => urlencode($password),
'originator' => urlencode($originator),
'phone' => urlencode($number),
'msgtext' => urlencode($message)
);
$fields_string = '';
//url-ify the data for the POST
foreach($fields as $key=>$value)
{
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
}

PHP function to implement sending SMS

I am trying to implement sending SMS for this project I am working on using PHP. Note: I don't mean sending free SMS with the carrier and other things, I actually contacted an SMS company that provided a link as such
www.smssender.com?username=myusername&pass=mypass&message=mymessage&recipient=phonenumber.
What function in PHP can be used to send such a request to the server API, and also get a response? Here is what I want (pseudocode):
function Sendsms(){
add details to sting
send url to sms server with the parameters
get response and display
}
you want to do something like the following (this is an example for a POST request)
i am using PHP's curl http://www.php.net/manual/en/function.curl-init.php
:
$url = 'http://domain.com/get-post.php';
$fields = array(
'lname' => urlencode($last_name),
'fname' => urlencode($first_name),
'title' => urlencode($title),
'company' => urlencode($institution),
'age' => urlencode($age),
'email' => urlencode($email),
'phone' => urlencode($phone)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
The response to the request is in the variable $result
Look like you are doing a GET request. Have you looked into php http_get function?
<?php
$response = http_get("http://www.example.com/", array("timeout"=>1), $info);
print_r($info);
?>
source: http://us2.php.net/manual/en/function.http-get.php
function Sendsms()
{
//add details to sting
$url="www.smssender.comusername=myusername&pass=mypass&message=
mymessage&recipient=phonenumber";
//send url to sms server with the parameters
$rsp = file_get_contents($url);
//get response and display
if( $res )
{
echo "sms successfully send";
}
}

send bulk sms from database

I've been trying to use the code below to send sms but it does not send when I loop. It only works if I just pick one number from database. I have over 5,000 numbers in the database and wish to send an sms to all of them at the same time, Please help.
mysql_select_db($database_xxx, $xxx);
$query_rs = "SELECT phone FROM `notify` order by id asc LIMIT $l1 , $l2";
$rs= mysql_query($query_rs, $xxx) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs= mysql_num_rows($rs);
$phone = $row_rs['phone'];
// Do while loop to send sms.
while($row=mysql_fetch_assoc($rs)){
// Let's do some formatting and keep smiling.
$giringirin = ereg_replace("[^0-9]", "", $phone );
if (strlen($giringirin) == 11) {
$phone1=substr($giringirin, 1);
$phone= "234$phone1";
} elseif (strlen($giringirin) == 13){
$phone = $giringirin;
}
extract($_POST);
//set POST variables
$url = "http://sms.xxx.com/bulksms/bulksms.php?username=$username&password=$password&message=$smsmessage&mobile=$phone&sender=$sender";
$fields = array(
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
if ($result == '1801') { echo "SMS has also been sent to the Customer ($phone) \n";} else { echo "Oooops, No sms was sent";}
//close connection
curl_close($ch);
}
Your code is confusing...
curl_setopt($ch,CURLOPT_POST,count($fields));
CURLOPT_POST is a boolean flag. Either you're doing a post, or you're not. The number of fields you're posting is irrelevant.
You're building up a series of variables/values to be posted, but doing it via string operations. CURL is perfectly capable of taking an array and doing all that for you, reducing your entire foreach loop to just
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
You're using extract() on $_POST, which pollutes your script's variable namespace with any garbage a malicious user cares to send over - you're essentially replicating PHP's utterly moronically brain-dead register_globals all over again.
You're using ereg, which has been deprecated for approximiately 5 million internet years. You should be using the preg functions insteadl
What happens when you run this script in the browser? Blank page? Something? Error?
Start by changing
$url = "http://sms.xxx.com/bulksms/bulksms.php?username=$username&password=$password&message=$smsmessage&mobile=$phone&sender=$sender";
to
$url = "http://sms.xxx.com/bulksms/bulksms.php?username=".$username."&password=".$password."&message=".$smsmessage."&mobile=".$phone."&sender=".$sender."";

problem sending varibles to remote url with CURL

I'm trying to send variables from server A to server B, and back. I have everything working other then actually sending the variables from server A to server B. So i can send variables back from server B to server A but just cant send them to Server B from server A. I use JSON to send the variables back (which works fine) and i use _POST to send them to server B.
Here is my code on both Servers:
Server A
<?
require ('../refference.php');
$post_fields = array(
'unq__id' => $sponsor_reference,
'gdi__username' => $sponsor_GDI_id,
);
$ch = curl_init('http://site.com/WP/d__access.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
$data = json_decode($result);
$sponsor_first_nme = $data->sponsor_first_nme;
echo $sponsor_first_nme;
?>
Server B
<?
include ('config/wp__2135432135435135412312415456654452547534.php');
mysql_connect($hostname,$username,$password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$reference = $_POST['unq__id'];
$username = $_POST['gdi__username'];
$select = mysql_query("SELECT * FROM $usertable WHERE ". "GDI_Username = '$username' AND Unique_id = '$reference'");
while($check = mysql_fetch_array($select)) {
$sponsor_email = $check["Email"];
$sponsor = $check["GDI_Username"];
$sponsor_first_nme = $check["First_Name"];
$sponsor_second_nme = $check["Last_Name"];
$sponsor_domain = $check["GDI_Domain"];
$unq_id = $check["Unique_id"];
}
$sponsor_name = "$sponsor_first_nme $sponsor_second_nme";
$result = array(
'sponsor_first_nme' => $sponsor_first_nme,
'sponsor_second_nme' => $sponsor_second_nme,
'sponsor_email' => $sponsor_email,
'sponsor' => $sponsor,
'sponsor_domain' => $sponsor_domain,
'unq_i' => $unq_id,
'sponsor_full_name' => $sponsor_name,
);
echo json_encode($result);
?>
I know that everything else works fine as I've replaced:
$select = mysql_query("SELECT * FROM $usertable WHERE ". "GDI_Username = '$username' AND Unique_id = '$reference'");
WITH
$select = mysql_query("SELECT * FROM $usertable WHERE ". "GDI_Username = 'myusername' AND Unique_id = '45415645154'");
So i know the problem lies within sending the variables (
'unq__id' => $sponsor_reference,
'gdi__username' => $sponsor_GDI_id,
from server A as i cant use them in the script on server B)
When i test it using the variables, I just get a blank page, but when i replace that line as mentioned above, i get the name ($sponsor_first_nme) echoed out (the expected result)
You could use serialize() to create a string representation of whatever you are trying to send.
You may have to set the post option before you set the post data.
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
If not, the post data could be empty.
Send the post data as a string
$fields = array(
'unq__id' => $sponsor_reference,
'gdi__username' => $sponsor_GDI_id,
);
$field_string = "";
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');
Now you can send it in curl:
Edit:
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
I've got it working, well it seemed to be working the whole time...
I was just echoing it out incorrectly. I used echo $sponsor_first_nme when it was supposed to be echo "$sponsor_first_nme" (with quotes).
Really appreciate all your help though! Thanks a BUNCH!

Categories