Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Double email sent!

the mail() function

Moderators: macek, egami, gesf

Double email sent!

Postby us3r4it » Tue Mar 27, 2012 1:06 am

Would you please help me to fix the problem of sending two emails instead of just one every time I run the following code using this url:
http://domain.org/image.php?path=dir/file.jpg

Code: Select all
<?php
$email="email@domain.org";
$body = "the body";
$subject="the subject";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Image Visit Receipt <rr@mrdv.org>' . "\r\n";

mail($email,$subject,$body,$headers);

if ($HTTP_GET_VARS["path"])
{
   $imagepath="/home2/mydomain/public_html/files/images/".$HTTP_GET_VARS["path"];
   if (file_exists($imagepath))
   {
      $image=imagecreatefromjpeg($imagepath);
      header('Content-Type: image/jpeg');
      imagejpeg($image);
      exit;
   }
}
?>
us3r4it
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Mar 27, 2012 12:54 am

Re: Double email sent!

Postby iPikTom » Fri Mar 30, 2012 10:48 pm

From my experience when I had a "hit counter" on my site, if the image isn't available (in this case the .JPG file), then it'll send a request twice. No idea why it would do it with your script though considering you're using "IF" statements. Have you tried adding an "ELSE" to them and seeing if that solves it? I know it sounds silly but sometimes it helps - even if you have it as something like:
Code: Select all
} else {
echo "";
}


:)
iPikTom
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Mar 30, 2012 9:28 pm

Re: Double email sent!

Postby us3r4it » Fri Mar 30, 2012 11:29 pm

Thanks for your reply, but it didn't work! Any other solution?
us3r4it
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Mar 27, 2012 12:54 am

Re: Double email sent!

Postby freshnet » Sat Mar 31, 2012 6:11 am

Someone else had a similar problem recently and was using a GET method, it turned out that their antivirus was checking the url and causing a second email to be sent a few seconds/minutes after the original. If that's what you're seeing, consider using a POST request instead and see if it helps.
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 278
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Double email sent!

Postby us3r4it » Sat Mar 31, 2012 5:03 pm

Thanks for the reply, but that is not the case because if instead of showing I use this code to download the image:

Code: Select all
if (file_exists($file))
      {
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename='.'"'.basename($file)).'"';
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . filesize($file));
         ob_clean();
         flush();
         readfile($file);
         exit;
      }


it will send just one email.
But interestingly I found that it is just because of Firefox. I tried it in IE and Opera and I just received one email. Firefox seems to do some modification and shows the image in the centre on a beautiful background and I reckon that's why causing this problem.

So, the problem is solved. Thanks for all the replies!
Cheers,
us3r4it
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Mar 27, 2012 12:54 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.