I want to add a contact form on to my website that enables new enquires to submit an enquiry.
i only need name, email and a comments box
thanks
michael
I want to add a contact form on to my website that enables new enquires to submit an enquiry.
i only need name, email and a comments box
thanks
michael
Last edited by biomike; 12-10-2008 at 05:52 PM. Reason: update
As you did not specify how you would like to view the comments etc. i have done it with the mail function and mysql:
If the method is other than that in the script, Please tell me and I will modify the script to your requirements.PHP Code:<?php
// Thomas Golding (hmsnacker123) (C) 2008
if(!$_POST['submit']){
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n";
echo "<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo "<tr><td>Name: </td><td><input type=\"text\" name=\"name\" /></td></tr>\n";
echo "<tr><td>Email: </td><td><input type=\"text\" name=\"email\" /></td></tr>\n";
echo "<tr><td>Comments: </td><td><textarea name=\"comments\" cols=\"40\" rows=\"5\"></textarea></td></tr>\n";
echo "<tr><td>Type:</td><td><select name=\"type\"><option value=\"1\">mail()</option><option value=\"2\">mysql</option></select></td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Submit\" /></td></tr>\n";
echo "</form>\n";
echo "</table>";
}else {
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$type = $_POST['type'];
if($name && $email && $comments && $type){
if($type == 1){
//If you choose the mail function
$to = "youremail@yourserver.com";
$subject = "Contact form";
$message = "You have comments off ".$name.", His/Her email is ".$email.", The comments are: ".$comments."";
mail($to, $subject, $message);
}
if($type == 2){
$conn = mysql_connect('localhost','username','password');
mysql_select_db('dbname', $conn);
$sql = "INSERT INTO table_name (`name`,`email`,`comments`) VALUES ('$name','$email','$comments')";
$res = mysql_query($sql) or die(mysql_error());
}
}else {
echo "Please supply all the fields.";
}
}
?>
Hi,
You will have to first create a form with these fields and then download formmail.php and link to this form. If you will type ‘download formmail.php’ on Google you will get this file along with the instructions for how to use it.
Cheers,
~Maneet Puri
Lexolution IT Services
Web Development Company
The following pages might help
Email Form 'HowTo's
PHP Form to email
Thanks hmsnacker123
It's not working. I am not receiving the email with the details. Also when you submit the form you then go to a blank page plus i was doing it in firefox and the blank page appeared on IE.
I have created the following form in my html document
I have updated your php code as follows called formmail.php.Code:<!-- STEP 1: Put the full URL to formmail.php on your website in the 'action' value. --> <form method="post" action="http://www.bioenergyhealing.org.uk/formmail.php" name="QuestionForm"> <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER"> <!-- STEP 2: Put your email address in the 'recipients' value. Note that you also have to allow this email address in the $TARGET_EMAIL setting within formmail.php! --> <input type="hidden" name="recipients" value="msc@bioenergyhealing.org.uk" /> <!-- STEP 3: Specify required fields in the 'required' value --> <input type="hidden" name="required" value="email:Your email address,name:Your name" /> <!-- STEP 4: Put your subject line in the 'subject' value. --> <input type="hidden" name="subject" value="Question FormMail" /> <font class=content> <p style="margin-top: 0; margin-bottom: 0" align="center"><strong><font face="Arial" size="2">Directions:</font></strong><font face="Arial" size="2"> Please type in your question below, then click the </font></p> <p style="margin-top: 0; margin-bottom: 0" align="center"><font face="Arial" size="2"> <strong>“Here's my question, Michael!”</strong> button below.</font></p> </font> <table border="0" cellspacing="5%"> <tr> <td valign="top" colspan="2"> <font class=content> <textarea name="mesg" rows="10" cols="50"></textarea> </font> </td> </tr> <tr> <font class=content> <td> <p><font size="3" face="Arial">Please enter your name:</font></p> </td> <td><font size="3" face="Arial"><input type="text" name="name" /> </font> </td> </font> </tr> <tr> <font class=content> <td> <p><font size="3" face="Arial">Please enter your email address:</font></p> </td> <td><font size="3" face="Arial"><input type="text" name="email" /> </font> </td> </font> </tr> <tr> <td colspan="2" align="center"> <table border="1" bordercolor="#000000" bgcolor="#EC4D00"> <tr> <td bgcolor="#EC4D00" bordercolor="#EC4D00"> <font class=content> <input type="submit" value="Here's my question Michael!" /> </font> </td> </tr> </table> </td> </tr> </table> </form>
Thanks MichaelPHP Code:<?php
// Thomas Golding (hmsnacker123) (C) 2008
if(!$_POST['submit']){
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n";
echo "<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo "<tr><td>Name: </td><td><input type=\"text\" name=\"name\" /></td></tr>\n";
echo "<tr><td>Email: </td><td><input type=\"text\" name=\"email\" /></td></tr>\n";
echo "<tr><td>Question: </td><td><textarea name=\"mesg\" cols=\"40\"
rows=\"5\"></textarea></td></tr>\n";
echo "<tr><td>Type:</td><td><select name=\"type\"><option value=\"1\">mail()</option><option
value=\"2\">mysql</option></select></td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Here's my
question Michael!\" /></td></tr>\n";
echo "</form>\n";
echo "</table>";
}else {
$name = $_POST['name'];
$email = $_POST['email'];
$question = $_POST['question'];
$type = $_POST['type'];
if($name && $email && $question && $type){
if($type == 1){
//If you choose the mail function
$to = "msc@bioenergyhealing.org.uk";
$subject = "question form";
$message = "You have questions ".$name.", His/Her email is ".$email.", The question are:
".$question."";
mail($to, $subject, $message);
}
}
?>
Last edited by Snookerman; 12-28-2009 at 01:25 PM. Reason: please use [code] tags or [php] tags
OK:
You might not have php mail set up.. use google to help you with this,
as for the script, Try this out and tell me if it helps you:
PHP Code:<?php
// Thomas Golding (hmsnacker123) (C) 2008
ob_start();
if(!$_POST['submit']){
if(isset($_GET['msg']))
echo $_GET['msg'];
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n";
echo "<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo "<tr><td>Name: </td><td><input type=\"text\" name=\"name\" /></td></tr>\n";
echo "<tr><td>Email: </td><td><input type=\"text\" name=\"email\" /></td></tr>\n";
echo "<tr><td>Question: </td><td><textarea name=\"mesg\" cols=\"40\" rows=\"5\"></textarea></td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Here's my question Michael!\" /></td></tr>\n";
echo "</form>\n";
echo "</table>";
}else {
$name = $_POST['name'];
$email = $_POST['email'];
$question = $_POST['mesg'];
if($name && $email && $question){
//If you choose the mail function
$to = "msc@bioenergyhealing.org.uk";
$subject = "question form";
$message = "You have questions ".$name.", His/Her email is ".$email.", The question are:".$question."";
mail($to, $subject, $message);
}
}
ob_end_flush();
?>
Were getting there. I am know getting the email with the question. However the form is on the php page when i need it on the html page http://www.bioenergyhealing.org.uk/ask_a_question3. This way the visitor doesn't have to go to another page to submit.
any suggestions
Ok well on the HTML page which is http://www.bioenergyhealing.org.uk/ask_a_question3 (I Think), I have copied the HTML for the form out of the source and changed a couple of things:
and in formail.php put:HTML Code:<form method="post" action="http://www.bioenergyhealing.org.uk/formmail.php" name="QuestionForm"> <font class=content> <p style="margin-top: 0; margin-bottom: 0" align="center"><strong><font face="Arial" size="2">Directions:</font></strong><font face="Arial" size="2"> Please type in your question below, then click the </font></p> <p style="margin-top: 0; margin-bottom: 0" align="center"><font face="Arial" size="2"> <strong>“Here's my question, Michael!”</strong> button below.</font></p> </font> <table border="0" cellspacing="5%"> <tr> <td valign="top" colspan="2"> <font class=content> <textarea name="mesg" rows="10" cols="50"></textarea> </font> </td> </tr> <tr> <font class=content> <td> <p><font size="3" face="Arial">Please enter your name:</font></p> </td> <td><font size="3" face="Arial"><input type="text" name="name" /> </font> </td> </font> </tr> <tr> <font class=content> <td> <p><font size="3" face="Arial">Please enter your email address:</font></p> </td> <td><font size="3" face="Arial"><input type="text" name="email" /> </font> </td> </font> </tr> <tr> <td colspan="2" align="center"> <table border="1" bordercolor="#000000" bgcolor="#EC4D00"> <tr> <td bgcolor="#EC4D00" bordercolor="#EC4D00"> <font class=content> <input type="submit" name="submit" value="Here's my question Michael!" /> </font> </td> </tr> </table> </td> </tr> </table> </form>
Hope that helps.PHP Code:<?php
// Thomas Golding (hmsnacker123) (C) 2008
ob_start();
if($_POST['submit']){
$name = $_POST['name'];
$email = $_POST['email'];
$question = $_POST['mesg'];
if($name && $email && $question){
//If you choose the mail function
$to = "msc@bioenergyhealing.org.uk";
$subject = "Question FormMail";
$message = "You have questions ".$name.", His/Her email is ".$email.", The question are:".$question."";
mail($to, $subject, $message);
header("Location: yoursuccesspage.html");
}else {
echo "Please supply all the fields";
}
}else {
echo "Improper use of this file.";
}
ob_end_flush();
?>
thanks hmsnacker123 for all your help it works.
Thats fine, Please thank me![]()
Bookmarks