/    Sign up×
Community /Pin to ProfileBookmark

PHP version difference – code not working

I am using PHP for the first time. I have some PHP on a site that works fine that I copied. It doesn’t work on my new site, I think because it uses version4.4.4 and the site that works is on version 5.

Here is the site where it works:
[url]http://www.diamondedgehomes.com/contactus.html[/url]

Here is the site that doesn’t work:
[url]http://www.hpcswb.com/contactus.html[/url]

I copied the form statement (including action=”contact.php”), the contact.php program and the contact.txt format for the email. When I test the contact us page it displays a blank page with [url]http://www.hpcswb.com/contact.php[/url] in the address bar (like it thinks the php program is an html page). It doesn’t send the email, and it never displays the confirm.html page that it should.

I have run a test (info.php) on the hpcswb.com site and it works (displays information page for version 4.4.4), so I know PHP is installed. This site is hosted by Comcast (unfortunately the client’s choice), so their tech support is non-existent.

Can anyone please tell me what differences there are between version 4.4.4 and version 5 that might cause this not to work? I can post the code here if that would make it easier.

I have been fooling with this for over a week and really need to get it resolved. I’m very frustrated! Thanks very much!

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@ctieppoauthorApr 24.2007 — I made a mistake - the site where the contact.php program works is also using PHP version 4. So now I'm really mystified why it doesn't work on my hpcswb.com site!

Help!! :eek:

Thanks.
Copy linkTweet thisAlerts:
@NogDogApr 25.2007 — Seems like about 9 times out of 10 when someone reports a problem like this, it's because the script depends on register_globals being turned on. But as this behavior is deprecated, most servers now do not have it activated. Thus, you may need to edit the script to use values from the $_POST, $_GET, and/or $_COOKIE super-global arrays, e.g. using [b]$_POST['fieldname'][/b] instead of just [b]$fieldname[/b].
Copy linkTweet thisAlerts:
@ctieppoauthorApr 25.2007 — nogdog - thanks for your reply. I checked and I am using the syntax you mentioned ($_POST)

Here is the code from contact.php:

<?php

if(isset($_POST["submit_butt"]))

{

$fname=$_POST['fname'];

$phone=$_
POST['phone'];

$email=$_POST['email'];

$address=$_
POST['address'];

$city=$_POST['city'];

$state=$_
POST['state'];

$zipcode=$_POST['zipcode'];

$request=$_
POST['request'];

$submit_butt=$_POST['submit_butt'];

$mail_body=file_get_contents("contact_email.txt");

$mail_body = str_replace("_fname", $fname, $mail_body);

$mail_body = str_replace("_
phone", $phone, $mail_body);

$mail_body = str_replace("_email", $email, $mail_body);

$mail_body = str_replace("_
address", $address, $mail_body);

$mail_body = str_replace("_city", $city, $mail_body);

$mail_body = str_replace("_
state", $state, $mail_body);

$mail_body = str_replace("_zipcode", $zipcode, $mail_body);

$mail_body = str_replace("_
request", $request, $mail_body);


$from="$email";

$to="[email protected]";


$subject='Contact Us mail';

$message=$mail_body;

mail($to,$subject,$message,"from:$from");

header("location:confirm.html");

}

?>

Please let me know if you (or anyone else) sees any other issues with this code. Thanks very much.
Copy linkTweet thisAlerts:
@NogDogMay 01.2007 — Some things I'd change that might make a difference:

  • 1. Many mail servers require that the "From:" email address be a valid email address on that server (substitute your valid email address for your site), and capitalize "From:" just to be on the safe side:
    [code=php]
    $from = "From: [email protected]: $email";
    [/code]

  • 2. For best compatibility, you should use a full URI for the header "Location:" redirection ("Location:" should also be capitalized):
    [code=php]
    header("Location: http://www.yoursite.com/confirm.html");
    [/code]

  • 3. To prevent your form being "hijacked" by spammers, make sure there is not header injection in the email value sent by the user:
    [code=php]
    $email = preg_replace('/[rn]+/', ' ', $_POST['email']);
    [/code]
  • Copy linkTweet thisAlerts:
    @NogDogMay 01.2007 — PS: You might want to add the following lines to the start of your script to ensure you see any warnings/notices that occur while you are debugging this:
    [code=php]
    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    [/code]
    Copy linkTweet thisAlerts:
    @ctieppoauthorMay 01.2007 — Thanks VERY much. I'll try all of that later and will post my results.
    Copy linkTweet thisAlerts:
    @ctieppoauthorMay 02.2007 — I'm really disappointed. I tried all of the things you suggested, and I got exactly the same result. A blank screen was displayed with the URL:

    http://www.hpcswb.com/contact.php

    I don't even see any warnings or errors, in spite of the fact that I added the command you (nogdog) suggested to display errors.

    Here is the updated code, with the changes in RED:

    <?php

    [COLOR="red"][B]ini_set('display_errors', 1);

    error_reporting(E_ALL); [/B]
    [/COLOR]


    if(isset($_POST["submit_butt"]))

    {

    $fname=$_POST['fname'];

    $phone=$_
    POST['phone'];

    [COLOR="red"][B]$email = preg_replace('/[rn]+/', ' ', $_POST['email']); [/B][/COLOR]

    $address=$_
    POST['address'];

    $city=$_POST['city'];

    $state=$_
    POST['state'];

    $zipcode=$_POST['zipcode'];

    $request=$_
    POST['request'];

    $submit_butt=$_POST['submit_butt'];

    $mail_body=file_get_contents("contact_email.txt");

    $mail_body = str_replace("_fname", $fname, $mail_body);

    $mail_body = str_replace("_
    phone", $phone, $mail_body);

    $mail_body = str_replace("_email", $email, $mail_body);

    $mail_body = str_replace("_
    address", $address, $mail_body);

    $mail_body = str_replace("_city", $city, $mail_body);

    $mail_body = str_replace("_
    state", $state, $mail_body);

    $mail_body = str_replace("_zipcode", $zipcode, $mail_body);

    $mail_body = str_replace("_
    request", $request, $mail_body);


    $from="$email";

    [COLOR="red"][B]$to="[email protected]";[/B][/COLOR]


    $subject='Contact Us mail';

    $message=$mail_body;

    mail($to,$subject,$message,"from:$from");

    [COLOR="Red"][B]header("Location:http://hpcswb.com/confirm.html");[/B][/COLOR]

    }

    ?>

    I'm really starting to think that something is wrong with the configuration of PHP itself with Comcast.

    Any further ideas? Anyone? Thanks to nogdog for all of his help so far. Anyone else up for the challenge?
    Copy linkTweet thisAlerts:
    @ctieppoauthorMay 02.2007 — One quick correction:

    [COLOR="Red"][B]header("Location:http://www.hpcswb.com/confirm.html");[/B][/COLOR]

    It didn't make a difference when I changed it, but thought I should mention that I noticed it and changed it.
    Copy linkTweet thisAlerts:
    @NogDogMay 02.2007 — Try adding this at the very end of the code you showed us (after the closing "}" of the IF block) to see if there is a disconnect between what you are expecting to receive from the form and what you are actually getting:
    [code=php]
    else
    {
    printf("<p>Expected post value not received.</p>n<pre>%s</pre>n",
    print_r($_POST, 1));
    }
    [/code]
    ×

    Success!

    Help @ctieppo spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.8,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...