Forum Moderators: coopster

Message Too Old, No Replies

can't get this mail form to submit.

php mail

         

generic

11:14 am on Jan 8, 2008 (gmt 0)

10+ Year Member



Hi, I'm having trouble getting this working. It's probably something simple as I'm more of a graphics guy than a code guy but anyway... any help would be appreciated.

<?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

hoxspeed

12:52 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



mail($to, $subject, "$name\n$phone\n$email\n$query");

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]

generic

6:13 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Thanks for the reply. It is pretty nasty looking code lol

I tried your suggestion but still no luck. For some reason, when I click the submit button, it does nothing - it won't even submit to give me an error to troubleshoot with, it just sits like I didn't submit it at all.

Any other ideas?

jatar_k

6:21 pm on Jan 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you view source on the form in your browser what do you see?

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?

jatar_k

6:22 pm on Jan 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



for testing purposes you could just dump the $_POST array at the very top of the page like this

echo '<pre>';
print_r($_POST);
echo '</pre>';

generic

6:25 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



I took a look at the source and the form action is coming up properly. I even tried to hardcode the file itself into the action and it didn't work either. This is a new version of a site, but I have gotten some PHP errors already that I worked out, so it's not an error issue that I can tell. This is so weird... It should at least submit and tell me I suck or something but no dice.

generic

6:28 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Oh man, that was lame.. I knew it was something dumb (courtesy PHP Freaks forum):

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?