Skip to content

Instantly share code, notes, and snippets.

@akv
Last active August 29, 2015 13:57
Show Gist options
  • Save akv/9389282 to your computer and use it in GitHub Desktop.
Save akv/9389282 to your computer and use it in GitHub Desktop.
Mail through Zend Desk Api
first Create a php File in which Html form for the mail is given.
Remember the name of the fields should be started by using z_ as created below
<html>
<div id="box_form">
<form id="zFormer" method="POST" action="mail_send.php" name="former">
<p>
Your Name:<input type="text" value="" name="z_name">
</p>
<p>
Your Email Address: <input type="text" value="" name="z_requester">
</p>
<p>
Subject: <input type="text" value="" name="z_subject">
</p>
<p>
Description: <textarea name="z_description"></textarea>
</p>
<p>
<input type="submit" value="submit" id="submitter">
</p>
</form>
</div>
</html>
Now in the configuaration file
<?php
define("ZDAPIKEY", "3mI3ptmDSyrQ7OZevFTU0uUBaXdbEpD6FodqX0Wz"); // key generated by the zend desk
define("ZDUSER", "arun12verma@gmail.com");//username specified --- copy of mail will also be shared
define("ZDURL", "https://jinglingapp.zendesk.com/api/v2/"); // this is the URL generated in the setting section of admins zend desk.please look at the API section where you will find this.
function curlWrap($url, $json)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_URL, ZDURL.$url);
curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$decoded = json_decode($output);
return $decoded;
}
$arr = array();
foreach($_POST as $key => $value){
if(preg_match('/^z_/i',$key)){
$arr[strip_tags($key)] = strip_tags($value);
}
}
$ticket = array('ticket' => array('subject' => $arr['z_subject'], 'comment' => array("value"=>$arr['z_description'] ), 'requester' => array('name' => $arr['z_name'], 'email' => $arr['z_requester'])));
if(CUSTOM){
foreach($_POST as $key => $value){
if(preg_match('/^c_/i',$key)){
$id = str_replace('c_', '', strip_tags($key));
$value = strip_tags($value);
$cfield=array('id'=>$id, 'value'=>$value);
$ticket['ticket']['custom_fields'][]=$cfield;
}
}
}
$ticket = json_encode($ticket);
$return = curlWrap("/tickets.json", $ticket);
//echo '<pre>';
//print_r($return);
?>
@akv
Copy link
Author

akv commented Mar 6, 2014

first Create a php File in which Html form for the mail is given.
Remember the name of the fields should be started by using z_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment