|
-
Apr 5th, 2009, 06:20 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] PHP Form Issue
Hi all,
Just wondering if someone could possibly help me with the following:
I have a simple web form:
Code:
<form id="form1" action="" name="form1" class="form" method="post">
<p class="textarea"><input type="text" name="email" value="email address"/>
<input type="submit" name="button" id="button" value="Submit" />
</form>
And at the very top of the page I have the following PHP code:
<?php
$to = "[email protected]";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
?>
The problem that I have is that the form is sending me emails even when the page has simply been loaded (less the users email). Can somebody please assist me in resolving this.
Many thanks
-
Apr 5th, 2009, 06:39 PM
#2
Re: PHP Form Issue
it's sending you emails because every single time you load that page, it's calling the mail() function. if you only want to send an email when the form is posted to, you can do this:
PHP Code:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
$to = "[email protected]";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
}
?>
and also, please use [php] and [/php] tags around your code ;)
-
Apr 6th, 2009, 03:30 AM
#3
Thread Starter
Hyperactive Member
Re: PHP Form Issue
Hi,
Thanks for that...much appreciated
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|