Forum Moderators: coopster

Message Too Old, No Replies

Contact Form Inputs Don't Work After Switching from Tables To Css

php contact form

         

mehdi

5:37 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



I get an e-mail but the subject header, from header and body are all empty.

HTML


<form action="email.php">
<div>
<p><label for="name">Name</label> <input type="text" id="name" /></p>
<p><label for="email">e-mail</label> <input type="text" id="email" /></p>
<p><label for="subject">Subject</label> <input type="text" id="subject" /></p>
<textarea title="Write your message here" name="message" id="message" cols="60" rows="10">
</textarea>
<p class="submit"> <input type="submit" value="Submit" />
</p>
</div>
</form>

PHP


<?php

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: webmaster@example.com\r\n";
$headers .= "Reply-To: webmaster@example.com\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

//CHANGE ME!
$to = 'testing@testing.com, testing2@testing.eu'; //Email address the comment will

$fromn = $_POST['name'];
$frome = $_POST['email'];
$subject = $_POST['subject'];

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromn <$frome>\r\n";
$headers .= "Reply-To: $fromme\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$content = str_replace("\n.", "\n..", $_POST['content']);
$content = "From $fromn :: $frome \n \n" . $content;

mail("".$to."", $subject, $content, $headers);

?>

Thank you. We will contact you shortly.

d40sithui

5:49 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



instead of:
<input type="text" id=...

have you tried using:
<input type="text" name=...

mehdi

6:23 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



Thanks but it still doesn't work.

jatar_k

6:27 pm on Aug 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld mehdi,

have you tried dumping the post to see what is actually there?

like so

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

jatar_k

6:36 pm on Aug 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



add the name attribute as suggested and also try adding method="post" to your form tag

mehdi

7:08 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



Thanks for the welcome.

Like this?


<form method="post" action="email.php">

The subject line is now displayed but From and the body are still empty. How do I dump a post?

jatar_k

7:10 pm on Aug 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> Like this?

yes

>> How do I dump a post?

using the code I posted on your script that does the mailing

I tested using this
<form method="post" action="cssformproc.php">
<div>
<p><label for="name">Name</label> <input type="text" name="name" id="name" /></p>
<p><label for="email">e-mail</label> <input type="text" name="email" id="email" /></p>
<p><label for="subject">Subject</label> <input type="text" name="subject" id="subject" /></p>
<textarea title="Write your message here" name="message" id="message" cols="60" rows="10">
</textarea>
<p class="submit"> <input type="submit" value="Submit" />
</p>
</div>
</form>

and the cssformproc.php file was only this

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

it worked once I added the 2 things mentioned element names and the form method

mehdi

7:48 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



This is the result of the dump :

Array
(
[name] => Mehdi
[email] => test@test.com
[subject] => This Better Work
[message] => It doesn\'t.
)

I then removed :

<form method="post" action="cssformproc.php">

and replaced it with :

<form method="post" action="email.php">

and used the code you list above :


<form method="post" action="email.php">
<div>
<p><label for="name">Name</label> <input type="text" name="name" id="name" /></p>
<p><label for="email">e-mail</label> <input type="text" name="email" id="email" /></p>
<p><label for="subject">Subject</label> <input type="text" name="subject" id="subject" /></p>
<textarea title="Write your message here" name="message" id="message" cols="60" rows="10">
</textarea>
<p class="submit"> <input type="submit" value="Submit" />
</p>
</div>
</form>

Still doesn't work. I ran the form on two domains. On domain one I get :

Subject, date, to. Empty from header and no body.

On domain two I get :

Subject, from, date, to. Empty body.

Chmod is set to 755 for the email.php form.

jatar_k

7:56 pm on Aug 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



empty body seems to be because you use $_POST['content'] in your script and the textarea is actually named message so you should use $_POST['message'], sorry I missed this originally

it not working on the first domain is strange, the second domain seems to be doing what it should

<added>I see you edited while I was posting, the missing from, could be a different setting if you are using the exact same code

mehdi

8:39 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



Awesome. It's working fine on both domains. The only issue now is that :

'

displays as :

'\

And the form doesn't recognise line returns e.g.

In a few seconds I will reach the end of the line and start a new paragraph.

This is the new paragraph.

Shows up as :

In a few seconds I will reach the end of the line and start a new paragraph. This is the new paragraph.

jatar_k

8:44 pm on Aug 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



smells like magic quotes might be on, hate that

you could parse the content from the textarea and change \n to \r\n to see if that makes any difference

try using str_replace [php.net]

mehdi

10:27 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



I changed this :

$content = str_replace("\n.", "\n..", $_POST['message']);

to this :

$content = str_replace("\r\n.", "\r\n..", $_POST['message']);

But it didn't have an effect. I take it this is a common problem? If so I'll just have to put up with it.

mehdi

2:00 am on Aug 8, 2007 (gmt 0)

10+ Year Member



One final problem. When I click in the message box for some reason the cursor starts on the second line. It's annoying as hell. What's causing this?


<form method="post" action="email.php">
<div>
<p><label for="name">Name</label> <input type="text" name="name" id="name" /></p>
<p><label for="email">e-mail</label> <input type="text" name="email" id="email" /></p>
<p><label for="subject">Subject</label> <input type="text" name="subject" id="subject" /></p>
<textarea title="Enter your message here" name="message" id="message" cols="60" rows="10">
</textarea>
<p class="submit"> <input type="submit" value="Submit" />
</p>
</div>
</form>

jatar_k

3:23 am on Aug 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



look up the wrap attribute for textarea, there are different settings for it and I can't remember what they are but they have some different effects inregards to newlines

the reason your cursor is on the second line is because you have a hard return in there

change
<textarea title="Enter your message here" name="message" id="message" cols="60" rows="10">
</textarea>

to
<textarea title="Enter your message here" name="message" id="message" cols="60" rows="10"></textarea>

mehdi

4:43 pm on Aug 11, 2007 (gmt 0)

10+ Year Member



Thanks.