Reputation: 1319
Is there any reason why this would send duplicate emails? I have a PHP page with only this code on it and every time I run it it sends me two emails.
<?php
mail("[email protected]", "test", "test");
?>
Upvotes: 3
Views: 12664
Reputation: 481
Late to the party, but for those who are going to read this in the future:
Unset the post value after falling through the check for a submit, thus the reload does not process the data again:
if(isset($_POST[$SubmitCode]))
{
unset($_POST[$SubmitCode]); // Clear post signal.
}
When the page reloads, frequently the post submit setting is not cleared. Why this is true I do not know, but clearing the post, solves the problem.
Upvotes: 1
Reputation: 11
Just in case, I discovered my code had a command to spare and it generated two emails be sent:
<?php
$headers .= 'Bcc: [email protected]' . "\r\n";
?>
I deleted this "\r\n" , it fixed the trouble.
Upvotes: 1
Reputation: 1319
Thanks for the input.
As it turns out this was a browser plugin issue, specifically ySlow 2.1.0 on Firefox 4.0.1
I asked our server manager to look into the problem and he reported that the log was showing two hits every time I went to the page. He tried loading it on his machine and the script worked properly and only loaded once. I tried myself on Chrome and it worked, only emailing once. I went through my various add-ons and finally isolated ySlow as the culprit.
Not sure if this means that ySlow is loading every page twice or what, but I'm going to have to keep it disabled. If anyone has any suggestions about fixing the problem with ySlow, please let me know.
Thanks again.
Upvotes: 2
Reputation: 1207
You can try to debug at this way
<?php
mail("[email protected]", "test", "test");
exit("sent");
?>
simply put a 'exit' there and try again. If it still sent twice, maybe is the server problem or could be the [mail function] in ‘php.ini’ (sendmail_from & sendmail_path)
Upvotes: -1
Reputation: 86
Maybe your page loads twice, therefore executes the code two times...You could try some limitation, something like that
if ($sent == '0') {
mail("[email protected]", "test", "test");
$sent = 1;
}
Is this a simple php page, or part of a CMS? Maybe some modules might interfere with your page...
Upvotes: 1