If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Form Data not displaying in Email, using send mail

Hi Everyone,

I am new to PHP and my first asignment was to try and send form data from an html page to an email id using a php script. The form reached the email id, however, the contents of the fields do not display. The filed description though shows up. What could be the problem? I have attached the script below. The same script worked on another linux server before. Any help is appreciated here.

It appears that the values of your variables ($name, $company, $address, etc.) are not being set. The script may have worked on another server that had "register globals" enabled. This setting is now disabled by default as it poses certain security risks.

You can set the values to those posted to the script by using the $_POST array in the following manner.

While debugging similar issues it helps to add a few debugging function calls to your code so you can see what's going on without having to check any emails or even wait for the entire script to execute.

var_dump($body);
die;

placing this before the mail is sent would display the contents of the body variable and terminate the script allowing you to see that the values were missing without having to send an email.

var_dump($company);
die;

would show the type and data, if any of the $company variable to confirm that it indeed has not been assigned a value.

Just GLANCED at your script - if it WORKED on a different machine, I'd first of all put the message and header terminations into a proper "look", by using "\r\n", which is mandatory to make sure that email() can even HANDLE it (depending on your environment). I'm not kidding, try this first.

Best from the south.

P.S. And add "wordwrap($message,70);", for most readers otherwise truncate the content...

Thanks for your reply. I tried what you said and placed your suggested code above "$to = "test@yahoo.com";
$too = "test@yahoo.com";
$subject = "Contact: test";
$from = $email;"......and so on..... in my code (hope that is the correct position to place). But it still did not work. Can you tell me where I should place correctly so that it works. As I mentioned earlier , I am absolutely new to PHP and borrowed this code from someone else.

Thanks,

Saktiyantra.

Originally Posted by tfk11

It appears that the values of your variables ($name, $company, $address, etc.) are not being set. The script may have worked on another server that had "register globals" enabled. This setting is now disabled by default as it poses certain security risks.

You can set the values to those posted to the script by using the $_POST array in the following manner.

While debugging similar issues it helps to add a few debugging function calls to your code so you can see what's going on without having to check any emails or even wait for the entire script to execute.

var_dump($body);
die;

placing this before the mail is sent would display the contents of the body variable and terminate the script allowing you to see that the values were missing without having to send an email.

var_dump($company);
die;

would show the type and data, if any of the $company variable to confirm that it indeed has not been assigned a value.

Thanks for your reply. Since I am new to PHP, I could not follow your suggestions. Is it possible for you to correct the code and give me please?

Regards,

Saktiyantra

Originally Posted by ariell

Just GLANCED at your script - if it WORKED on a different machine, I'd first of all put the message and header terminations into a proper "look", by using "\r\n", which is mandatory to make sure that email() can even HANDLE it (depending on your environment). I'm not kidding, try this first.

Best from the south.

P.S. And add "wordwrap($message,70);", for most readers otherwise truncate the content...

If it worked on another server and doesn't work on the new server then I would look at server configurations to give you a clue. I'm guessing this is old code from pre 'register globals off' days. If the new server has them turned off (as it should) then you need to refer to POSTed variable in the superglobal $_POST['posted_var']

For testing purposes ONLY add this to the top of your scripts

PHP Code:

ini_set('register_globals', 1);

If the form now works, rewrite the vars to use the correct $_POST way of calling on them. It's a mighty bad idea to leave this hack/testcode in place.

To debug, remove the entire mail code and simply print_r($_POST) until you are sure you're getting the variables to the script.

Last edited by SyCo; 10-23-2008 at 10:41 AM.

Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

I hope this was correct. Also I still did not receive the form data in my email. Earlier the autoresponder was not working, but with the change in code as above, autoresponder started working.

Can you advice here please? Also please note that I am a novice to PHP and you are explaining to an absolute beginner who has borrowed this code from elsewhere .

Thank You,

Saktiyantra.

Originally Posted by SyCo

If it worked on another server and doesn't work on the new server then I would look at server configurations to give you a clue. I'm guessing this is old code from pre 'register globals off' days. If the new server has them turned off (as it should) then you need to refer to POSTed variable in the superglobal $_POST['posted_var']

For testing purposes ONLY add this to the top of your scripts

PHP Code:

ini_set('register_globals', 1);

If the form now works, rewrite the vars to use the correct $_POST way of calling on them. It's a mighty bad idea to leave this hack/testcode in place.

To debug, remove the entire mail code and simply print_r($_POST) until you are sure you're getting the variables to the script.