Page 1 of 1

PHP code no longer works in PHP5

Posted: Fri Mar 14, 2008 7:00 am
by dreamblade myth
Hello folks

I'm using form mail on my website, on a Linux server, software has just been upgraded from PHP 4 to PHP 5; the following, form mail script, and PHP mailer, no longer works. Contact form and PHP script are included.

I don't really understand what I'm dealing with here and need help in adapting both form mail and PHP to allow for the upgrade/change, if both need to be adapted. The form mail has been set up to check for missing fields, etc, and has, until now, worked seamlessly with the PHP script.

Help with this will be much appreciated, been trying to resove this for over a week now and find myself out of options, many thanks.......

http://www.b4uc.tv


***** PLEASE USE THE CODE AND PHP TAGS WHEN POSTING *****

Code: Select all

<br>
 
<form action="sendmail.php" method="get" name="Contact Form">
<input name="formEMAIL" type="hidden" value="info@your_domain">
<input name="formREDIRECT" type="hidden" value=
"http://www.your_domain/onlinemail/thanks.html">
<input name="formSUBJECT" type="hidden" value=
"Enquiry Form">
<p class="unnamed3"><b>*</b> Mandatory fields</p>
<br>
 
<table width="90%" border="0" cellspacing="10" cellpadding="0">
<tr>
<td class="unnamed3"><b>Title</b> *</td>
<td><input name="title" type="text" class="textbox" size=
"28"></td></tr>
<tr>
<td class="body"><b class="unnamed3">First Name</b></td>
<td><input name="first_name" type="text" class="textbox"
size="28"></td></tr>
<tr>
<td class="unnamed3"><b>Surname</b> *</td>
<td><input name="surname" type="text" class="textbox" size=
"28"></td></tr>
<tr>
<td class="body"><b class="unnamed3">Company Name</b></td>
<td><input name="company_name" type="text" class="textbox"
size="28"></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td></tr>
<tr>
<td valign="top" class="unnamed3"><b>Your Enquiry*</b><br>
Please give as much information as you can about the kind of
information you require, so we can get back to you with a full
response.</td>
<td>
<textarea name="enquiry" cols="22" rows="5" class="Textfield">
</textarea></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td></tr>
<tr>
<td class="body"><b class="unnamed3">Preferred method of contact</b></td>
<td align="right" valign="top" class="unnamed3">Email
<input type="radio" name="contact_method" value="by_email"
checked> Telephone <input type="radio" name="contact_method"
value="by_telephone"></td></tr>
<tr>
<td class="unnamed3"><b>Email address</b>*</td>
<td><input name="email" type="text" class="textbox" size=
"28"></td></tr>
<tr>
<td class="body"><b class="unnamed3">Telephone number</b></td>
<td><input name="telephone_number" type="text" class="textbox"
size="28"></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td></tr>
<tr>
<td colspan="2" class="unnamed3"><b>Privacy</b>: the information you
provide here will only be used to deal with your enquiry and will
not be passed on to any third parties.<br>
<br>
<br></td></tr>
<tr>
<td valign="bottom"><input name="Submit" type="submit" class="Form"
value="Submit Enquiry"></td>
<td><input name="reset" type="reset" class="Form" value=
"Clear Form"></td></tr></table>
<p>&nbsp;</p></form>
<br>
 
 
 
 
 
 
<?php 
// Script Vars
$formError = false;
$error_style = "style=\"color: #666666; text-align: center;font-family: Verdana, Helvetica, Arial, sans-serif;font-size : 11px;\"";
ini_set("sendmail_from", "info@your_domain");
//============================//
//====== Functions ======//
//============================//
/* Function to display an error */
function echo_missing_var($formField) {
global $error_style;
echo "<div $error_style>The '<b>".$formField."</b>' field is missing.</div><br>\n";
}
/* Function check for a valid email */
function check_email($formField, $email_addr) {
global $error_style, $formError;
if(!eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$", $email_addr)) {
echo "<div $error_style>
The email address supplied through the field '<b>".$formField."</b>' 
(<b>$email_addr</b>) is incorrect or invalid.
</div><br>\n";
$formError = true;
}else {
$formError = false;
}
 
return $formError;
}
//============================//
?>
<html><head><title>2-Design.co.uk|website design</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#E9E9E9">
<?php
if($HTTP_GET_VARS){
if(empty($HTTP_GET_VARS['formEMAIL'])) { // The email to where the content should go
echo_missing_var("formEMAIL");
$formError = true;
}else{
$formError = check_email("formEMAIL", $HTTP_GET_VARS['formEMAIL']); // Check for a valid email address
}
if(empty($HTTP_GET_VARS['email'])) { // The visitor's email, the reply email address
echo_missing_var("email");
$formError = true;
}else{
$formError = check_email("email", $HTTP_GET_VARS['email']); // Check for a valid email address
}
if(empty($HTTP_GET_VARS['formSUBJECT'])) { // The subject
echo_missing_var("formSUBJECT");
$formError = true;
}
if(empty($HTTP_GET_VARS['formREDIRECT'])) { // The redirect page after sending
echo_missing_var("formREDIRECT");
$formError = true;
}
 
if(empty($HTTP_GET_VARS['title'])) { // Title(added)
echo_missing_var("title");
$formError = true;
}
if(empty($HTTP_GET_VARS['surname'])) { // The surname(added)
echo_missing_var("surname");
$formError = true;
}
if(empty($HTTP_GET_VARS['enquiry'])) { // enquiry(added)
echo_missing_var("enquiry");
$formError = true;
}
 
 
 
if(!$formError) {
// The message body header:
$formBODY = "This message has been sent from ".$_SERVER['HTTP_HOST']." 
by ".$HTTP_GET_VARS['formREPLY']."\n\n\n";
while(list($var, $val)=each($HTTP_GET_VARS)){ // Get all variables
$$var=$val;
$formBODY .= "[".$var."]:\n".$val."\n\n"; // build the message body 
}
// The message body footer:
$formBODY .= "\n\nThe person's IP address who sent this email is: ".$_SERVER['REMOTE_ADDR']."
-------------------------------
http://www.your_domain
-------------------------------";
 
// Send the email
if(mail("$formEMAIL", "$formSUBJECT", "$formBODY", "From: $email")) {
echo "<META HTTP-EQUIV=\"refresh\" content=\"0;URL=$formREDIRECT\">";
exit; 
}else {
echo "<hr noshade><div $error_style>Could not send email at this time. Please try again later.
<a href=\"javascript&#058;history.go(-1)\">GO BACK</a></div>\n";
} 
}else {
echo "<hr noshade><div $error_style><br>Your Email has <b>NOT</b> been sent due to the above missing mandatory fields.<br><br>Use the <b>BACK</b> button on your browser to return to the form to fill in the missing fields</div>\n";
}
}
?> 
</body>
</html>

