dreamblademyth Posted April 8, 2008 Share Posted April 8, 2008 Hello Folks Can someone help in getting this 'sendmail.php' script to work for PHP5 please-the hosting Linux server has had a software update; have been trying for ages to sort this out and I've not worked with PHP previously. This script works with a html form (and a thanks page) which is posted after the PHP script. Help will be greatly appreciated, many thanks.........dreamblademyth I've come to a stand still with hosting support and I'm unsure of what to do next; their last support message read: Looking at your script it looks like it isn't designed to work with PHP5, it is using: $HTTP_GET_VARS when it should be using: $_GET There are also other issues with your script that you will need to resolve This following server notice was posted regarding their upgrade from PHP4 to PHP5. 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. 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. <?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.co.uk</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']." ------------------------------- 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: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 ?> <form action="sendmail.php" method="get" name="Contact Form"> <input name="formEMAIL" type="hidden" value="info@your_domain.co.uk"> <input name="formREDIRECT" type="hidden" value= "http://www.your_domain.co.uk/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> </td> <td> </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> </td> <td> </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> </td> <td> </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> </p></form> Quote Link to comment https://forums.phpfreaks.com/topic/100166-php-script-not-working-in-php5/ Share on other sites More sharing options...
wildteen88 Posted April 8, 2008 Share Posted April 8, 2008 You should use $_GET not $_GET_VARS Quote Link to comment https://forums.phpfreaks.com/topic/100166-php-script-not-working-in-php5/#findComment-512195 Share on other sites More sharing options...
dreamblademyth Posted April 8, 2008 Author Share Posted April 8, 2008 Changed all $_GET_VARS to $_GET - still not working. The server people say other issues in the script need resolving? <?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>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($_GET){ if(empty($_GET['formEMAIL'])) { // The email to where the content should go echo_missing_var("formEMAIL"); $formError = true; }else{ $formError = check_email("formEMAIL", $_GET['formEMAIL']); // Check for a valid email address } if(empty($_GET['email'])) { // The visitor's email, the reply email address echo_missing_var("email"); $formError = true; }else{ $formError = check_email("email", $_GET['email']); // Check for a valid email address } if(empty($_GET['formSUBJECT'])) { // The subject echo_missing_var("formSUBJECT"); $formError = true; } if(empty($_GET['formREDIRECT'])) { // The redirect page after sending echo_missing_var("formREDIRECT"); $formError = true; } if(empty($_GET['title'])) { // Title(added) echo_missing_var("title"); $formError = true; } if(empty($_GET['surname'])) { // The surname(added) echo_missing_var("surname"); $formError = true; } if(empty($_GET['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['formREPLY']."\n\n\n"; while(list($var, $val)=each($_GET)){ // 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']." ------------------------------- 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: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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/100166-php-script-not-working-in-php5/#findComment-512209 Share on other sites More sharing options...
GingerRobot Posted April 8, 2008 Share Posted April 8, 2008 What happens when you run the script? Any error messages? Quote Link to comment https://forums.phpfreaks.com/topic/100166-php-script-not-working-in-php5/#findComment-512259 Share on other sites More sharing options...
darkfreaks Posted April 8, 2008 Share Posted April 8, 2008 put the following in your script to check for errors: <?php ini_set('error_reporting',E_ALL); ?> Quote Link to comment https://forums.phpfreaks.com/topic/100166-php-script-not-working-in-php5/#findComment-512265 Share on other sites More sharing options...
dreamblademyth Posted April 8, 2008 Author Share Posted April 8, 2008 Hello That's excellent, the script function is now working and mail is being successfully sent. I omitted to change one small detail, adding an email address in one field, before uploading the new files after changing them. What are the server tec people meaning by needing to alter further aspects of this script? Do you see anything else which will future proof this script. I want to try and add CAPTCHA to this form mail to prevent unfair use of automated programs. Is this something that can work easily with this script and form mail? Many thanks for helping........ Quote Link to comment https://forums.phpfreaks.com/topic/100166-php-script-not-working-in-php5/#findComment-512294 Share on other sites More sharing options...
darkfreaks Posted April 8, 2008 Share Posted April 8, 2008 captcha can easily be intergrated into any script. lookup a few captcha classes. Quote Link to comment https://forums.phpfreaks.com/topic/100166-php-script-not-working-in-php5/#findComment-512300 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.