bc rusty
bc rusty

Reputation: 108

php sending double email

I realize that this is similar to this question, however, I only get a double email when sending to myself. I have sent emails to others with the same script, and they get a single email. This is the email script:

<?php
  function sendEmail( $recipient, $sub, $msg )
  {
    $to      = $recipient;
    $subject = $sub;
    $message = $msg;

    mail( $to, $subject, $message );
  }
?>

The code calling this is this:

if( $retVal != FALSE ) // No errors in execution of report generation
{
  $subject = "Successful Report";
  $message = "The report was successfully generated.";
  // Notify people about success
  sendEmail( $mailto, $subject, $message );

  echo "Successful report generation\n";
}
else // Error in report generation
{
  $subject = "Unsuccessful Report";
  $message = "The report failed to generate.";
  // Notify people about failure
  sendEmail( $mailto, $subject, $message );

  echo "Report generation was unsuccessful\n";
}

where $retval is the return value of system(). Can anyone shed some light on this issue? Or is this something that can be overlooked?

Thanks very much

-rusty

Upvotes: 1

Views: 5147

Answers (3)

er_jack
er_jack

Reputation: 112

$message = "";
$header = "Content-Type: text/html; charset=UTF-8;\r\n";
mail($mailto, $subject, $message, $header);

Upvotes: 0

Aaron Dougherty
Aaron Dougherty

Reputation: 725

Based on the conversation: You are the only recipient that is receiving double email, and the string "Successful report generation" only prints once. It sounds like PHP is not the culprit here, rather something outside of PHP, such as the MTA.

Take a look at the headers of the two email you receive, particularly the MessageID header. If they are identical, then a single email was sent from PHP (good!) and somewhere along the line it got delivered to you twice.

If they are not identical (messy), then PHP did in fact send out two emails (not likely) or there is a resender somewhere between PHP and your mail client.

In the later case, I would take a deeper look at the headers in your email, to determine the source and route of each email, as well as the envelope to determine where the MTA though it was sending mail to.

Upvotes: 3

Mike Mackintosh
Mike Mackintosh

Reputation: 14237

I would add the output from debug_backtrace() into the body of your email. This will allow you to determine when the sendEmail function is called and who called it.

Upvotes: 0

Related Questions