Re: PHP code no longer works in PHP5

Posted: Fri Mar 14, 2008 10:05 am
by nickvd
Without proper highlighting, I only skimmed the code... Change all occurrences of $HTTP_GET_VARS into $_GET...

Re: PHP code no longer works in PHP5

Posted: Fri Mar 14, 2008 6:25 pm
by dreamblade myth
Implemented this change, uploaded PHP to server but the same problem persists..........

Re: PHP code no longer works in PHP5

Posted: Sat Mar 15, 2008 8:53 am
by nickvd
dreamblade myth wrote:Implemented this change, uploaded PHP to server but the same problem persists..........

Perhaps if you explained in detail what exactly this 'problem' is... I don't see anything other that 'this no longer works'... While that is indeed a problem, it is not something that we can easily help with :)

More explanation is needed...

Re: PHP code no longer works in PHP5

Posted: Sat Mar 15, 2008 9:09 am
by dreamblade myth
The form, once processed by sendmail.php, is then forwarded to the thanks page; all appears to function as planned but no mail is actually delivered. Hope this helps.

Re: PHP code no longer works in PHP5

Posted: Sat Mar 15, 2008 9:11 am
by nickvd
dreamblade myth wrote:The form, once processed by sendmail.php, is then forwarded to the thanks page; all appears to function as planned but no mail is actually delivered. Hope this helps.

Have you ran the script with error_reporting turned all the way up? There may be some hidden errors that aren't getting displayed...

Re: PHP code no longer works in PHP5

Posted: Sat Mar 15, 2008 9:35 am
by dreamblade myth
The issue has finally been resolved by the technical dept as a missing F-fifth parameter. This is located on line 166 of the above PHP script.

The updated code is changed from: (mail("$formEMAIL", "$formSUBJECT", "$formBODY", "From: $email"))

to

(mail("$formEMAIL", "$formSUBJECT", "$formBODY", "From: root@your_domain", "-froot@root@your_domain"))

Thanks for helping, appreciated

Re: PHP code no longer works in PHP5

Posted: Wed Mar 19, 2008 7:43 am
by dreamblade myth
Hello Folks

My mistake with the previous post, the change to the script did not resolve the problem. Can someone help me in getting this script to work for PHP5 please. Help will be much appreciated.

This following server notice was posted regarding their upgrade from PHP4 to PHP5, which is probably relevant. I've not worked with PHP previously and don't understand what's happening here.


Upgrading from PHP4 to PHP5

PHP5 has been designed to be as backwards compatable as possible with PHP4, most website will require no changes to make them compatible with PHP5 which has many features not available on earlier versions of PHP, however there are a few differences that you should be awaire of when upgrading to this version.

Reserved Keywords

The following keywords are now reserved: final, php user filer, interface, implements, public, private, protected, abstract, clone, try, catch, throw and this.
The following keywords are no longer reserved: cfunction, and old function.

A full list of reserved keywords can be found in the PHP manual at http://www.php.net/manual/en/reserved.p ... d.keywords.

