PHP code no longer works in PHP5
Posted: Fri Mar 14, 2008 7:00 am
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 *****
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> </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>
<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: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>