Php email sending email twice

I am sure that someone will be able to tell me that I am making a stupid mistake but I cannot figure out what I am doing wrong here.
I have a customer contact form that the customer can change if required, once the form is correct for them (and there are no errors) they are then sent to a page to check some other details by means of clicking on a simple html link. The first thing this new file does is to send the customer an email confirming that their details have been updated, it does other stuff after but I have suspended those queries for the time being while I try to work out why the email is being sent twice.
If no mysql query is made (i.e I try to send the email by accessing the file directly and defining the variables rather than doing a mysql query) the email is only sent once. However, if the mysql query is made to find the email and contact name of the customer, the email is sent twice at the same time. The code is as below, emailfrom etc details are deleted for the purposes of this question but are defined in my file. Please - what am I doing wrong??

<?php session_start();
require_once ('include/config.php'); //contains database info only
require_once ('database.php'); //contains connection info only
if(get_magic_quotes_gpc())
{
	function stripslashes_deep($value)
	{
		$value = is_array($value) ?
		array_map('stripslashes_deep', $value):
		stripslashes($value);
		return $value;
	}
	$_POST=array_map('stripslashes_deep', $_POST);
	$_GET=array_map('stripslashes_deep', $_GET);
	$_COOKIE=array_map('stripslashes_deep', $_COOKIE);
	$_REQUEST=array_map('stripslashes_deep', $_REQUEST);
}
?>
//html code for page here

  <?php
   echo "<p><b>Customer ID: $customer_id</b></p>"; //session variable
   
 //send an email confirming changes made to details
 $customer_id = mysql_real_escape_string($customer_id);
 $sql = "SELECT contact_name, email FROM tbl_customer WHERE customer_id = '$customer_id'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$email = $row['email'];
$contact_name = $row['contact_name'];

//send email confirming changes
$emailto = "$email";


// email from
$emailfrom = "sender@mycompany.com";
$headers  = "MIME-Version: 1.0 \\r\
";
$headers .= "Content-type: text/html; charset=iso-8859-1 \\r\
";
$headers .= "From: " . $emailfrom . "\\r\
";
$headers .= "Cc: me@mycompany.com\\r\
";
$subject = "Your Customer Details";
$contact_name = "$contact_name"; 
$message = '
<html>
<head>
<title> Your Customer Details</title>
</head>
<body>
<p>Dear ' .$contact_name.'</p>
<p>Your details at the mycompany quote/order system have been updated. 
You can login with your customer reference number and the email address to which this message has been sent to view your entry.
If you did not make this request, please let us know what action you would like us to take.</p>
<p>Thanks</p>
<p>The mycompany team</p>
</body>
</html>
'
;

mail($emailto, $subject, $message, $headers); 
echo "<p>email sent to customer</p>";
?>