Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

haydn!

macrumors 65816
Original poster
Nov 10, 2008
1,288
1,874
UK
Hi, I'm looking for some help as the Fasthosts support centre is not proving too supportive!

I've uploaded a single page, php website to www.hortonknightsmortgages.co.uk but whenever you try to visit it, your met with a 500 error. It seems to be a PHP issue, as the image files are available if you type in the direct URL, and when tested with a HTML doc, it loaded fine.

I've checked with Fasthosts and they first told me there was no problem, and that they could view the site. Turns out they couldn't. They're now saying it's a problem with the PHP script.

The website works perfectly when hosted on my domain, so I don't get it. I'm under the impression PHP script either works and loads, or it doesn't and that there is no in between.

Here's the script:

PHP:
<?php

                    function is_valid_email($email) {
                        return preg_match("/^[0-9a-z!#$%&'*+-\/\?^_`{|}~=\"]+(\.[0-9a-z!#$%&'*+-\/\?^_`{|}~=\"]+)*@([0-9a-z-]+(\.[0-9a-z-]+)*\.[a-z]{2,6}|(([0-9]|0[0-9][0-9]|[0-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.([0-9]|0[0-9][0-9]|[0-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.([0-9]|0[0-9][0-9]|[0-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.([0-9]|0[0-9][0-9]|[0-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))))$/i",$email);
                    }
                   
                    function is_tel($telephone) {
                        // Valids all uk numbers including +44's or anything like that
                        $telephone = str_replace(" ","",$telephone);
                        $telephone = str_replace("+","",$telephone);
                        $pattern = '/^01[1-9]{1}|02[03489]{1}|05[0-9]|07[056789]{1}|08[047]{1}|441[1-9]{1}|442[03489]{1}|445[0-9]|447[056789]{1}|448[047]{1}$/Ui';
                        if (!preg_match($pattern, $telephone)) {
                            return false;
                        } else {
                            if(substr($telephone, 0, 2) == "44") {
                                $telephone = "0" . substr($telephone, 3, strlen($telephone));
                            }
                            if(strlen($telephone < 10)) {
                                return false;
                            }
                        return true;
                        }
                    }

                        if($_GET['action'] == "send") {
                            if(strlen($_POST['name']) > 2) {
                                if(is_tel($_POST['phone'])) {
                                    if(is_valid_email($_POST['email'])) {
                                                    // Send message
                                                    $send_email = mail("hello@****************","Email From HKMS Website","Name: " . stripslashes($_POST['name']) . "\n\nPhone Number: " . $_POST['phone'] . "\n\nEmail: " . $_POST['email'],"FROM: " . $_POST['name'] . " <" . $_POST['email'] . ">");

                                                    ?>

                                                        <div class="formerrormessage"><h3 style="color: #FFFFFF;">Thank You!</h3>
                                                        <strong>You're message has been sent. We'll call you as soon as possible.</strong></div>

                                                    <?php

                                                    if(!$send_email) {
                                                        ?>
                                                            <div class="formerrormessage"><h3 style="color: #FFFFFF;">We're sorry, your message could not be sent.</h3>
                                                        <strong>An error has occurred and your message could not be sent. Please try again later. Sorry for any inconvenience caused.</strong></div>
                                                        <?php
                                                    }

                                        } else {
                                            // Invalid email.
                                            $email_error = true;
                                            $any_error = true;
                                        }
                                    } else {
                                        // Phone number not valid.
                                        $phone_error = true;
                                        $any_error = true;
                                    }
                                } else {
                                    // Name too short.
                                    $name_error = true;
                                    $any_error = true;
                                }
                   
                            }

                    ?>

                        <form method="post" action="<?php echo(basename(__FILE__) . "?action=send"); ?>">
                            <?php
                                if($name_error) {
                            ?>
                            <div class="formerrormessage"><strong>The name you've entered is not valid.</strong> Please use only letters.</div>
                            <?php
                                }
                            ?>
                            <div class="formrow">
                                <div class="formlable">Your name</div>
                                <div class="formright"><input class="field" type="text" name="name" <?php if($any_error) { ?>value="<?=$_POST['name']?>"<?php } ?> /></div>
                            </div>
                           
                            <?php
                                if($phone_error) {
                            ?>
                            <div class="formerrormessage"><strong> The phone number you've entered is invalid.</strong> Your phone number must be UK based and not contain any letters.</div>
                            <?php
                                }
                            ?>
                            <div class="formrow">
                                <div class="formlable">Phone number</div>
                                <div class="formright"><input class="field" type="text" name="phone" <?php if($any_error) { ?>value="<?=$_POST['phone']?>"<?php } ?> /></div>
                            </div>
                           
                            <?php
                                if($email_error) {
                            ?>
                            <div class="formerrormessage"><strong>The email address you've entered is invalid.</strong> Please check you have entered it correctly.</div>
                            <?php
                                }
                            ?>
                            <div class="formrow">   
                                <div class="formlable">Your email</div>
                                <div class="formright"><input class="field" type="text" name="email" <?php if($any_error) { ?>value="<?=$_POST['email']?>"<?php } ?> /></div>
                            </div>
                           
                            <input class="button" type="image" src="images/structure/button01.png" value="Submit">
                        </form>

Can someone, somewhere help?! :(

Thanks in advance!
 
What version of PHP are you testing on and what version of PHP is on the host?

Since the 500 error is usually a permission issue - I would make sure any files referenced in the script have permissions of 644 and their containing folders at least 755.

And a side note: You have it read "You're message has been sent." and it should be "Your"
 
Note sure if it's causing the error, but this line needs fixing,
PHP:
if(strlen($telephone < 10)) {
Should be apparent why, but deals with the parentheses.

Another piece to tweak,
PHP:
<form method="post" action="<?php echo(basename(__FILE__) . "?action=send"); ?>">
becomes,
PHP:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
One issue could be that some web servers don't understand PHP shorthand like this,
PHP:
<?=$_POST['phone']?>
and need the full <?php at the start.
 
Hi, I'm looking for some help as the Fasthosts support centre is not proving too supportive!!

I am not associated with "Fasthosts" at all, but just an FYI, I don't know of any web host that will debug your PHP scripts for free.

If it is an issue with file permissions, as SDub90 suggested, I can see that. But helping you fix a PHP problem is beyond what a web host is expected to support, at least in my experience with various web hosting companies.
 
I've tried updating the permissions, but for some reason after a minute or two they're defaulting back to 600 across the board, and Fasthosts doesn't allow you to change the permissions of folders! This is currently with Fasthosts support as that surely shouldn't be happening?

And a side note: You have it read "You're message has been sent." and it should be "Your"

Good spot, thanks!

Thanks for the other pointers, I'll make those changes and see how I get on!

On a side note, I never asked them to debug my code, I asked them to investigate why the website didn't load on their servers when the exact same files performed fine on another host. Their responses so far have been shocking - the first telling me she could see the site fine - turns out she was following the link I'd provided to the second URL which hosts the site fine!
 
Looking at the response headers for the page I see that it's being served on a Microsoft IIS web server. I wonder if that may be part of it. Have you tried other PHP scripts with simpler things like,
PHP:
<?php
echo 'Test';
?>
 
The best thing to do is look in your apache error log - a 500 error from PHP should show up there and help to explain why. Usually a 500 from PHP is either an infinite loop, a memory over-use error or permissions error.

That said, fasthosts are by far the worst hosting company I've ever seen (even worse than 1&1)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.