Sendgrid示例php发送重复的电子邮件

I'm basically going through Sendgrid's example for sending an email to duplicate email addresses but getting strange results. I receive duplicate emails (4 of them) every time. I've looked through several threads and almost all have been resolved by a duplicate request. However, from what I can see there are none (and again, this is basically the example script from Sendgrid). Any help would be greatly appreciated...

Code:

$url = 'https://api.sendgrid.com/';
$user = 'My Username';
$pass = 'My Password';

$json_string = array(

  'to' => array(
    'myemail@example.com', 'myemail@gmail.com'
  ),
  'category' => 'test_category'
);


$params = array(
    'api_user'  => $user,
    'api_key'   => $pass,
    'x-smtpapi' => json_encode($json_string),
    'to'        => 'example3@sendgrid.com',
    'subject'   => 'testing from curl',
    'html'      => 'testing body',
    'text'      => 'testing body',
    'from'      => 'senderemail@example.com',
  );


$request =  $url.'api/mail.send.json';

// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);



// print everything out
print_r($response);

The printout says success (only one time). The email is delivered fine. The only problem is that 4 emails show up to every emailbox.

If you're running this through a browser, it's likely your have plugins that are causing repeat submissions - which will look like it's only happening once from your browser's point of view. Web logs will also show you if this is happening. Try calling it from curl on a command line to guarantee that it's only submitting the request once.