t3x Posted August 27, 2011 Share Posted August 27, 2011 Hello everyone, I'm just trying to get this code to work from php 4 to php 5.3.5. I have researched a fair bit and tried to modify it myself but without any luck, i tried using POST tags as well but since i do not know anything about php i didn't get very far So basically this is the code responding to my flash file in order to send a mail using a form. This code works fine using php 4 but this new windows hosting site can only use php 5.3.5, also this might not be complete as i have tweaked it a fair bit for it to work but it works fine in php 4 <title>MY SITE</title> <div align="center"> </div> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"> <? $adminaddress = "me@hotmail.com"; $siteaddress ="http://www.mysite.com"; $sitename = "MY SITE"; $date = date("m/d/Y H:i:s"); if ($REMOTE_ADDR == "") $ip = "no ip"; else $ip = getHostByAddr($REMOTE_ADDR); IF ($action != ""): mail("$adminaddress","Email submition", "FAO: Admin @ $sitename \n First Name: $fname Email: $vemail The visitor commented: ------------------------------ $comments ------------------------------ Logged Info : ------------------------------ Using: $HTTP_USER_AGENT Hostname: $ip IP address: $REMOTE_ADDR Date/Time: $date","FROM:$adminaddress"); ENDIF; ?> Any help converting this would be greatly appreciated. Thank you for your time. Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/ Share on other sites More sharing options...
voip03 Posted August 27, 2011 Share Posted August 27, 2011 You’re if statement is in capital letters. Change to small letters. http://php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/#findComment-1262565 Share on other sites More sharing options...
t3x Posted August 27, 2011 Author Share Posted August 27, 2011 Thank you very much for your reply voip03, unfortunately that didn't work. I'm ready through that link you posted, it looks interesting, if you think of anything else i can try let me know Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/#findComment-1262571 Share on other sites More sharing options...
voip03 Posted August 27, 2011 Share Posted August 27, 2011 Use this code <? $from = "mysite.com <no-reply@mysite.com >"; $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: $from\r\n"; $verifyemail = "reciver email address"; $mail_body="Test mail"; if (mail($verifyemail,"Customer contact", $mail_body,$headers)) { echo " Thankyou! - Your feedback has been sent! "; } else { echo " Thankyou! - We could not send email. Please try later! "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/#findComment-1262582 Share on other sites More sharing options...
DavidAM Posted August 27, 2011 Share Posted August 27, 2011 1) Don't use short tags "<?", always use the full open tag "<?php". 2) It looks like the code depends on registered_globals being on. This has been deprecated and off by default for a long time. It is a security problem. $REMOTE_ADDR should be $_SERVER['REMOTE_ADDR'] -- same with HTTP_USER_AGENT $action is probably a form field, so I guess it should be $_POST['action'] -- same with $fname, $vemail, $comments 3) Turn on error reporting, and fix the errors/warnings and notices. error_reporting(E_ALL); ini_set("display_errors", 1); Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/#findComment-1262602 Share on other sites More sharing options...
PFMaBiSmAd Posted August 27, 2011 Share Posted August 27, 2011 Edit: Basically says the same as what DavidM posted above ^^^ The problem(s) with the code has nothing directly to do with php4 vs php5. It is old out of date code that would not work under the last recommend php4 configuration either. The code is dependent on register_globals (turned off by default in php4.2 in the year 2002.) It is also using short open tags <? which may or may not be enabled and should simply never be used. Make the following changes - 1) Use <?php for the opening php tag. 2) Change $REMOTE_ADDR to $_SERVER['REMOTE_ADDR']. The one that is inside the message body string will need to be enclosed in {}, i.e. {$_SERVER['REMOTE_ADDR']} 3) Change $HTTP_USER_AGENT to $_SERVER['HTTP_USER_AGENT'] and since it is inside the message body string it needs to be enclosed in {} as well. 4) Change all the external POST variables from just $variable_name to $_POST['variable_name']. For example, $action becomes $_POST['action'] Edit2: Since they are inside the message body string, they will each need to be enclosed in {} Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/#findComment-1262610 Share on other sites More sharing options...
t3x Posted August 27, 2011 Author Share Posted August 27, 2011 Thank you all for your help, i haven't been able to make it work yet but now i understand the problem. Here is what i have so far: <title>My site</title> <div align="center"> </div> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"> <?php $adminaddress = "me@hotmail.com"; $siteaddress ="http://www.mysite.com"; $sitename = "my site"; $date = date("m/d/Y H:i:s"); if ( {$_SERVER['REMOTE_ADDR']}.== "") $ip = "no ip"; else $ip = getHostByAddr( {$_SERVER['REMOTE_ADDR']}. ); if ($_POST['action'] != ""): mail("$adminaddress","Email submition", "FAO: Admin @ $sitename \n First Name: {$_POST['fname']} Email: {$_POST['vemail']} The visitor commented: ------------------------------ {$_POST['comments']} ------------------------------ Logged Info : ------------------------------ Using: {$_SERVER['HTTP_USER_AGENT']} Hostname: $ip IP address: $REMOTE_ADDR Date/Time: $date","FROM:$adminaddress"); ENDif; ?> Does this look like it should be ok? David, where do you see the error messages? i did add that line of code to it before and tried it, but i don't know where the error report is suppose to be. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/#findComment-1262693 Share on other sites More sharing options...
jcbones Posted August 27, 2011 Share Posted August 27, 2011 if ( {$_SERVER['REMOTE_ADDR']}.== "") $ip = "no ip"; To: if ( empty($_SERVER['REMOTE_ADDR']) ) $ip = "no ip"; else $ip = getHostByAddr( {$_SERVER['REMOTE_ADDR']}. ); To: else $ip = getHostByAddr( $_SERVER['REMOTE_ADDR'] ); if ($_POST['action'] != ""): To: if ( !empty($_POST['action']) ): Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/#findComment-1262702 Share on other sites More sharing options...
t3x Posted August 28, 2011 Author Share Posted August 28, 2011 GREAT, that did it, it works !! Jcbones, PFMaBiSmAd, DavidAM, voip03, thank you all for your help, it is very much appreciated I'll post the working code so that if anyone else has the same problem they can grab it here: <title>MY SITE</title> <div align="center"> </div> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"> <?php $adminaddress = "me@hotmail.com"; $siteaddress ="http://www.mysite.com"; $sitename = "MY SITE"; $date = date("m/d/Y H:i:s"); if ( empty($_SERVER['REMOTE_ADDR']) ) $ip = "no ip"; else $ip = getHostByAddr( $_SERVER['REMOTE_ADDR'] ); if ( !empty($_POST['action']) ): mail("$adminaddress","Email submition", "FAO: Admin @ $sitename \n First Name: {$_POST['fname']} Email: {$_POST['vemail']} The visitor commented: ------------------------------ {$_POST['comments']} ------------------------------ Logged Info : ------------------------------ Using: {$_SERVER['HTTP_USER_AGENT']} Hostname: $ip IP address: $REMOTE_ADDR Date/Time: $date","FROM:$adminaddress"); ENDif; ?> Thank you all again ! Quote Link to comment https://forums.phpfreaks.com/topic/245807-php-4-to-php-535-help/#findComment-1262715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.