hey guys, Let me please describe the situation: I have a contact form in my website which sends emails every time a person fills out the form. then , it should also insert the data into mysql database. unfortunately , it does not work - not sending the form and does not insert into the database. can you guys please take a look at both my html and php scripts and let me know what you think ? I would greatly appreciate it. here is the html: <script type="text/javascript" language=JavaScript src=Validation.js></script> <table width="230" height="180" cellpadding="4" cellspacing="0" border="0" dir=rtl align=left bgcolor=#fffffff style="border: solid 1px #164976"> <form method=post name="frmEmail" action="Test123.php" onsubmit="javascript:return CheckForm('frmEmail')"> <tr> <td colspan=3 align="right" height=10 valign="top" class="leadFromTop"><b>Contact us</b></td> </tr> <tr> <td colspan=3 align="right" class="leadTextNN11"> Please contact us:<br> <br> </td></tr> <tr> <td width=80 class="purpleTextN"> name: <font color='red'>*</font> </TD> <td width=5></td> <td align="left"><input class="inputShort" type="text" id="txtName" name="txtName"></td> </tr> <tr> <td class="purpleTextN">phone: <font color='red'>*</font> </TD> <td width=5></td> <td align="left"><input class="inputShort" type="text" id="txtPhone" name="txtPhone"></td> </tr> <tr> <td class="purpleTextN">email</td> <td width=5></td> <td align="left"><input class="inputShort" type="text" id="txtEmail" name="txtEmail" ></td> </tr> <tr> <TD class=purpleTextN noWrap align=left><nobr>Subject <font color='red'>*</font> </nobr></TD> <TD align=middle colSpan=3> <SELECT class=inputList id="ddlSubject" name="ddlSubject"> <option value="" selected>select</option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </SELECT> </TD> </tr> <tr> <td class="purpleTextN">Content</td> <td width="5" nowrap></td> <td class="purpleTextN"><textarea name="txtcontent" id="txtcontent" class="select210" rows="2" cols="20"></textarea></td> </tr> <tr> <td colspan=3 align="right" class="leadTextNN11"> <br> </td></tr> <tr> <td colspan=3 align=center> <input class="" type="button" name="Submit" value="send" onclick="CheckForm('frmEmail');return false";"> </td></tr> </table><br> </form> here is the php: <?php $name = $_POST['txtName'] ; $phone = $_POST['txtPhone'] ; $email = $_POST['txtEmail'] ; $Subject = $_POST['ddlSubject'] ; $Content = $_POST['txtcontent'] ; mail( "emailtosendtheform", "Example feedback", $name , $phone, $email , $Subject ,$Content "From: $email" ); header( "Location: http://www.example.com/thankyou.html" ); // Make a MySQL Connection mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("databasename") or die(mysql_error()); // Insert a row of information into the table "tablename" mysql_query("INSERT INTO tablename (name, phone , email , Subject , Content) VALUES ('$_POST[name]','$_POST[phone]','$_POST', '$_POST[Subject]', '$_POST[Content]')"; or die(mysql_error()); echo "Data Inserted!"; ?>
Are you getting any errors? Your mail() function call needs to be fixed, unless you just changed that to remove your email address.
do you refer to "emailtosendtheform" ? Yes , I just changed that to remove myemail address. I do getting errors , do you have any idea why? Thank you.
whats the error are you getting? take note that if you are developing this on your local pc at home, (i mean not on the real server), theres a chance the email will not come out.. you have to have a mail server.
of course I do I have an hosting account in which I'm playing with. It just says "error in line 17" or similar. it does not specify anything. thank you.
your table name is really tablename? one more thing, try to change (name, phone , email , Subject , Content) to ('name', 'phone' , 'email' , 'Subject' , 'Content')
it is not really tablename of course I created a real table. regarding changing (name, phone , email , Subject , Content) to ('name', 'phone' , 'email' , 'Subject' , 'Content') : in this tutorial http://www.tizag.com/mysqlTutorial/mysqlinsert.php is says otherwise. any other ideas? thanks for your help.
so have you check what is the code at line 17? check your database connection. Maybe it's the source of the problem
i just read the code, and look what i found! lol mail( "emailtosendtheform", "Example feedback", $name , $phone, $email , $Subject ,$Content "From: $email" ); header( "Location: http://www.example.com/thankyou.html" ); This is wrong. Refer to this http://fr2.php.net/manual/en/function.mail.php to get a good example of how using the mail function. $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: ' . "\r\n" . 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); And you use header function just before the query to the database, thats kinda wrong to. If you call that header function, it will redirect you to the page you specified. Thus, the code below it will not be executed.