Forum Moderators: coopster

Message Too Old, No Replies

Move from php 4 to 5 problem

         

chrissyboy2000

4:04 pm on May 29, 2009 (gmt 0)

10+ Year Member



A couple of weeks ago, my host moved us on to a new shared server and since then, our customer info request form has stopped working.

I still receive the email ok but it doesn't contain any of the data a visitor has entered.

I spoke to my host today and they have said its probably a coding issue as the old server was php 4 and the new one is php 5.

Truth is, I don't know any php at all... I created this from a free to use script which I hacked around with until it worked properly so haven't a clue how to fix it.

The php file (with text shortened and email address and personal details subbed out) is as follows:

<? mail("$email","Information request","Hello!

Thank you for requesting further information. snipped here ", "From: me@example.com\n");

mail("me@example.com", "Please send me wholesale catalogues", "The following catalogue(s) have just been requested: $cat1$cat2$cat3$cat4

Title: $title
First name: $firstname
Surname: $surname

Company: $companyname
Established: $year

Address 1: $address1
Address 2: $address2
Town: $town
Postcode: $postcode

Telephone: $telephone
Fax: $fax
Email: $email

Comments: $comments", "From: me@example.com\n");

echo"<meta http-equiv='refresh' content='0;URL=http://www.example.com/catalogue-requested.htm'>";
?>

The line of code from the html page that calls this is:

<FORM method="post" action="http://www.example.com/MailingList.php" onsubmit="return formCheck(this);">

Many thanks for any suggestions and apologies if its something blatantly obvious... I guess I should learn php but there never seems enough time!

[edited by: dreamcatcher at 6:43 pm (utc) on May 29, 2009]
[edit reason] use example.com. Thanks. [/edit]

idfer

5:06 pm on May 29, 2009 (gmt 0)

10+ Year Member



What probably happened is that in the old server, register_globals was set to ON, so all the data from the form was automatically loaded into global variables. In the new server, this feature is turned off, so you have to explicitly assign the variables from the $_POST super-global (much more secure).

Without seeing the entire form, it's hard to tell what statements you need exactly but i'll guess all the variables in your script come from form elements, so... add this to the top of your script (right after the <? and before the first call to mail()), and give it a go:

$email = $_POST['email'];
$cat1 = $_POST['cat1'];
$cat2 = $_POST['cat2'];
$cat3 = $_POST['cat3'];
$cat4 = $_POST['cat4'];
$title = $_POST['title'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$companyname = $_POST['companyname'];
$year = $_POST['year'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$town = $_POST['town'];
$postcode = $_POST['postcode'];
$telephone = $_POST['telephone'];
$fax = $_POST['fax'];
$comments = $_POST['comments'];

Hope this helps.

chrissyboy2000

5:42 pm on May 29, 2009 (gmt 0)

10+ Year Member



You're amazing, thank you so much! :)

eelixduppy

5:45 pm on May 29, 2009 (gmt 0)



...and welcome to Webmaster World! :)

dreamcatcher

6:46 pm on May 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, a warm welcome. Variable variables [uk.php.net] and a simple loop can come in handy here.

foreach ($_POST AS $key => $value) {
$$key = $value;
}

dc

eelixduppy

7:10 pm on May 29, 2009 (gmt 0)



Using the variable variable approach, however, introduces the same security risk that register globals does. To be more secure it's probably better to use the $_POST super-global array as it is.

You can find more information at the website: [php.net...]