Sending email function problem

Dear All:

I have a website. A user needs to sign up, so he fills out a registration form. An email with an activation link should be sent to his email address. Currently, instead of one email with the activation link, a person receives 2 similar emails with the same activation link. Time frame between two emails is 1 second. Tested with gmail and yahoo accounts. Same story. Here are the headers in gmail:


from Site Name <info@sitename.net>
to kravchenko.temp359@gmail.com,
kravchenko.temp359@gmail.com


Currently, more than 50% of Yahoo account holders don’t receive email notifications from my site. Maybe it has to do something with the above described problem.

Below is the send_mail() function responsible for sending a mail to a user with the activation link:


<?
/***************** Function send_mail ****************************************************/
function send_mail($user_id, $user_name, $nickname, $password, $email, $key)
{
$boundary   = md5( time() );
$date       = date( 'r' );
$click_link = "http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']);

$html     = file("mails/reg_mail.html");
$element  = preg_replace("/FIELD_nickname/",  $nickname,   $html);
$element  = preg_replace("/FIELD_password/",  $password,   $element);
$element  = preg_replace("/FIELD_name/",  $user_name,   $element);
$element  = preg_replace("/FIELD_id/",        $user_id,    $element);
$element  = preg_replace("/FIELD_key/",       $key,        $element);
$element  = preg_replace("/FIELD_link/",      $click_link, $element);
$ausgabe  = implode("", $element);

$headers = <<<END
From: Site Name<info@sitename.net>
To: $email
Date: $date
MIME-Version: 1.0
Content-Type: multipart/related; boundary="$boundary"

END;

$message = <<<END
Content-Type: multipart/alternative
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Activate Your Account!

Dear $user_name, you are one step away to creating your account at Site Name. To finish registration, please click on the activation link below:

http://www.sitename.net/confirmation.php?id=$user_id&key=$key

If clicking on the activation link does not take you to our website (sitename.net), please copy the link
above and paste it into the address bar of your browser.

Sincerely,
Site Name.


--$boundary
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

$ausgabe

--$boundary--


END;

if (mail($email, "Activate your account.", $message, $headers))
   return true;
else   
   return false;
}

/************* End send_mail ****************/


And a call to the function:


send_mail($rec['user_id'], $rec['name'], $nickname, $password, $email, $key)

Does it look normal? Do you see any problems with this code?

And here is the contents of the original gmail letter:


Delivered-To: kravchenko.temp359@gmail.com
Received: by 10.150.178.5 with SMTP id a5cs148505ybf;
Tue, 27 Apr 2010 09:01:02 -0700 (PDT)
Received: by 10.114.248.20 with SMTP id v20mr2080613wah.65.1272384060165;
Tue, 27 Apr 2010 09:01:00 -0700 (PDT)
Return-Path: <alexkravchenko@p3nlhg184.shr.prod.phx3.secureserver.net>
Received: from p3nlsmtp02.shr.prod.phx3.secureserver.net (p3nlsmtp02.shr.prod.phx3.secureserver.net [72.167.234.226])
by mx.google.com with SMTP id r20si2256142wam.10.2010.04.27.09.00.59;
Tue, 27 Apr 2010 09:01:00 -0700 (PDT)
Received-SPF: pass (google.com: domain of alexkravchenko@p3nlhg184.shr.prod.phx3.secureserver.net designates 72.167.234.226 as permitted sender) client-ip=72.167.234.226;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of alexkravchenko@p3nlhg184.shr.prod.phx3.secureserver.net designates 72.167.234.226 as permitted sender) smtp.mail=alexkravchenko@p3nlhg184.shr.prod.phx3.secureserver.net
Received: (qmail 2073 invoked from network); 27 Apr 2010 16:00:58 -0000
Received: from unknown (HELO p3nlhg184.shr.prod.phx3.secureserver.net) ([97.74.24.184])
(envelope-sender <alexkravchenko@p3nlhg184.shr.prod.phx3.secureserver.net>)
by p3nlsmtp02.shr.prod.phx3.secureserver.net (qmail-ldap-1.03) with SMTP
for <kravchenko.temp359@gmail.com>; 27 Apr 2010 16:00:58 -0000
Received: from p3nlhg184.shr.prod.phx3.secureserver.net (localhost.localdomain [127.0.0.1])
by p3nlhg184.shr.prod.phx3.secureserver.net (8.13.8/8.12.11) with ESMTP id o3RG0wxn028456
for <kravchenko.temp359@gmail.com>; Tue, 27 Apr 2010 09:00:58 -0700
Received: (from alexkravchenko@localhost)
by p3nlhg184.shr.prod.phx3.secureserver.net (8.13.8/8.12.11/Submit) id o3RG0v6k028449;
Tue, 27 Apr 2010 09:00:57 -0700
Message-Id: <201004271600.o3RG0v6k028449@p3nlhg184.shr.prod.phx3.secureserver.net>
To: kravchenko.temp359@gmail.com
Subject: Activate your account.
From: Site Name<info@sitename.net>
To: kravchenko.temp359@gmail.com
Date: Tue, 27 Apr 2010 09:00:57 -0700
MIME-Version: 1.0
Content-Type: multipart/related; boundary=“8a40e7b6132ad332f0f2fce3961f8d43”


Thank you for any help!
Alex.

$headers = <<<END
From: Site Name<info@sitename.net>
To: $email

Remove that line and see what happens.

Hi! Thank you! That solves my problem. I appreciate your time and efforts!
Alex.