20090928

Leads

Sales leads were being sent to a single email account that a team for sales people were checking. The problem is that some leads were being worked twice. To help organize, track and distribute leads, I created a PHP script inside the search parts website that would choose at random a sales person to send a lead. This script is tied to a form that prospective customers fill out giving information about the product they are looking for. This form is parsed and emailed to a sales person to handle. All of this is put in to a mysql database so we can track which sales person handled which lead and how many leads they are getting per day.


Here is the script: (marked in green)

We pick a random number.
srand((float) microtime() * 10000000);

We put all of the sales people in to an array.
$eaddress[1]="salesperson1@domain.com";
$eaddress[2]="salesperson2@domain.com";
$eaddress[3]="salesperson3@domain.com";

We match the random number with a sales person inside the array.
$rn = array_rand($eaddress);
$pa_eaddress=$eaddress[$rn];

Next part we assign the two values $paname and $pa_ext, to the corresponding sales person's name and their extension number. This will be used inside the signature of the automated email the prospect will receive upon submitting a request.
if ($rn==1){
$paname="Sales Person1";
$pa_ext="5001";
} elseif ($rn==2) {
$paname="Sales Person2";
$pa_ext="5002";
} elseif ($rn==3) {
$paname="Sales Person3";
$pa_ext="5003";

} else {}

Here we use the $paname and $pa_eaddres to make it look like the email was sent by the sales person. So when the prospect receives the automated response the "from:" email address is that of the sales person.
$headers3 .= "From: ".$paname." <".$pa_eaddress.">. \r\n";
$headers3 .= "Content-Type: text/html; charset=iso-8859-1 \r\n";

This is the title or subject of the email the sales person and prospect both receive.
$m_subject = "Quote Request";

Next we fill out the email that is sent to the sales person. This is how we make the leads look like they were emailed by the prospect using the prospect's email address and first name they supplied in the online form. This email is also CC'd to a manager that reviews them and keeps them on file.
$headers1 = "";
$headers1 .= "From: ".$fname1." <".$sender_email1 .">\n";
$headers1 .= 'Cc: manager@domain.com' . "\r\n";
$headers1 .= "Content-Type: text/html; charset=iso-8859-1\n";
$todate1=date("Y-m-d");$todate2=date("h:i:s A");

To ensure that the prospect emails the sales person rather than the automated smtp server, we reinforce this by using the "Reply-To:" field represented by $extra.
$extra = "From:".$pa_eaddress."\r\nReply-To:".$pa_eaddress."\r\nContent-Type: text/html; charset=iso-8859-1\r\n";

We send the automated response to the prospect. $message1 is the body of the email letting them know that they will be contacted shortly. $message1 also contains at the bottom (to resemble a typical email signature) the name of the sales person, their phone number plus extension and email address.
mail($sender_email1, $m_subject, $message1, $extra);

We now send the mail to the sales person. $message is everything a sales person would need to look up the product and contact the prospect. $message is a created by parsing all of the values from the form that prospect filled out and rearranged to make it easier for a sales person to read.
if(mail($pa_eaddress, $m_subject, $message, $headers1))

This is a copy or CC to the manager. We do not use this anymore. We store everything in a database now. This line has been committed using // .
//mail("manager@domain.com", $m_subject, $message, $headers1);

This is a continuation of the if() statement above, just FYI.
{

Here we combine the first name ($fname) and last name ($lname), separated by a space, to create the full name of the prospect.
$name=$fname." ".$lname;

This is how we capture and store all of the leads in the database. Everything is stored in the table aptly named "data_mining". This is just a basic INSERT statement used on a mysql database. Proper syntax on the INSERT statement be found here http://dev.mysql.com/doc/refman/5.1/en/insert.html
$ins=mysql_query("INSERT INTO data_mining (`id`, `request_number`, `form_date`, `year`, `make`, `model`, `sub_model`, `engine_size`, `budget`, `condition`, `first_name`, `last_name`, `address1`, `address2`, `city`, `state`, `zip_code`, `phone`, `phone_ext`, `email_address`, `pa_name`) VALUES('','$tr_no','$todate1','$yr','$mk','$models','$submodels','$eng','$budget','$quote','$fname','$lname','$address1','$address2','$city','$state','$zip','$phone','$ext','$email','$paname')");

This is the message we display to the prospect after the email has been sent and everything stored in to the database. You can put anything you wish here or just have it redirect them back to the home page.
$msg="Thank you for filling out the form!";
}


This script requires a lot of hands on management, meaning it must be edited every time we have someone out of the office or if someone is under a high load we must adjust the amount they are getting. I'm currently working on a script that will allow changes to be made on the fly and allow for better report/monitoring using the "data_mining" table in the mysql database. I will cover this in a part 2.

No comments: