email form help

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
jaimeg
Forum Newbie
Posts: 6
Joined: Tue Jan 21, 2003 1:59 am
Location: Albuquerque

email form help

Post by jaimeg »

I have a simple form I am learning from a book. I found out why it was not working so I corrected it to --- $_post [' variable '] --- but the message is still not printing on my email. I get the email from the sender but not the input [' variable '] they fill out.
Is their anything wrong with this code?

thank you in advance for any help

Jaime

<?

$msg = "email sent from my web site";
$msg .= "Sender's Name: $_POST['sender_name']";
$msg .= "Sender's email: $_POST['sender_email']";
$msg .= "Message: $_POST['mesage']";

$to = "my@email";
$subject = "Web Site feedback form";
$mailheaders = "From: web site\n";
$mailheaders .= "Reply-To: $sender_email\n\n";

mail ($to, $subject, $msg, $mailheaders);

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

Post by twigletmac »

Which version of PHP is the server running? To find out just run this script:

Code: Select all

<?php
echo 'Current PHP version: ' . phpversion();
?>
What do you get if you put the following into the script that handles the information from the form:

Code: Select all

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

echo '<h1>'.$HTTP_POST_VARS.'</h1>';
echo '<pre>';
print_r($HTTP_POST_VARS);
echo '</pre>';
Mac
jaimeg
Forum Newbie
Posts: 6
Joined: Tue Jan 21, 2003 1:59 am
Location: Albuquerque

Post by jaimeg »

the website is running PHP Version 4.2.2

Where in the script do I post this code?:
echo '<h1>'.$_POST.'</h1>';
echo '<pre>';
print_r($_POST);
echo '</pre>';

echo '<h1>'.$HTTP_POST_VARS.'</h1>';
echo '<pre>';
print_r($HTTP_POST_VARS);
echo '</pre>';

before the mail () or after it?

Jaime
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Post by Skywalker »

If you are running local, then maybe you have to install a mail server?

I am not sure but I think if you are running local, you have run an mail server.

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

Post by twigletmac »

Skywalker wrote:If you are running local, then maybe you have to install a mail server?

I am not sure but I think if you are running local, you have run an mail server.

Greathings Skywalker
If they are getting the mail but the variables are not being sent through then this is not the problem.

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

Post by twigletmac »

jaimeg wrote:the website is running PHP Version 4.2.2

Where in the script do I post this code? before the mail () or after it?
Put it before you do anything with the $_POST variables, so above the mail() function call.

Mac
jaimeg
Forum Newbie
Posts: 6
Joined: Tue Jan 21, 2003 1:59 am
Location: Albuquerque

Post by jaimeg »

I get the emails I just don't get the input from the fields from the senders.
name, email and message.

I get the headers that I typed.

My web site features sais it comes pre-configured with php, and since I get the emails but not the information, do I still need to check if I the sysadmin installed a mail server?

I would imagine if I did not have a mail server that I would not even get the emails. Am I wrong?

Like I said. I am brand new at this php stuff.
Any help is really appreciated.
Jaime
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You've got a mail server because you get the e-mail so don't worry about that.

Oh, just spotted something try this:

Code: Select all

$msg = 'email sent from my web site'."\n"; 
$msg .= 'Sender''s Name: '.$_POST['sender_name']."\n"; 
$msg .= 'Sender''s email: '.$_POST['sender_email']."\n"; 
$msg .= 'Message: '.$_POST['mesage']."\n";
Mac
jaimeg
Forum Newbie
Posts: 6
Joined: Tue Jan 21, 2003 1:59 am
Location: Albuquerque

that did it.

Post by jaimeg »

WOW that did it.
The form works!!! .$
NOw I can go to sleep it's 2.41 am in ALbuquerque.

thank you so very much.

Part II tomorrow, I will have to figure out how to redirect to a confirmation page and error check the form.

Thank you .. Thank you.. Thank you.

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

Post by twigletmac »

That's alright, it looks like your error reporting is either turned off, or turned down low, otherwise the code would have given you a bunch of errors, try putting this at the top of your scripts:

Code: Select all

ini_set('display_errors', TRUE);   //Print out errors (as a part of the output). 
error_reporting(E_ALL); //E_ALL  - All errors and warnings
Mac
Post Reply