Form help again Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sroussie
Forum Newbie
Posts: 19
Joined: Wed Aug 27, 2003 12:26 pm
Location: Buffalo, NY

Form help again Please

Post by sroussie »

HI,

I have tried to obtain info from my form using php but only manage to get the Subject line and one line in the message. I cannot get any of the other fields. I even removed all fields except three and I still cannot get the last field. Everything else works. I am very new to this. I have enclosed the code I am using.

Thanks.

HTML FORM

<html>
<head>
</HEAD>

<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>

<form action="contact_small.php" method="POST">
Subject:<input type="text" name="subject" size="60" tabindex="1">
<p>Message: <textarea name="content" rows="4" cols="58" tabindex="2"></textarea></p>
<p>Name: <input type="text" name="username" tabindex="3"></p>
<p></p>
<p>
<input type="submit" name="submit" value="Submit"></p>
</form>

</body>

</html>


PHP File

<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php


$sendto = "sroussie@adelphia.net";
$subject = $_POST['subject'];
$content = $_POST['content'];
$username = $_POST['username'];


mail("$sendto","Subject: $subject","Message: $content","Name: $username");

echo 'Thank you.'

?>
</body>
</html>
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Try echoing out your variables in the PHP page. It looks like it should work, so I'm guessing the problem is in your email code... probably you've got some character in the text you're sending that needs to be escaped with addslashes() or htmlspecialchars() or one of the other handlers.
User avatar
sroussie
Forum Newbie
Posts: 19
Joined: Wed Aug 27, 2003 12:26 pm
Location: Buffalo, NY

Post by sroussie »

Hi,

I tried echoing the variables and they displayed on the screen. SO now I am really confused as to why it doesn't work.

Sue
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

While this might not change anything, try simplifying the mail() call:

Code: Select all

mail($sendto, $subject, $content, $username);
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

um, have you set a SMTP in your server? have you configured the php.ini file with it?
the mail() function won't work without setting up the smtp settings
User avatar
sroussie
Forum Newbie
Posts: 19
Joined: Wed Aug 27, 2003 12:26 pm
Location: Buffalo, NY

Post by sroussie »

w do I set the SMTP? Should I assume SMTP is working if I get the email - even though the info isn't there?

Sue
User avatar
sroussie
Forum Newbie
Posts: 19
Joined: Wed Aug 27, 2003 12:26 pm
Location: Buffalo, NY

Post by sroussie »

microthick wrote:While this might not change anything, try simplifying the mail() call:

Code: Select all

mail($sendto, $subject, $content, $username);
I tried the above and it worked. Then I added the label for subject and content. That worked. As soon as I added the label for username it stopped working. Now I just have to figure out why.

Sue
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The fourth parameter in the mail() function is for e-mail headers, so if you want the username to be part of the message then it should be added to the content.

Code: Select all

mail("$sendto","Subject: $subject","Message: $content","Name: $username");
could become

Code: Select all

$message =<<<END

Message: $content

Name: $username
END;

mail($sendto, $subject, $message);
Mac
User avatar
sroussie
Forum Newbie
Posts: 19
Joined: Wed Aug 27, 2003 12:26 pm
Location: Buffalo, NY

Post by sroussie »

Thanks much, that worked. I was kind of wondering about that myself. I understand it a lot better now. I have one last issue to resolve but I want to figure it out if I can before I ask for help.

Thanks,
Sue
Post Reply