Forum Moderators: coopster
<?php
if (isset($_POST['submit'])){
$to = "me@mysite.com";
$subject = "website contact";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$query = $_POST['query'];
mail($to, $subject, "$name\n$phone\n$email\n$query");
echo "<p>Success!</p>";
} else {
echo "<form id=\"contact\" name=\"contact_form\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">
<p class=\"contact_label\">Your Name:<br />
<input name=\"name\" type=\"text\" />
Your Email:<br />
<input name=\"email\" type=\"text\" />
Your Phone Number:<br />
<input name=\"phone\" type=\"text\" />
Question/Comment:<br />
<textarea name=\"query\" rows=\"4\"></textarea>
</p>
<p>
<input name=\"submit\" id=\"submit\" type=\"button\" value=\"Send It\" style=\"width: auto;\" />
</p>
</form>";
}
?>
Thanks in advance!
gen
Error must be in the above line ;
try like this
if (isset($_POST['submit'])){
$to = "me@mysite.com";
$subject = "website contact";
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$query = $_POST['query'];
$strbody="Name:".$name."\r\n Phone :".$phone."\r\n Email :".$email."\r\n Query :".$query."\r\n";
mail($to, $subject, $strbody);
echo "<p>Success!</p>";
} else {
echo "<form id=\"contact\" name=\"contact_form\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">
<p class=\"contact_label\">Your Name:<br />
<input name=\"name\" type=\"text\" />
Your Email:<br />
<input name=\"email\" type=\"text\" />
Your Phone Number:<br />
<input name=\"phone\" type=\"text\" />
Question/Comment:<br />
<textarea name=\"query\" rows=\"4\"></textarea>
</p>
<p>
<input name=\"submit\" id=\"submit\" type=\"button\" value=\"Send It\" style=\"width: auto;\" />
</p>
</form>";
}
?>
Anyway above code can be be optimized, above codes seems to be very unprofessional code. as you said you are beginer so no worry, keep it up
Gurmukh Singh
[edited by: jatar_k at 1:00 pm (utc) on Jan. 8, 2008]
[edit reason] no sigs thanks [/edit]
does the form action get written properly?
is it parsing the php properly?
maybe you could start by validating the html of the form
you could also look to see if errors are turned on to make sure it isn't dying silently. Have you seen php errors in your browser on this site before?
Find:
<input name=\"submit\" id=\"submit\" type=\"button\" value=\"Send It\" style=\"width: auto;\" />
Replace
<input name=\"submit\" id=\"submit\" type=\"submit\" value=\"Send It\" style=\"width: auto;\" />
It's always the little things. Wow, I'm gonna go buy a book :) Thanks for all the help.
Any ideas on optimizing this code?