-1

I have written a code in php in mail sending. The code is working. But the issue is that after sending mail to an email id one time,then when the page is refreshed again, again a mail is being send. How to prevent this ? Can suggest a solution for this ?

anu
  • 25
  • 1
  • 7
  • 2
    Possible duplicate of [how to prevent form resubmission when page is refreshed via PHP](http://stackoverflow.com/questions/6320113/how-to-prevent-form-resubmission-when-page-is-refreshed-via-php) – Manohar Khadka Jan 31 '17 at 08:01
  • 1
    some code wil help us understand your problem better – Masivuye Cokile Jan 31 '17 at 08:08

3 Answers3

2

add this line after send mail function

header("Location: " . $_SERVER['REQUEST_URI'] . "?mail=sent");
exit();

or redirect to some other page by POST method or SESSIONS variable.

Manikandan
  • 502
  • 1
  • 7
  • 17
0

I would redirect to a different page, by doing this you can show the user the mail was send successfully. If this isn't possible make sure the $_POST or $_GETparameters are unset.

bjorvack
  • 59
  • 2
  • 4
0

you need to put the mail function: mail() inside the conditional loop who processes the mail as if not the mail function will keep sending email at each page refresh or each time submit btn is clicked! undesirable off-course. Show us the code if you need more help.

Pellumb
  • 1
  • 2