The idea is to add a trello card to your trello board anytime you receive an email from your contact form 7 wordpress plugin.
Here is how you can do it :
[php light= »true »]
add_action( ‘wpcf7_mail_sent’, ‘your_wpcf7_mail_sent_function’ );
function your_wpcf7_mail_sent_function($contact_form){
$boardid=’5040f5a3********d1c9ddc70′;
$listid=’507f1*********a7a4885′;
$apiKey=’6b93***********9146d740c2555798d8′;
$token=’6a50b26d45736cfc***********91a29b9bfc7a8c’;
$posted_data = $contact_form->posted_data;
$formid=$contact_form->id;
if ($formid==2){
// devis détaillé :
$name="Demande de devis détaillé – ".$posted_data[‘url’]."\n\n";
$desc="De : ".$posted_data[‘your-name’]." ".$posted_data[‘your-email’].""."\n\n";
$desc.="Sujet : Demande de devis détaillé"."\n\n";
$desc.="Société : ".$posted_data[‘societe’]."\n\n";
$desc.="Téléphone : ".$posted_data[‘tel’]."\n\n";
$desc.="URL : ".$posted_data[‘url’]."\n\n";
$desc.="Langue : ".$posted_data[‘lang’]."\n\n";
$desc.="Cible : ".$posted_data[‘cible’]."\n\n";
$desc.="Etat : ".$posted_data[‘etat’]."\n\n";
$desc.="Année de création : ".$posted_data[‘annee’]."\n\n";
$desc.="Facebook : ".$posted_data[‘facebook’]."\n\n";
$desc.="Twitter : ".$posted_data[‘twitter’]."\n\n";
$desc.="Mots clés :".$posted_data[‘keywords’]."\n\n";
$desc.="Budget : ".$posted_data[‘budget’]."\n\n";
$desc.="Informations supplémentaires : ".$posted_data[‘your-message’]."\n\n";
$desc.="Affilié :".$_COOKIE[‘from’]."\n\n";
$desc.="– Ce email a été envoyé via formulaire de contact #".$formid." de xxx "."\n\n";
add_to_trello($name,$desc,$listid,$boardid,$apiKey,$token);
}
if ($formid==3){
// devis rapide :
$name="Demande de devis rapide – ".$posted_data[‘url’]."\n\n";
$desc="De : ".$posted_data[‘your-name’]." ".$posted_data[‘your-email’].""."\n\n";
$desc.="Sujet : Demande de devis rapide"."\n\n";
$desc.="Téléphone : ".$posted_data[‘tel’]."\n\n";
$desc.="URL : ".$posted_data[‘url’]."\n\n";
$desc.="Budget : ".$posted_data[‘budget’]."\n\n";
$desc.="Affilié :".$_COOKIE[‘from’]."\n\n";
$desc.="– Ce email a été envoyé via formulaire de contact #".$formid." de xxx "."\n\n";
add_to_trello($name,$desc,$listid,$boardid,$apiKey,$token);
}
elseif ($formid==4) {
// Demande de rappel :
$name="Demande de rappel – ".$posted_data[‘tel’]."\n\n";
$desc=$posted_data[‘tel’]." souhaite être rappelé !"."\n\n";
$desc.="Affilié :".$_COOKIE[‘from’]."\n\n";
$desc.="– Ce email a été envoyé via formulaire de contact #".$formid." de xxx "."\n\n";
add_to_trello($name,$desc,$listid,$boardid,$apiKey,$token);
}
}
function add_to_trello($name,$desc,$listid,$boardid,$apiKey,$token){
$data = array(
‘idList’ => $listid,
‘name’ => $name,
‘desc’ => $desc
);
$card=cURL_POST_trello($data,’https://trello.com/1/cards/’,$apiKey,$token);
}
function cURL_POST_trello($data,$url,$key,$token){
$ch = curl_init();
$questionmarkishere=strpos($url,’?’);
if ($questionmarkishere){$char=’&’;}else{$char=’?’;}
curl_setopt($ch, CURLOPT_URL, $url.$char.’key=’.$key.’&token=’.$token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, false);
$body = curl_exec($ch);
$headers = curl_getinfo($ch);
//$result=array(‘headers’=>$headers,’body’=>$body);
curl_close($ch);
$result=json_decode($body);
return $result;
}
[/php]