View Full Version : PHP and HTML Contact box: how much for it
london11
February 19th, 2007, 06:12 AM
Hi there
I would like some one to help me with a contact box for my website. when you submit an email that i not filed i want it to give an errror message to go back and fill in the blank filed. once submited i want it to take them to a page that say thank you for submiting, once that is done they get taken automaticaly to the home page.
evildrummer
February 19th, 2007, 06:56 AM
Well here is the code I have on my one which works fine, just change the parts that are different for you such as e-mail etc.
The HTML FORM:
<form action="send.php" method="post">
Name:
<input type="text" name="name"/>
<br />
E-Mail:
<input type="text" name="email"/>
<br />
Message:<br />
<textarea name="message" cols="60" rows="7"></textarea>
<br />
<input type="submit" name="submit" value="Send Message!" />
</form>
then in send.php have:
<?php
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
if(isset($_POST['submit'])) {
$to = "webadmin@woprid.com";
$subject = "Contact From";
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$time = time();
$status = "Attempted to send message at: $time";
mail($to, $subject, $body);
} else {
$status = "Message Failure! Please wait 10 minutes then try again, if the error persists you may contact the web admin at webadmin@woprid.com.";
}
?>
To have it auto go back to the home page I think you could add:
header(location: http://www.example.com/);
london11
February 19th, 2007, 10:20 AM
HI there
thanks for that i will try it today
london11
February 19th, 2007, 10:25 AM
were do i add header(location: http://www.example.com/); part
evildrummer
February 19th, 2007, 10:30 AM
the end of the send.php before the ?> but so send.php becomes:
<?php
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
if(isset($_POST['submit'])) {
$to = "webadmin@woprid.com";
$subject = "Contact From";
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$time = time();
$status = "Attempted to send message at: $time";
mail($to, $subject, $body);
} else {
$status = "Message Failure! Please wait 10 minutes then try again, if the error persists you may contact the web admin at webadmin@woprid.com.";
}
header(location: "http://www.example.com/");
?>
london11
February 19th, 2007, 05:56 PM
it works but when you dont fill in the fileds and you send the mail it sends you an empty email. this will mean people can spam your website and send you a lot of emails with just one click
can you help me
evildrummer
February 19th, 2007, 06:21 PM
You can check if You can check if the variables are set, I think you could do something such as:
<?php
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$valid = 0;
if (isset($name_field)) {
$valid++;
}
if (isset($email_field)) {
$valid++;
}
if (isset($message)) {
$valid++;
}
if($valid == 3;) {
$to = "webadmin@woprid.com";
$subject = "Contact From";
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$time = time();
$status = "Attempted to send message at: $time";
mail($to, $subject, $body);
} else {
$status = "Message Failure! Please wait 10 minutes then try again, if the error persists you may contact the web admin at webadmin@woprid.com.";
}
header(location: "http://www.example.com/");
?>
london11
February 20th, 2007, 08:52 PM
HI there
could you do it for me and i could pay you somthing
evildrummer
February 21st, 2007, 06:32 AM
nah, you dont need to, when I get back tonight ill just make a contact box for you for FREE, just post all the requirements you need.
london11
February 21st, 2007, 08:45 AM
ok thanks
Name email and comment
evildrummer
February 21st, 2007, 08:50 AM
ok, should be long, ill do it tonight, im off to the cinema now :tb:
london11
February 21st, 2007, 09:23 AM
ok thank you so much
london11
February 22nd, 2007, 11:40 AM
any chance of the contact form
evildrummer
February 22nd, 2007, 03:57 PM
ok, yeah forgot, I was ill but here it is:
form.html (or whatever file its in):
<form action="send.php" method="post">
Name:
<input type="text" name="name"/>
<br />
E-Mail:
<input type="text" name="email"/>
<br />
Comment:<br />
<textarea name="message" cols="60" rows="7"></textarea>
<br />
<input type="submit" name="submit" value="Send Message!" />
</form>
and then send.php:
<?php
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
if($name_field == '' || $email_field == '' || $message == '') {
echo 'ERROR!!!!!';
//insert extra error code if needed
} else {
$to = "webadmin@woprid.com";
$subject = "Contact From";
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$time = time();
$status = "Attempted to send message at: $time";
mail($to, $subject, $body);
header(location: "http://www.example.com/");
}
?>
change teh e-mail adress and also the forward adress!
london11
February 22nd, 2007, 07:23 PM
i will try it out today thanks for that
evildrummer
February 23rd, 2007, 11:48 AM
Does it work?
london11
February 24th, 2007, 06:33 PM
their is still a slight problem
evildrummer
February 24th, 2007, 06:36 PM
Whats the problem?
london11
February 27th, 2007, 08:39 PM
sorry i took long to reply quit busiey with uni it seem to me that it dosent work when i click on the submit button iand have not enter any fileds it still submits it is meant to give me a error saying i have to fill in the filds before you can submit.
thank you for your help
evildrummer
February 28th, 2007, 08:33 AM
Ok, maybe this send.php might work:
<?php
if(isset($_POST['name']) || isset($_POST['name']) || isset($_POST['name'])) {
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$to = "webadmin@woprid.com";
$subject = "Contact From";
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$time = time();
$status = "Attempted to send message at: $time";
mail($to, $subject, $body);
header(location: "http://www.example.com/");
} else {
echo 'ERROR!!!!!';
//insert extra error code if needed
}
?>
london11
February 28th, 2007, 07:43 PM
do you have the compleate code with the html thamks man
LooInSpain
March 1st, 2007, 04:22 AM
Here is the one I use for one of my websites:
html code:
<p class="style3">Please complete our form and click the SUBMIT button to send us an email with your details and requirements. We will contact you as soon as possible.</p>
<FORM ACTION="contact.php" METHOD=POST>
<p align="left" class="style5 style2">Name <INPUT TYPE="text" NAME="name" SIZE="30"></p>
<p align="left" class="style5 style2">E-Mail Address <INPUT TYPE="text" NAME="email" SIZE="30"></p>
<p align="center" class="style2">
<INPUT name="Submit" TYPE="Submit" value="Submit">
<INPUT TYPE="reset">
</p
and a seperate php sheet entitled contact.php
<?php
$mailto = 'you@youremail.com';
$subject = "Email Title" ;
$formurl = "http://www.yoursite.com/contact.html" ;
$errorurl = "http://www.yoursite.com/error.html" ;
$thankyouurl = "http://www.yoursite.com/thanks.html" ;
$uself = 0;
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) ) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" );
header( "Location: $thankyouurl" );
exit ;
?>
With this you need to create seperate error and thanks pages whether they enter all the info needed or not. Once all the data has been completed they will get the thanks message and you will receive an email with their name and email as they have filled in.
If you need extra input boxes just copy one of those in the html code and change the NAME of it, then make sure you copy that onto the php sheet as well.
Let me know if this is what you needed.
london11
March 2nd, 2007, 12:04 PM
i will try it out today thanks people
xoxspankyxox
March 7th, 2007, 01:45 PM
I am new to these sort of thing so i am not so sure how to go about this.
I am looking for a code to use in my website as a form of contact/feedback code
i have seen many. i also have made one myself or updated one for a friend for her site
i am not so sure i understand where i need to put the email addy at to where i want the replies an so forth done. I was wondering if this is differnt for html codes as it is for php type code.
could someone offer me some assistance??
london11
March 8th, 2007, 11:37 AM
this is were you add your email code:
<?php
$mailto = 'you@youremail.com'; when they fill in the contact box, this part of the code will send it to your email code. just change that part 'you@youremail.com'
london11
March 8th, 2007, 11:38 AM
i have done my one it works now i had to code it my self cool
xoxspankyxox
March 9th, 2007, 05:49 AM
Thank you so much for the help. I will be trying this out in the next couple days to see if it works.
also another ?
does this code still work if i do not use php script?
i would just add a contact.php along with one for
contact.html
correct?
Just want to make sure before i add everything.
And thank you again for the help:pleased:
london11
March 13th, 2007, 09:13 PM
the code above which is give works just needs a bit of ajustment to it and you should be fine
london11
March 13th, 2007, 09:14 PM
did ur contact box work did u try it
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.