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 <>

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<>
To: $email
Date: $date
MIME-Version: 1.0
Content-Type: multipart/related; boundary="$boundary"


$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:$user_id&key=$key

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

Site Name.

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




if (mail($email, "Activate your account.", $message, $headers))
   return true;
   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:

Received: by with SMTP id a5cs148505ybf;
Tue, 27 Apr 2010 09:01:02 -0700 (PDT)
Received: by with SMTP id v20mr2080613wah.65.1272384060165;
Tue, 27 Apr 2010 09:01:00 -0700 (PDT)
Return-Path: <>
Received: from ( [])
by with SMTP id r20si2256142wam.10.2010.;
Tue, 27 Apr 2010 09:01:00 -0700 (PDT)
Received-SPF: pass ( domain of designates as permitted sender) client-ip=;
Authentication-Results:; spf=pass ( domain of designates as permitted sender)
Received: (qmail 2073 invoked from network); 27 Apr 2010 16:00:58 -0000
Received: from unknown (HELO ([])
(envelope-sender <>)
by (qmail-ldap-1.03) with SMTP
for <>; 27 Apr 2010 16:00:58 -0000
Received: from (localhost.localdomain [])
by (8.13.8/8.12.11) with ESMTP id o3RG0wxn028456
for <>; Tue, 27 Apr 2010 09:00:58 -0700
Received: (from alexkravchenko@localhost)
by (8.13.8/8.12.11/Submit) id o3RG0v6k028449;
Tue, 27 Apr 2010 09:00:57 -0700
Message-Id: <>
Subject: Activate your account.
From: Site Name<>
Date: Tue, 27 Apr 2010 09:00:57 -0700
MIME-Version: 1.0
Content-Type: multipart/related; boundary=“8a40e7b6132ad332f0f2fce3961f8d43”

Thank you for any help!

$headers = <<<END
From: Site Name<>
To: $email

Remove that line and see what happens.

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