PHPのプログラムから「Web-to-ケース」機能をよびだすには?
Salesforceの「Web-to-ケース」機能は、Webサイトに公開したページからSalesforceへのケース登録を行うことができます。
お問い合わせフォームをサイト上に公開している場合は便利な機能です。
サイトによっては静的なHTMLファイルのみだけでなく動的に表示するコンテンツを切り替えるためにPHPなどのプログラム言語を使っている場合があります。
このような環境でHTMLファイルからではなくPHPプログラムから「Web-to-ケース」機能をよびだしてケースを登録することができます。
以下は、PHPプログラムから「Web-to-ケース」機能を呼び出すサンプルコードです。サイトにあわせて内容を変更のうえご利用ください。
<?php
function web2case($items) {
$url = 'https://webto.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8';
// Salesforceの組織ID
$oid = 'xxxxxxxxxxxxxxx';
// 登録内容を変数に設定
$lastname=$items['lastname'];
$firstname=$items['firstname'];
$email =$items['email'];
$description=$items['description'];
$title=$items['title'];
$title=$items['type'];
$customfield1 =$items['customfield1'];
$customfield2 =$items['customfield2'];
$fields = array(
// Salesforceへのパラメーター
'orgid' => $oid,
'retURL' => '',
'subject'=>(urlencode($title)),
'name'=>urlencode($lastname) . ' ' . urlencode($firstname),
'email'=>urlencode($email),
'description'=>urlencode($description),
'type'=>urlencode($type),
'xxxxxxxxxxxxxxxxxx'=>urlencode($customfield1),
'xxxxxxxxxxxxxxxxxx'=>urlencode($customfield2),
//'debug' => '1',
//'debugEmail' => urlencode("xxx@xxxx"),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST,count($fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>
サンプルコードをご利用時の注意
- サンプルコードはPHPプログラムを利用または開発されたことのある方を対象にしています。
- コードはサンプルでありそのままでは利用できません。各パラメータを適切なものに設定しテストを行った上でご利用ください。
- ’xxxxxxxxxxxxxxxxxx’にはご利用のSalesforce組織での各ID(組織IDや項目のID)を記述ください。
- サンプルコードについてお問い合わせは原則Synergy!LEADサポートの対象外となります。
「Activation!トレーニング」をご契約のお客様に対してのみサポートをさせていただきます。ご了承ください。
