Home > Archive > PHP DB > April 2006 > Example of mail()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Renzo Clavijo 2006-04-28, 7:58 am |
| Hi all.
In the code bellow you'll find an easy to use example of mail().
I know it's very simple but the question is: How can I erase the
values held in $_REQUEST such that when I press F5 or I click "Reload"
there are no messages sent again?
Thanks a lot for your help.
Best Regards
RENZO CLAVIJO
PD: Please forgive me if my english is not OK
--------------
<html>
<head>
<title>Correo</title>
</head>
<body>
<form name="form_send" method="post" target="<?php echo $_REQUEST['PHP_SELF'];?>">
Address: <input type="text" name="address_mail" size="20">
<br>
Subject: <input type="text" name="subject" size="20">
<br>
Message: <input type="text" name="message" size="20">
<br>
<input type="submit" name="send_mail" value="Enviar">
</form>
</body>
<?php
if(isset($_REQUEST['send_mail'])){
mail($_REQUEST['address_mail'],$_REQUEST
['subject'],$_REQUEST['message']);
}
?>
</html>
---------------------------------
Blab-away for as little as 1¢/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice.
| |
| benmoreassynt 2006-04-28, 6:57 pm |
| Renzo Clavijo wrote:
> <?php
> if(isset($_REQUEST['send_mail'])){
> mail($_REQUEST['address_mail'],$_REQUEST
['subject']
$_REQUEST['message']);
> }
I would try something like this:
if(isset($_REQUEST['send_mail']))
{
mail($_REQUEST['address_mail'],$_REQUEST
['subject']
$_REQUEST['message']);
unset($_REQUEST);
}
That should wipe all the variables in $_REQUEST before the user clicks
reload. It will not work on a global variable if you use it inside a
function. There are other ways to do the same thing, but I think that
should do it.
BMA
| |
| benmoreassynt 2006-04-28, 6:57 pm |
| benmoreassynt wrote:
> I would try something like this:
>
>
> if(isset($_REQUEST['send_mail']))
> {
> mail($_REQUEST['address_mail'],$_REQUEST
['subject']
> $_REQUEST['message']);
> unset($_REQUEST);
> }
As a follow up, if you want to use that in a public environment, you really
need to run the $_REQUEST array through something like strip_tags() at the
very least, and probably write your script in such a way that nobody can
inject headers into the form for spamming. The archives of the PHP mailing
list include ways to do it.
BMA
| |
|
|
Hi,
Why not use cookies to check if the user has pressed F5 or refreshed the page? There is a number of ways to do this, all should work effectively depending on your how many people hit the page etc.
a) Store the message in a cookie, and run PHP code to check before executing the mail() function. If the message matches after a refresh than don't execute the mail() function. You could display the message again in the box or setup a error reporting
message saying you cannot refresh the page or send the same message twice.
b) Everytime the page is loaded (whatever.php) from a weblink or something have a hidden field like id=rand() ... Use a random generator to randomly uissue lets say a 12 char legnth. So if the user refreshes the hidden field would be the same hence no
mail() execution. However if the page is loaded from a weblink the php issues a new code.
c) I did have a c.. but forgot. Look up the following on google "checksum or chksum"
Anyways. There is more ways but it's time for me to hit the sack(). :P
J
|
|
|
|
|