Case sensitivity

The values of __CLASS__, __METHOD__, and __FUNCTION__ and classes/methods of get_class(), get_parent_class() and get_class_methods() are now returned as declared, this may lead to problems in older scripts that rely on a lowercase value.

Other changes

array_merge() will now accept only arrays. If a non-array variable is passed, a E_WARNING will be thrown for every such parameter.
The Illegal use of string offsets causes an E_ERROR rather than an E_WARNING.
strrpos() and strripos() now use the entire string as a needle.
The T_ML_COMMENT constant is no longer defined by the Tokenizer extension. If error_reporting is set to E_ALL, PHP will generate a notice.
$_SERVER should be populated with argc and argv if variables_order includes "S".
An object with no properties is no longer considered "empty".
ip2long() now returns FALSE when an invalid IP address is passed as argument to the function, rather than -1.
If there are functions defined in the included file, they can be used in the main file independent if they are before return() or after. If the file is included twice, PHP 5 issues fatal error because functions were already declared.
register_globals has now been turned off on all Linux servers.


Code: Select all

<?php 
// Script Vars
$formError = false;
$error_style = "style=\"color: #666666; text-align: center;font-family: Verdana, Helvetica, Arial, sans-serif;font-size : 11px;\"";
ini_set("sendmail_from", "info@your_domain.co.uk");
//============================//
//======    Functions   ======//
//============================//
/* Function to display an error */
function echo_missing_var($formField) {
    global $error_style;
    echo "<div $error_style>The '<b>".$formField."</b>' field is missing.</div><br>\n";
}
/* Function check for a valid email */
function check_email($formField, $email_addr) {
    global $error_style, $formError;
    if(!eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$", $email_addr)) {
        echo "<div $error_style>
                The email address supplied through the field '<b>".$formField."</b>' 
                (<b>$email_addr</b>) is incorrect or invalid.
              </div><br>\n";
        $formError = true;
    }else {
        $formError = false;
    }
    
return $formError;
}
//============================//
?>
<html><head><title>your-domain</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#E9E9E9">
<?php
if($_GET_VARS){
    if(empty($_GET_VARS['formEMAIL'])) {        // The email to where the content should go
        echo_missing_var("formEMAIL");
        $formError = true;
    }else{
        $formError = check_email("formEMAIL", $_GET_VARS['formEMAIL']); // Check for a valid email address
    }
    if(empty($_GET_VARS['email'])) {        // The visitor's email, the reply email address
        echo_missing_var("email");
        $formError = true;
    }else{
        $formError = check_email("email", $_GET_VARS['email']); // Check for a valid email address
    }
    if(empty($_GET_VARS['formSUBJECT'])) {      // The subject
        echo_missing_var("formSUBJECT");
        $formError = true;
    }
    if(empty($_GET_VARS['formREDIRECT'])) {     // The redirect page after sending
        echo_missing_var("formREDIRECT");
        $formError = true;
    }
    
    if(empty($_GET_VARS['title'])) {        // Title(added)
        echo_missing_var("title");
        $formError = true;
    }
    if(empty($_GET_VARS['surname'])) {      // The surname(added)
        echo_missing_var("surname");
        $formError = true;
    }
    if(empty($_GET_VARS['enquiry'])) {      // enquiry(added)
        echo_missing_var("enquiry");
        $formError = true;
    }
    
    
    
    if(!$formError) {
        // The message body header:
        $formBODY = "This message has been sent from ".$_SERVER['HTTP_HOST']." 
                        by ".$_GET_VARS['formREPLY']."\n\n\n";
          while(list($var, $val)=each($_GET_VARS)){     // Get all variables
            $$var=$val;
            $formBODY .= "[".$var."]:\n".$val."\n\n";               // build the message body           
          }
        // The message body footer:
        $formBODY .= "\n\nThe person's IP address who sent this email is: ".$_SERVER['REMOTE_ADDR']."
                    -------------------------------
                    http://www.your_domain.co.uk
                    -------------------------------";
                    
        // Send the email
        if(mail("$formEMAIL", "$formSUBJECT", "$formBODY", "From: root@your_domain.co.uk", "-froot@your_domain.co.uk")) {
            echo "<META HTTP-EQUIV=\"refresh\" content=\"0;URL=$formREDIRECT\">";
            exit;       
        }else {
            echo "<hr noshade><div $error_style>Could not send email at this time. Please try again later.
                     <a href=\"javascript&#058;history.go(-1)\">GO BACK</a></div>\n";
        }            
    }else {
        echo "<hr noshade><div $error_style><br>Your Email has <b>NOT</b> been sent due to the above missing mandatory fields.<br><br>Use the <b>BACK</b> button on your browser to return to the form to fill in the missing fields</div>\n";
    }
}
?> 
</body>
</html>
<?php
?>

<a href="http://www.b4uc.tv">Fine Art Photography, Documentary Photography and Video Art Gallery</a>