/SFWebtoLead.php

https://github.com/jorgeguberte/Salesforce-Web-To-Lead-PHP-Wrapper · PHP · 81 lines · 52 code · 15 blank · 14 comment · 7 complexity · f2acbdc2f2473fd5249a94461e3f3d66 MD5 · raw file

  1. <?php
  2. /**
  3. * Classe que insere um novo 'lead' no Salesforce via WebToLead.
  4. *
  5. * @author Jorge Guberte <shout@jorgeguberte.com>
  6. * @version 1.0
  7. */
  8. class SFWebtoLead{
  9. /**
  10. *
  11. * Classe �nica.
  12. * @var string $_oid
  13. * @var string
  14. *
  15. */
  16. private $_oid;
  17. private $_SFServletURL;
  18. function SFWebtoLead(){
  19. //Configura��o
  20. $this->_oid = ''; // OID do Salesforce
  21. $this->_SFServletURL = "http://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
  22. }
  23. function Send(array $args){
  24. $outboundArgs = array('oid'=>$this->_oid);
  25. foreach($args as $key=>$value){
  26. if($key !== "submit")
  27. $outboundArgs[stripslashes($key)] = stripslashes($value);
  28. }
  29. if(!$this->_curlSend($outboundArgs)){
  30. return False;
  31. }else{
  32. return True;
  33. }
  34. }
  35. private function _curlSend($outboundArgs){
  36. if(!function_exists('curl_init')){
  37. return false;
  38. }
  39. $ch = curl_init();
  40. if(curl_error($ch) != ""){
  41. return false;
  42. }
  43. try{
  44. curl_setopt($ch, CURLOPT_URL, $this->_SFServletURL);
  45. curl_setopt($ch, CURLOPT_POST, 1);
  46. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($outboundArgs));
  47. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  48. }catch(Exception $e){
  49. return false;
  50. }
  51. try{
  52. $res = curl_exec($ch);
  53. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  54. curl_close($ch);
  55. if($httpCode == '200'){
  56. return True;
  57. }else{
  58. return False;
  59. }
  60. }catch(Exception $e){
  61. return false;
  62. }
  63. return true;
  64. }
  65. }
  66. ?>