Forum Moderators: coopster
I have a contact form that was running on php4 and now server has iis7 with php5 (thanks isp)
my code no longer works. i have read various post saying that php is backward compatible and others that say it is not.
my code is below.
<?php
$contact_name = $_POST['name'];
$contact_email = $_POST['email'];
$contact_subject = $_POST['subject'];
$contact_message = $_POST['message'];
if( $contact_name == true )
{
$sender = $contact_email;
$receiver = "daren@example.co.uk";
$client_ip = $_SERVER['REMOTE_ADDR'];
$email_body = "Name: $contact_name \nEmail: $sender \nSubject: $contact_subject \nMessage: $contact_message \nIP: $client_ip \nFlash Contact Form provided by http://www.example.co.uk";
$extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion().;
if( mail( $receiver, “Flash Contact Form - $contact_subject”, $email_body, $extra ) )
{
echo "success=yes";
}
else
{
echo "success=no";
}
}
?>
1. is it backward?
2. is this code not going to work on php5?
[edited by: coopster at 1:51 pm (utc) on Feb. 24, 2009]
[edit reason] please use example.com, thanks! [/edit]
(Were you on Apache previously?)
Just a point... you seem to be using curly double quotes in your mail() function. I would change these to straight quotes "..."
if( mail( $receiver, “Flash Contact Form - $contact_subject”, $email_body, $extra ) )
You also have a period (.) at the end of your $extra= line. This should be removed.
You could also try changing the "\r\n" line separators in your extra header to just "\n" (although it should be "\r\n" - see the PHP manual page for mail() [uk.php.net])
What error(s) do you receive?
Generally... most PHP4 code should work OK under PHP5 with only minimal changes. Yes, in many ways it's backward compatible - just not 100%.
a bit of background that might help.
my original server was linux and the form worked correctly however the xml gallery didnt so the switch was made to windows with iis7 that has php5.
i did notice that on the linux server , there was a number of other folders and files that i believe was php related. on the windows server, my domain root folder has no additional files or folders.
i phoned them to make sure that the php was enabled and they said that the php.ini was located at the root of their server in a location that i do not have permissions to get to.
They ran a php test file from my domain folder and they said it ran ok.
i assumed then for it to be code related and not their server.
could it be that i am missing the support files (php.ini and others) to be able to complete the function?
i did notice that on the linux server , there was a number of other folders and files that i believe was php related. on the windows server, my domain root folder has no additional files or folders.
Is this really your domain/web root folder? Or the folder above your webroot? Certainly all the files/folders in your webroot (the root directory accessible from the web) should be the same, regardless of what server you are on - this is your website. However, the files/folders above your webroot could be server dependent.
By the sounds of it you are on a shared server, so you will not have access to the php.ini that relates to the whole server. However, for your form/mail script to run you should not need to change the php.ini file - it should already be set up correctly.
If you don't see any errors reported, try having a look at your server error.log. Or enable errors for your script by placing the following at the start...
ini_set('display_errors','On');
error_reporting(E_ALL ¦ E_STRICT); // A pipe character Does your script return "success=yes" or "success=no" ?
My website folder does not have any php related files.
i placed the code for errors but i do not know where to see the results.
The form process is fill out all fields and click send. The notice of "sending" appears under the send button and gets stuck there. Its as tho it tries to initiate the send process but then cannot complete, or get to the success or fail message.
It is making me think that it is related to a call to the php system on the server root but cannot see the necessary files to complete? sorry if i am off the mark but i have never used php before.
thanks
My website folder does not have any php related files.
You mean it has no files related to the Zend PHP engine? No, it shouldn't. But it should have your php related files that contain your form/mail script etc. ...? Presumably your PHP files have the extension ".php" ?
The form process is fill out all fields and click send. The notice of "sending" appears under the send button and gets stuck there. Its as tho it tries to initiate the send process but then cannot complete, or get to the success or fail message.
This doesn't sound as if it's a fault with the code in your OP, but perhaps with the code of your form? Is your form actually being posted? You could paste that here to have a look...
well i started by creating the php5-fcgi and php5.ini (full set of folders and files from a link i found) and then i tested the website.
good news it worked.....(i ran around the room screaming)..... once. tried it again and since has NOT.
i am convinced the issue lies in how to make my mailer.php file (not code)talk to the php process on the server.