I am trying to make my form work, but keep getting this error. I have uploaded it to a server, but its just not working. What am I doing wrong? This is the error message I am getting:
Fatal error: Call to undefined function curl_init() in /home/mxwll05/public_html/beta/MSY/test-contact/Contact.php on line 82
PLEASE HELP! Here's my code for contact.php
<?php
/*
* Copyright 2008, Constant Contact
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class Contact {
// Constructor VARIABLES
var $user_name;
var $password;
var $api_key;
var $log_file_name = "ccsub.log";
// contact vars
var $email_address='';
var $list_url;
var $first_name;
var $last_name;
var $middle_name;
var $company_name;
var $job_title;
var $work_phone;
var $home_phone;
var $update_date;
var $list_name;
var $err_message;
var $custom_fields = array();
var $nritems;
// FUNCTIONS
// constructor
public function __construct($user,$pw,$key, $log_file) {
$this->user_name=$user;
$this->password=$pw;
$this->api_key=$key;
if ($log_file) $this->log_file_name=$log_file;
}
// set contact vars
function SetPrimaryInfo($email, $list, $first, $last, $middle, $company, $job) {
//if ((!empty($email)) && (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $email))) {
// $this->err_message .= '<br />Missing or invalid email address.';
//}
$this->email_address=$email;
$this->first_name=$first;
$this->last_name=$last;
$this->middle_name=$middle;
$this->update_date=date("Y-m-d").'T'.date("H:i:s").'+01:00';
$this->company_name=$company;
$this->job_title=$job;
$this->list_name=$list;
$this->list_url=$this->FindContactList($list);
}
public function SetContactInfo($home_num, $home_num, $addr_1, $addr_2, $addr_3, $city, $state, $country, $postal_code, $sub_postal) {
$this->home_number=$home_num;
$this->home_number=$home_num;
$this->address_line_1=$addr_1;
$this->address_line_2=$addr_2;
$this->address_line_3=$addr_3;
$this->city_name=$city;
$this->state_code=$state;
$this->country_code=$country;
$this->zip_code=$postal_code;
$this->sub_zip_code=$sub_postal;
}
public function SetCustomFields($cf_array) {
$this->custom_fields = $cf_array;
}
private function FindContactList($list_name) {
$request = "http://api.constantcontact.com/ws/customers/".$this->user_name."/lists";
$session = curl_init($request);
// Set up Digest authentication - username and password.
$userNamePassword = $this->api_key."%".$this->user_name.":".$this->password;
if (empty($this->api_key) || empty($this->user_name) || empty($this->password)) {
$this->err_message .= '<br />Missing or invalid user name or password or api key.';
error_log(date('Y-m-d H:i:s') .
' Error invlid user name or password or api key '.
"\n", 3, $this->log_file_name);
}
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
curl_setopt($session, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($session, CURLOPT_GET, 1);
curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($session, CURLOPT_HEADER, 0); // Do not return headers
//don't send the response to browser
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($session);
curl_close($session);
//error handling and write to log file
if (!$response) {
$list_id = -1;
if ($this->log_file_name) error_log(date('Y-m-d H:i:s') .
' Error attempting to connect via curl to ' . $request .
"\n", 3, $this->log_file_name);
} else {
$data = simplexml_load_string($response);
foreach($data->entry as $data_entry) {
$entry_name = urlencode($data_entry->content->ContactList->Name);
if ($entry_name == $list_name) {
$list_id=$data_entry->content->ContactList['id'];
}
}
}
return $list_id;
}
public function GetErrorMessage() {
return $this->err_message;
}
// output feed
public function MaketEntry() {
if ($this->list_url == -1 || empty($this->list_url) || $this->list_url == ""){
$this->err_message .= '<br />could not find valid list with the name '. $this->list_name;
error_log(date('Y-m-d H:i:s') .
' Error could not find valid list with list name ' . $this->list_name .
"\n", 3, $this->log_file_name);
}
$xml_sttring = "<entry xmlns='http://www.w3.org/2005/Atom'></entry>";
$xml_object = simplexml_load_string($xml_sttring);
$title_node = $xml_object->addChild("title", htmlspecialchars("Hmmm this is ignored right now"));
$updated_node = $xml_object->addChild("updated", htmlspecialchars($this->update_date));
$author_node = $xml_object->addChild("author");
$author_name = $author_node->addChild("name", htmlspecialchars("CTCT Samples"));
$id_node = $xml_object->addChild("id", "urn:uuid:E8553C09F4xcvxCCC53F481214230867087");
$summary_node = $xml_object->addChild("summary", htmlspecialchars("Customer document"));
$summary_node->addAttribute("type", "text");
$content_node = $xml_object->addChild("content");
$content_node->addAttribute("type", "application/vnd.ctct+xml");
$contact_node = $content_node->addChild("Contact", htmlspecialchars("Customer document"));
$contact_node->addAttribute("xmlns", "http://ws.constantcontact.com/ns/1.0/");
$email_node = $contact_node->addChild("EmailAddress", urldecode(htmlspecialchars($this->email_address)));
$fname_node = $contact_node->addChild("FirstName", urldecode(htmlspecialchars($this->first_name)));
$lname_node = $contact_node->addChild("LastName", urldecode(htmlspecialchars($this->last_name)));
$lname_node = $contact_node->addChild("MiddleName", urldecode(htmlspecialchars($this->middle_name)));
$lname_node = $contact_node->addChild("CompanyName", urldecode(htmlspecialchars($this->company_name)));
$lname_node = $contact_node->addChild("JobTitle", urldecode(htmlspecialchars($this->job_title)));
$optin_node = $contact_node->addChild("OptInSource", htmlspecialchars("ACTION_BY_CONTACT"));
if (!empty($this->home_number))
$hn_node = $contact_node->addChild("HomePhone", htmlspecialchars($this->home_number));
if (!empty($this->work_number))
$wn_node = $contact_node->addChild("WorkPhone", htmlspecialchars($this->work_number));
if (!empty($this->address_line_1))
$ad1_node = $contact_node->addChild("Addr1", htmlspecialchars($this->address_line_1));
if (!empty($this->address_line_2))
$ad2_node = $contact_node->addChild("Addr2", htmlspecialchars($this->address_line_2));
if (!empty($this->address_line_3))
$ad3_node = $contact_node->addChild("Addr3", htmlspecialchars($this->address_line_3));
if (!empty($this->city_name))
$city_node = $contact_node->addChild("City", htmlspecialchars($this->city_name));
if (!empty($this->state_code))
$state_node = $contact_node->addChild("StateCode", htmlspecialchars($this->state_code));
if (!empty($this->country_code))
$ctry_node = $contact_node->addChild("CountryCode", htmlspecialchars($this->country_code));
if (!empty($this->zip_code))
$zip_node = $contact_node->addChild("PostalCode", htmlspecialchars($this->zip_code));
if (!empty($this->sub_zip_code))
$subzip_node = $contact_node->addChild("SubPostalCode", htmlspecialchars($this->sub_zip_code));
if (!empty($this->custom_fields)) {
foreach($this->custom_fields as $k=>$v) {
if (!empty($v))
$contact_node->addChild("CustomField".$k, htmlspecialchars($v));
}
}
$contactlists_node = $contact_node->addChild("ContactLists");
$contactlist_node = $contactlists_node->addChild("ContactList");
$contactlist_node->addAttribute("id", $this->list_url);
$entry = $xml_object->asXML();
return $entry;
}
};
?>
The error message you're
The error message you're seeing is stating that the Apache server can not find the PHP function curl_init(). This is most likely because the version of php you have installed prior to PHP 5 or you do not have the curl library and utilities installed. You should check your server configuration to ensure you have the most updated version of php installed and that your Curl libraries are also correctly installed.
Dave B Support Engineer, Constant Contact