On an inbound email need to create a contact record with incoming mail

Whenerver any email will come into personal account of sugarcrm email then I want to create the contact record using custom code. So I wrote the after save logic hook but Its not working when the email is coming into sugarcrm.The logic hook is triggering when I send the mail from surgarcrm.

But I need the logic hook should trigger whenerver email will come to sugarcrm. Please check my code and suggest me how can I do this??.

$hook_array[‘after_save’] = Array();
$hook_array[‘after_save’][] = Array(1, ‘create_contact’, ‘custom/modules/Emails/createContacts.php’, ‘createContact’, ‘createContact’);

<?php if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); ini_set("display_errors",1); class createContact{ function createContact(&$bean, $event, $arguments){ //echo "Kumar";exit require_once("modules/Contacts/Contact.php"); $contact = new Contact(); $contact->last_name = 'emailsomething'; $contact->email1 = 'Emailthing@example.com'; $contact->save(); $myVariable=print_r($bean, TRUE); $GLOBALS['log']->fatal($myVariable); } } ?>

php